LVS环境搭建及图形化管理(Pacemaker管理+heartbeat心跳+ipvs(DR)+ldirector健康检查及转发)

http://blog.csdn.net/big1980/article/details/9812793

VS环境搭建及图形化管理(Pacemaker管理+heartbeat心跳+ipvs(DR)ldirector健康检查及转发)
        很久没有正儿八经的写技术博客了,希望各位看官海涵。接下来,直接进入主题。
为了使用一个名叫LCMC(好像叫Linux Cluster Managerment Console)的lvs图形化管理界面,我这次lvs的主角确定为heartbeat(基本停止开发,只进行维护)。之前在公司的生产环境进行试验,所以LCMC可以直接连接公网进行wget和yum安装,所以一切都显得非常便捷,基本一个主备模式的lvs只需要几分钟就轻松搞定。为了防止试验环境对生产网的干扰,只得把主机放到测试环境中去。由于测试环境无法直接访问公网,所以花了一天把所需的安装包都收集好。好了,开始安装。
1.系统安装
操作系统:RHEL5.8 X86_64 版本
内核版本: 2.6.18-308.el5

2.配置

借图一用


服务器及IP为
虚拟IP(VIP) :                              eth0:192.168.29.100                  eth1:xxx.xxx.xxx.45/46
主LVS(ds1.lvs.stefentang):        eth0:192.168.29.45                  eth1:xxx.xxx.xxx.45
备LVS(ds2.lvs.stefentang):        eth0:192.168.29.46                  eth1:xxx.xxx.xxx.46
实机1(rs1.lvs.stefentang):       eth0:192.168.29.47(45)  eth0:无
实机2(rs2.lvs.stefentang):       eth0:192.168.29.48(46)  eth0:无

3.软件安装
为了便于日后集成到操作系统的安装包中去,都采用rpm包安装(所需安装包稍后上传)
在ds1和ds2上分别安装:
  1. [root@ds1 ~]# rpm -ivh --force *.rpm  
  1. [root@ds2 ~]# rpm -ivh --force *.rpm  
