heartbeat+lvs
关于heartbeat的配置参见上一篇博文rhel6-heartbeathttp://wangziyin.blog.51cto.com/blog/6948950/1297018
1.环境
Realserver1192.168.122.3:apache
Realserver2192.168.122.82:apache
LoadBalance 192.168.122.33:heartbeat apache
LoadBalance 192.168.122.34:heartbeat apache
在desk33 desk34上:
yum -y ldirectord-3.9.2-1.2.x86_64.rpm perl-IO-Socket-INET6 ipvsadm
添加:
[[email protected]]# vim haresources
desk34.example.comIPaddr::192.168.122.122/24/eth0 ldirectord httpd
这个文件中定义了实现集群所需的各个软件的启动脚本,这些脚本必须放在/etc/init.d或者
/etc/ha.d/resource.d目录里 IPaddr 的作用是启动Virutal IP,它是 HeartBeart自
带的一个脚本. ldirectord 的作用是启动ldirectord 监控程序,它会使ldirectord.cf 中
定义的lvs 生效, 并监听其健康状;httpd是 apache 服务的启动脚本。
[[email protected]]# vim ldirectord.cf
#Sample for an http virtual service
virtual=192.168.122.122:80
real=192.168.122.82:80 gate
real=192.168.122.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
#/etc/init.d/heartbeat start
启动之前最好使用/etc/init.d/ldirecord start 测试是否可以启动。
heartbeat会启动httpd与ldirectord服务:
注意一定要安装perl-IO-Socket-INET6否则会出现如下错误:
ERROR:Return code 2 from /etc/ha.d/resource.d/ldirectord
Retryingfailed stop operation [ldirectord]
info: Running /etc/ha.d/resource.d/ldirectord stop
ERROR:Return code 2 from /etc/ha.d/resource.d/ldirectord
info: Retrying failed stop operation [ldirectord]
info:Running /etc/ha.d/resource.d/ldirectord stop
ERROR:Return code 2 from /etc/ha.d/resource.d/ldirectord
ERROR:Resource script for ldirectord probably not LSB-compliant.
[[email protected]]# ipvsadm -l
IPVirtual Server version 1.2.1 (size=4096)
ProtLocalAddress:Port Scheduler Flags
->RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.122.122:http rr
->desk3.example.com:http Route 1 0 0
->desk82.example.com:http Route 1 0 0
http访问测试:
http://192.168.122.122页面会在desk3与desk82之间循环
当关闭desk82的http服务时:
[[email protected]]# ipvsadm -l
IPVirtual Server version 1.2.1 (size=4096)
ProtLocalAddress:Port Scheduler Flags
->RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.122.122:http rr
->desk3.example.com:http Route 1 0 0
lvs会将故障的节点剔除负载均衡。
当将realserver的httpd全部关闭后,服务将会切换到LoadBalance desk34上
[[email protected]]# ipvsadm -l
TCP 192.168.122.122:http rr
->localhost:http Local 1 0 4
当将LoadBalance 的服务也关闭,则前端无法访问。HA也不会切换,因为heartbeat本身不能对服务进行健康检查
西安石油大学计算机学院
王兹银