关于 ldirectord
ldirectord 用来实现LVS负载均衡资源在主、备节点间的故障转移。在首次启动时,ldirectord可以自动创建IPVS表。此外,它还可以监控各 RealServer的运行状态,一旦发现某RealServer运行异常时,还可以将其从IPVS表中移除。
ldirectord 进程通过向RealServer的RIP发送资源访问请求并通过由RealServer返回的响应信息来确定RealServer的运行状态。在 Director上,每一个VIP需要一个单独的ldirectord进程。如果RealServer不能正常响应Director上 ldirectord的请求,ldirectord进程将通过ipvsadm命令将此RealServer从IPVS表中移除。而一旦 RealServer再次上线,ldirectord会将其重新添加至IPVS表中。
例 如,为了监控一组提供web服务的RealServer,ldirectord进程使用HTTP协议请求访问每台RealServer上的某个特定网页。 ldirectord进程根据自己的配置文件中事先定义的RealServer正常响应结果来判断当前的返回结果是否正常。比如,在每台web服务器的网 站目录中存放一个页面".ldirectord.html",其内容为"Nice",ldirectord进程每隔一段时间就访问一次此网页,并根据获取 到的响应信息来判断RealServer的运行状态是否正常。如果其返回的信息不是"Nice",则表明服务不正常
服务环境搭建
实验主机环境介绍:
主机使用版本 : redhat rhe6.5
iptables stop 以及 selinux disablesl
主机ip :172.25.254.79
Load Balance : wyx1 :172.25.79.1 VIP 172.25.79.111 (对外开放)
Realserver1 :wyx2 : 172.25.79.2 vip 172.25.79.111 (仅对同一WLAN用户开放)
Realserver1 :wyx3: 172.25.79.3 vip 172.25.79.111 (仅对同一WLAN用户开放)
安装ldirectord 软件
[root@wyx1 ~]# yum install ldirectord-3.9.5-3.1.x86_64.rpm -y
查找ldirectord配置文件
[root@wyx1 /]# rpm -ql ldirectord
/etc/ha.d
/etc/ha.d/resource.d
/etc/ha.d/resource.d/ldirectord
/etc/init.d/ldirectord
/etc/logrotate.d/ldirectord
/usr/lib/ocf/resource.d/heartbeat/ldirectord
/usr/sbin/ldirectord
/usr/share/doc/ldirectord-3.9.5
/usr/share/doc/ldirectord-3.9.5/COPYING
/usr/share/doc/ldirectord-3.9.5/ldirectord.cf
/usr/share/man/man8/ldirectord.8.gz
复制配置文件到本机/etc/ha.d/
[root@wyx1 /]# cp /usr/share/doc/ldirectord-3.9.5/ldirectord.cf /etc/ha.d/
编辑配置文件/etc/ha.d/ldirectord.cf
# Global Directives
checktimeout=3
checkinterval=1
autoreload=yes
quiescent=no
# Sample for an http virtual service
virtual=172.25.79.111:80
real=172.25.79.2:80 gate
real=172.25.79.3:80 gate
fallback=127.0.0.1:80 gate
service=http
scheduler=rr
#persistent=600
#netmask=255.255.255.255
protocol=tcp
checktype=negotiate
checkport=80
request="index.html"
#receive="Test Page"
#virtualhost=www.x.y.z
配置完成开启服务
[root@wyx1 /]# /etc/init.d/ldirectord start
Starting ldirectord... success
wyx2
安装http服务
[root@wyx2 ~]# yum install httpd -y
编辑默认发布目录
[root@wyx2 ~]# cat /var/www/html/index.html
<h1>www.wyx.org: wyx2</h1>
启动http服务
[root@wyx2 ~]# /etc/init.d/httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 172.25.79.2 for ServerName
[ OK ]
添加vip
[root@wyx2 ~]# ip addr add 172.25.79.111/24 dev eth0
[root@wyx2 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:77:c2:f5 brd ff:ff:ff:ff:ff:ff
inet 172.25.79.2/24 brd 172.25.79.255 scope global eth0
inet 172.25.79.111/24 scope global secondary eth0
inet6 fe80::5054:ff:fe77:c2f5/64 scope link
valid_lft forever preferred_lft forever
对外隐藏vip
[root@wyx2 ~]# arptables -A IN -d 172.25.79.111 -j DROP
[root@wyx2 ~]# arptables -A OUT -s 172.25.79.111 -j mangle --mangle-ip-s 172.25.79.2
保存修改
[root@wyx2 ~]# /etc/init.d/arptables_jf save
wyx3 :
安装http服务
[root@wyx3 ~]# yum install httpd -y
编辑默认发布目录
[root@wyx3 ~]# cat /var/www/html/index.html
<h1>www.wyx.org: wyx3</h1>
启动http服务
[root@wyx3 ~]# /etc/init.d/httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 172.25.79.3 for ServerName
[ OK ]
添加vip
[root@wyx3 ~]# ip addr add 172.25.79.111/24 dev eth0
[root@wyx3 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:e6:31:59 brd ff:ff:ff:ff:ff:ff
inet 172.25.79.3/24 brd 172.25.79.255 scope global eth0
inet 172.25.79.111/24 scope global secondary eth0
inet6 fe80::5054:ff:fee6:3159/64 scope link
valid_lft forever preferred_lft forever
对外隐藏vip
[root@wyx3 ~]# arptables -A IN -d 172.25.79.111 -j DROP
[root@wyx3 ~]# arptables -A OUT -s 172.25.79.111 -j mangle --mangle-ip-s 172.25.79.3
保存修改
[root@wyx3 ~]# /etc/init.d/arptables_jf save
测试
wyx2与wyx3都在工作时:
[root@foundation79 html]# curl 172.25.79.111
<h1>www.wyx.org: wyx3</h1>
[root@foundation79 html]# curl 172.25.79.111
<h1>www.wyx.org: wyx2</h1>
[root@foundation79 html]# curl 172.25.79.111
<h1>www.wyx.org: wyx3</h1>
[root@foundation79 html]# curl 172.25.79.111
<h1>www.wyx.org: wyx2</h1>
当停止wyx3时仅有wyx2在工作,
[root@wyx3 ~]# /etc/init.d/httpd stop
Stopping httpd: [ OK ]
由wyx1 的回环接口接管wyx3的服务
[root@foundation79 html]# curl 172.25.79.111
<h1>www.wyx.org: wyx2</h1>
[root@foundation79 html]# curl 172.25.79.111
<h1>www.wyx.org: wyx3</h1>
[root@foundation79 html]# curl 172.25.79.111
<h1>www.wyx.org: wyx2</h1>
[root@foundation79 html]# curl 172.25.79.111
<h1>www.wyx.org: wyx3</h1>
完成对于系统的健康检测,在客户端不会发现该服务以终止,会显示服务还是正常运行
但是坚持不料多久wyx1就会奔溃,应为访问量太大会导致该服务器承受不了直接挂掉。