执行结果:
  1. Preparing...                ########################################### [100%]  
  2.    1:libtool-ltdl           ########################################### [  2%]  
  3.    2:net-snmp-libs          ########################################### [  4%]  
  4.    3:libesmtp               ########################################### [  5%]  
  5.    4:openhpi-libs           ########################################### [  7%]  
  6.    5:OpenIPMI-libs          ########################################### [  9%]  
  7.    6:lm_sensors             ########################################### [ 11%]  
  8.    7:libqb                  ########################################### [ 13%]  
  9.    8:imake                  ########################################### [ 14%]  
  10.    9:drbd83                 ########################################### [ 16%]  
  11.   10:bzip2                  ########################################### [ 18%]  
  12.   11:pacemaker-debuginfo    ########################################### [ 20%]  
  13.   12:openais-debuginfo      ########################################### [ 21%]  
  14.   13:heartbeat-debuginfo    ########################################### [ 23%]  
  15.   14:glib2-devel            ########################################### [ 25%]  
  16.   15:cluster-glue-debuginfo ########################################### [ 27%]  
  17.   16:autoconf               ########################################### [ 29%]  
  18.   17:zlib-devel             ########################################### [ 30%]  
  19.   18:libxml2-devel          ########################################### [ 32%]  
  20.   19:automake               ########################################### [ 34%]  
  21.   20:libtool-ltdl-devel     ########################################### [ 36%]  
  22.   21:perl-TimeDate          ########################################### [ 38%]  
  23.   22:openib                 ########################################### [ 39%]  
  24.   23:libsepol-devel         ########################################### [ 41%]  
  25.   24:libselinux-devel       ########################################### [ 43%]  
  26.   25:libgpg-error-devel     ########################################### [ 45%]  
  27.   26:libgcrypt-devel        ########################################### [ 46%]  
  28.   27:keyutils-libs-devel    ########################################### [ 48%]  
  29.   28:e2fsprogs-devel        ########################################### [ 50%]  
  30.   29:krb5-devel             ########################################### [ 52%]  
  31.   30:openssl-devel          ########################################### [ 54%]  
  32.   31:libesmtp-devel         ########################################### [ 55%]  
  33.   32:libxslt-devel          ########################################### [ 57%]  
  34.   33:libtool                ########################################### [ 59%]  
  35.   34:bzip2-devel            ########################################### [ 61%]  
  36.   35:kmod-drbd83            ########################################### [ 63%]  
  37.   36:libqb-devel            ########################################### [ 64%]  
  38.   37:resource-agents-debugin########################################### [ 66%]  
  39.   38:cluster-glue-libs      ########################################### [ 68%]  
  40.   39:cluster-glue           ########################################### [ 70%]  
  41.   40:libibverbs             ########################################### [ 71%]  
  42.   41:resource-agents        ########################################### [ 73%]  
  43.   42:corosync               ########################################### [ 75%]  
  44.   43:librdmacm              ########################################### [ 77%]  
  45.   44:corosynclib            ########################################### [ 79%]  
  46.   45:cluster-glue-libs-devel########################################### [ 80%]  
  47.   46:libnes                 ########################################### [ 82%]  
  48.   47:corosynclib-devel      ########################################### [ 84%]  
  49.   48:heartbeat-libs         ########################################### [ 86%]  
  50.   49:pacemaker-libs         ########################################### [ 88%]  
  51.   50:openaislib             ########################################### [ 89%]  
  52.   51:heartbeat              ########################################### [ 91%]  
  53.   52:openais                ########################################### [ 93%]  
  54.   53:pacemaker              ########################################### [ 95%]  
  55.   54:heartbeat-devel        ########################################### [ 96%]  
  56.   55:openaislib-devel       ########################################### [ 98%]  
  57.   56:pacemaker-libs-devel   ########################################### [100%]  
4.配置HB(/etc/ha.d/ha.cf)可以由LCMC来完成,也可以手动编辑。
  1. #集群中的节点不会自动加入  
  2. autojoin    none  
  3.   
  4. #heartbeat会记录debug日志,如果启用use_logd,则此选项会被忽略  
  5. debugfile   /var/log/ha-debug  
  6.   
  7. #记录所有non-debug消息,如果启用use_logd,则此选项会被忽略  
  8. logfile    /var/log/ha-log  
  9.   
  10. #告诉heartbeat记录那些syslog  
  11. logfacility   local0  
  12.   
  13. #指定两个心跳检测包的时间间隔  
  14. keepalive 1  
  15.   
  16. #多久以后心跳检测决定集群中的node已经挂掉  
  17. deadtime   30  
  18.   
  19. #心跳包检测的延时事件,如果延时,只是往日志中记录warning日志,并不切换服务  
  20. warntime  10  
  21.   
  22. #在heartbeat启动后,在多长时间内宣布node是dead状态,因为有时候系统启动后,网络还需要一段时间才能启动  
  23. initdead  120  
  24.   
  25. #如果udpport指令在bcast ucast指令的前面,则使用哪个端口进行广播,否则使用默认端口  
  26. udpport   694  
  27.   
  28. #设置使用哪个网络接口发送UDP广播包,可以设置多个网络接口  
  29. bcast  eth1 eth1  
  30.   
  31. #设置在哪个网络接口进行多播心跳检测  
  32. mcast eth0 239.192.0.0 694 1 0  
  33.   
  34. #设置使用哪个网络接口进行UDP单播心跳检测,在ds2上为10.0.0.45  
  35. #ucast  eth1 10.0.0.46  
  36.   
  37. #在主节点的服务恢复后,是否把从节点的服务切换回来  
  38. auto_failback off  
  39.   
  40. #告诉集群中有哪些节点,node名称必须是uname -n显示出来的名称,可以在一个node中设置多个节点,也可以多次设置node,每一个在集群中的node都必须被列出来  
  41. node ds1.lvs.stefentang ds2.lvs.stefentang  
  42.   
  43. #设置ping节点,ping节点用来检测网络连接  
  44. #ping 10.0.0.254  
  45.   
  46. #开启Pacemaker cluster manager,因为历史原因,次选项默认是off,但是应该保持该选项值为respawn。在设置为respawn默认自动使用以下配置  
  47. #pacemaker  respawn  
  48. crm respawn  
  49. compression bz2  
  50. compression_threshold 20  
  51. traditional_compression on  
  52. #默认配置文件中下面还有很多选项,由于暂时用不到所以暂时忽略  

