ubuntu server 10.4 下LVS-DR+heartbeat +Ldirectord实现web服务高可性负载均衡实验

前言:
ubuntu server 10.4 的LVS-DR+heartbeat 实验中实现了负载均衡器的高可用性,可是存在一个问题就是如果其中一台www服务器故障后,根据lvs的rr算法,当客户端有请求时还会访问到这台故障服务器。这时应用Ldirectord就可以解决这个问题。
那什么是Ldirectord, ldirectord is a daemon to monitor and administer real servers in a LVS cluster of load balanced virtual servers. ldirectord typically used as a resource for Linux-HA , but can also be run from the command line. ldirectord has a configuration file which specifies the virtual services and their associated real servers. When ldirectord is initialised it creates the virtual services for the clutster. ldirectord monitors the health of the real servers by periodically requesting a known URL and checking that the response contains an expected response. If a real server fails then the server is removed and will be reactivated once it comes back on line. If all the real servers are down then a fall-back server is inserted into the pool, which will made quiescent one of the real web servers comes back on line. Typically, the fall-back server is localhost. If an HTTP virtual service is being provided then it is useful to run an Apache HTTP server that returns a page indicating that the service is temporarily inaccessible. (引用自“ http://www.vergenet.net/linux/ldirectord/”),直观能看到那台服务器故障,用#sudo ipvsadm 看到的weight值为零(0)的那台就是。
实验环境:
ubuntu server 10.4 的LVS-DR+heartbeat 实验中相同
1,配置主负载均衡器ubserver1:
    (1)安装Ldirectord软件包
    #sudo apt-get install ldirectord
#sudo cp /usr/share/doc/ldirectord/examples/ldirectord.cf  /etc/ha.d
    (2)ha.cf及authkeys配置文件内容不变与 ubuntu server 10.4 的LVS-DR+heartbeat 实验中相同
(3)haresources文件做以下改动
ubserver1 192.168.3.100 lvs.sh 改为
ubserver1 192.168.3.100 lvs.sh ldirectord
   (4)ldirectord.cf文件配置:
#sudo vim /etc/ha.d/ldirectord.cf
lvs-ldirectord5
当 checktype=negotiate时要求启用
request=”test.html” #在www服务器ubserver2,ubserver3的/var/www下建立test.html/页内容为“work”,这是因为: ldirectord monitors the health of the real servers by periodically requesting a known URL and checking that the response contains an expected response
receive=”work”
当 checktype=connect时这两个配置可以注释掉因为 Connect only attemts to make a TCP/IP connection,我做实验时,把这两个注释掉,发现当一台www服务器down掉后,是发现不了的,不知道这是为什么。
*:ldirectord.cf的配置可以参考: http://linux.die.net/man/8/ldirectord
checktype = connect| external| negotiate| off| on| ping| checktimeout N
Type of check to perform. Negotiate sends a request and matches a receive string. Connect only attemts to make a TCP/IP connection, thus the request and receive strings may be omitted. If checktype is a number then negotiate and connect is combined so that after each N connect attempts one negotiate attempt is performed. This is useful to check often if a service answers and in much longer intervalls a negotiating check is done. Ping means that ICMP ping will be used to test the availability of real servers. Ping is also used as the connect check for UDP services. Off means no checking will take place and no real or fallback servers will be activated. On means no checking will take place and real servers will always be activated. Default is negotiate.
2,配置从主负载均衡器ubserver5:
与主负载均衡器ubserver1的所做的修改相同。ldirectord.cf配置文件内容相同。
3,模拟故障:
关掉ubserver2的www服务后与启有后,用#sudo ipvsadm �CL �Cn 查看结果
lvs-ldirecotrd4
4,用了Ldirectord后,当一台www服务器down掉后,在客户端不会出现错误页;如不用,则会。
总结:用lvs+heartbeat+ldirectord感觉要配置的东西的很多,ha.cf,haresources,authkeys,ldirectord.cf四个配置文件,还要在www服务器上建立让ldirectord发现它是否正常的网页,还要写LVS的脚本(实验用的lvs.sh就是)这样的配置过程给以后的维护带来困难。网上关于这方面的配置案例很多,都大同小异,一定要亲自实验下,不然不知道到底行不行。过程中会碰到很多问题,解决了就是学习。

你可能感兴趣的:(Web,负载,heartbeat,ldirectord,高可性)