5.配置/etc/ha.d/authkeys(LCMC完成,authkeys文件属性必须是600,否则日志会报错。)

  1. ## generated by drbd-gui  
  2. auth 1  
  3. 1 sha1 9AO5FmCl9RwBZZLIepNERwSbMMsmgeiF  

6.配置ldirectord(/etc/ha.d/ldirectord.cf)可以手动编辑,也可以拷贝ldirectord的share目录下的文件

  1. #  
  2. # Sample ldirectord configuration file to configure various virtual services.  
  3. #  
  4. # Ldirectord will connect to each real server once per second and request  
  5. # /index.html. If the data returned by the server does not contain the  
  6. # string "Test Message" then the test fails and the real server will be  
  7. # taken out of the available pool. The real server will be added back into  
  8. # the pool once the test succeeds. If all real servers are removed from the  
  9. # pool then localhost:80 is added to the pool as a fallback measure.  
  10.   
  11. # Global Directives  
  12. checktimeout=3  
  13. checkinterval=1  
  14. #fallback=127.0.0.1:80  
  15. autoreload=yes  
  16. logfile="/var/log/ldirectord.log"  
  17. #logfile="local0"  
  18. emailalert="tanghuifeng@besttone.com.cn"  
  19. emailalertfreq=3600  
  20. emailalertstatus=all  
  21. quiescent=yes  
  22.   
  23. # Sample for an http virtual service  
  24. virtual=192.168.29.100:80  
  25.     real=192.168.29.47(45):80 gate  
  26.     real=192.168.29.48(46):80 gate  
  27. #    real=192.168.6.6:80 gate  
  28. #     fallback=127.0.0.1:80 gate  
  29.     service=http  
  30.     request="health/health.html"  
  31.     receive="running status: available"  
  32. #    virtualhost=some.domain.com.au  
  33.     scheduler=rr  
  34.     #persistent=600  
  35.     #netmask=255.255.255.255  
  36.     protocol=tcp  
  37.       checktype=negotiate  
  38.       checkport=80  
  39.      request="health/health.html"  
  40.      receive="running status: available"  
  41.      virtualhost=ds1/ds2.lvs.stefentang  

测试心跳是否正常: tcpdump -i eth1 -n -p udp port 694

7.安装http服务器

lvs配置完后,配置真实服务器
  1. [root@rs1 ~]# rpm -ivh /mnt/Server/apr-1.2.7-11.el5_6.5.x86_64.rpm  
  2. [root@rs1 ~]# rpm -ivh /mnt/Server/postgresql-libs-8.1.23-1.el5_7.3.x86_64.rpm  
  3. [root@rs1 ~]# rpm -ivh /mnt/Server/apr-util-1.2.7-11.el5_5.2.x86_64.rpm  
  4. [root@rs1 ~]# rpm -ivh /mnt/Server/mailcap-2.1.23-1.fc6.noarch.rpm  
  5. [root@rs1 ~]# rpm -ivh /mnt/Server/httpd-2.2.3-63.el5.x86_64.rpm  
  6. [root@rs1 ~]# service httpd start  

http服务80端口根目录添加一个health/health.html,内容为

[47(45)/48(46).DS1/2]running status: available

然后浏览器输入http://RIP/health/health.html ,能正确看到内容。
配置实机环路地址 lo:0(/etc/init.d/lvs_rs)
  1. #!/bin/bash  
  2. #chkconfig: 2345 80 90  
  3. #description:lvs real server set lo:0 VIP address  
  4. VIP=192.168.29.100  #virtual ip  
  5.     case "$1" in  
  6.     start)  
  7.     echo " start LVS of REALServer"  
  8.     /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up  
  9.     echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore  
  10.     echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce  
  11.     echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore  
  12.     echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce  
  13.     ;;  
  14.     stop)  
  15.     /sbin/ifconfig lo:0 down  
  16.     echo "close LVS Directorserver"  
  17.     echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore  
  18.     echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce  
  19.     echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore  
  20.     echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce  
  21.     ;;  
  22.     *)  
  23.     echo "Usage: $0 {start|stop}"  
  24.     exit 1  
  25.     esac  
然后
  1. chmod u+x lvs_rs  
  1. /etc/inid.d/lvs_rs start  

验证ldirectord是否做健康检查可以尝试查看httpd的access日志文件如(访问源从29.45变成29.46期间LVS做了一次切换):

  1. 192.168.29.45 - - [08/Aug/2013:07:32:16 +0800] "GET /health/health.html HTTP/1.1" 200 372 "-" "libwww-perl/5.805"  
  2. 192.168.29.45 - - [08/Aug/2013:07:32:17 +0800] "GET /health/health.html HTTP/1.1" 200 372 "-" "libwww-perl/5.805"  
  3. 192.168.29.46 - - [08/Aug/2013:07:33:12 +0800] "GET /health/health.html HTTP/1.1" 200 372 "-" "libwww-perl/5.805"  
  4. 192.168.29.46 - - [08/Aug/2013:07:33:13 +0800] "GET /health/health.html HTTP/1.1" 200 372 "-" "libwww-perl/5.805"  

开始怎么也想不通,为啥切换动作差不多花了整整55秒,后来发现DNS配置有问题,干脆把DNS解析注释掉(修改/etc/resolv.conf文件):

  1. 192.168.29.45 - - [17/Aug/2013:02:46:37 +0800] "GET /health/health.html HTTP/1.1" 200 364 "-" "libwww-perl/5.805"  
  2. 192.168.29.45 - - [17/Aug/2013:02:46:38 +0800] "GET /health/health.html HTTP/1.1" 200 364 "-" "libwww-perl/5.805"  
  3. 192.168.29.46 - - [17/Aug/2013:02:46:55 +0800] "GET /health/health.html HTTP/1.1" 200 364 "-" "libwww-perl/5.805"  
  4. 192.168.29.46 - - [17/Aug/2013:02:46:59 +0800] "GET /health/health.html HTTP/1.1" 200 364 "-" "libwww-perl/5.805"  

并且修改heartbeat的以下三个参数后,就缩短到17秒,估计也不能改得太小,造成误判。
  1. warntime  5  
  2. deadtime  10  
  3. initdead 30  


接下来都可以在LCMC端操作了,稍后配图。

8.查看配置结果

  1. [root@ds1 ~]# crm_mon  
  2. Attempting connection to the cluster...  
  3. ============  
  4. Last updated: Thu Aug  8 06:59:53 2013  
  5. Stack: Heartbeat  
  6. Current DC: ds1.lvs.stefentang (a4f7c50b-823d-4434-bb1d-850aa18918b2) - partition with quorum  
  7. Version: 1.0.12-unknown  
  8. 2 Nodes configured, unknown expected votes  
  9. 2 Resources configured.  
  10. ============  
  11.   
  12. Online: [ ds1.lvs.stefentang ds2.lvs.stefentang ]  
  13.   
  14. res_IPaddr2_VIP (ocf::heartbeat:IPaddr2):       Started ds1.lvs.stefentang  
  15. res_ldirectord_1        (ocf::heartbeat:ldirectord):    Started ds1.lvs.stefentang  
  1. [root@ds2 ~]# crm_mon  
  2. Attempting connection to the cluster...  
  3. ============  
  4. Last updated: Thu Aug  8 07:01:15 2013  
  5. Stack: Heartbeat  
  6. Current DC: ds1.lvs.stefentang (a4f7c50b-823d-4434-bb1d-850aa18918b2) - partition with quorum  
  7. Version: 1.0.12-unknown  
  8. 2 Nodes configured, unknown expected votes  
  9. 2 Resources configured.  
  10. ============  
  11.   
  12. Online: [ ds1.lvs.stefentang ds2.lvs.stefentang ]  
  13.   
  14. res_IPaddr2_VIP (ocf::heartbeat:IPaddr2):       Started ds1.lvs.stefentang  
  15. res_ldirectord_1        (ocf::heartbeat:ldirectord):    Started ds1.lvs.stefentang  

最后用ab并发1000,10000连接,压了一下,查看了分发情况如下:

  1. IP Virtual Server version 1.2.1 (size=4096)  
  2. Prot LocalAddress:Port Scheduler Flags  
  3.   -> RemoteAddress:Port           Forward Weight ActiveConn InActConn  
  4. TCP  192.168.29.100:http rr  
  5.   -> 192.168.29.45:http           Local   1      3          5071  
  6.   -> 192.168.29.46:http           Route   1      4          4930  
  1. Server Software:        Apache/2.2.3  
  2. Server Hostname:        192.168.29.100  
  3. Server Port:            80  
  4.   
  5. Document Path:          /is/checkNumber.do  
  6. Document Length:        1336 bytes  
  7.   
  8. Concurrency Level:      1000  
  9. Time taken for tests:   68.166 seconds  
  10. Complete requests:      10000  
  11. Failed requests:        9883  
  12.    (Connect: 0, Receive: 0, Length: 9883, Exceptions: 0)  
  13. Write errors:           0  
  14. Total transferred:      16318053 bytes  
  15. HTML transferred:       13448053 bytes  
  16. Requests per second:    146.70 [#/sec] (mean)  
  17. Time per request:       6816.590 [ms] (mean)  
  18. Time per request:       6.817 [ms] (mean, across all concurrent requests)  
  19. Transfer rate:          233.78 [Kbytes/sec] received  
  20.   
  21. Connection Times (ms)  
  22.               min  mean[+/-sd] median   max  
  23. Connect:        1    7  42.7      5    3014  
  24. Processing:    81 6228 1490.0   6244   11462  
  25. Waiting:       33 3396 2218.5   3159   10526  
  26. Total:         86 6235 1490.7   6250   11467  

心血来潮,测了一下ab的极限,呵呵:

  1. ==================================10000=====================================  
  2. InActConn连接数上不去了,保持在2600左右  
  3. IP Virtual Server version 1.2.1 (size=4096)  
  4. Prot LocalAddress:Port Scheduler Flags  
  5.   -> RemoteAddress:Port           Forward Weight ActiveConn InActConn  
  6. TCP  192.168.29.100:http rr  
  7.   -> 192.168.29.45:http           Local   1      4996       2563  
  8.   -> 192.168.29.46:http           Route   1      5003       2557  
  9.   
  10. ==================================20000=====================================  
  11. ActiveConn连接数上不去了,保持在7500左右,ab压力机报错:apr_socket_connect(): 由于系统缓冲区空间不足或队列已满,不能执行套接字上的操作。(730055)  
  12. IP Virtual Server version 1.2.1 (size=4096)  
  13. Prot LocalAddress:Port Scheduler Flags  
  14.   -> RemoteAddress:Port           Forward Weight ActiveConn InActConn  
  15. TCP  192.168.29.100:http rr  
  16.   -> 192.168.29.45:http           Local   1      7624       2188  
  17.   -> 192.168.29.46:http           Route   1      7571       2186  



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值