标签:lvs ipvs heartbeat 高可用 负载均衡
lvs+heartbeat-ldirectord实现高可用负载均衡
IPVS规则与heartbeat
ipvs规则不再使用ipvsadm配置,而是依靠heartbeat的包工具ldirectord去生成规则
并且ldirectord有检测后端RS健康状况的机制(利用权重,非常正常剔除(w=0),正常后添加)。
删除之前 heartbeat v2 crm lamp配置的约束和资源
节点分别停止heartbeat:/etc/init.d/heartbeat stop
规划
ipvs-ld节点: 192.168.0.190 node1
ipvs-ld点: 192.168.0.201 node2
RS:192.168.0.202 node4 ,192.168.0.193 node3
lvs vip 192.168.0.199
ldirectord依赖于自己的配置文件生成ipvs规则,因此,定义集群服务,添加RS都在配置文件中指定,而无需手动执行ipvsadm命令;
ldirectord能对各RS的健康状态做检测,并能实现按需添加或者删除各RS。
1,两个节点安装 heartbeat-ldirectord-2.1.4-12.el6.x86_64.rpm
[root@node2 heartbeat2]# rpm -ivh heartbeat-ldirectord-2.1.4-12.el6.x86_64.rpm
error: Failed dependencies:
ipvsadm is needed by heartbeat-ldirectord-2.1.4-12.el6.x86_64
perl(LWP::Debug) is needed by heartbeat-ldirectord-2.1.4-12.el6.x86_64
perl(LWP::UserAgent) is needed by heartbeat-ldirectord-2.1.4-12.el6.x86_64
perl(Mail::Send) is needed by heartbeat-ldirectord-2.1.4-12.el6.x86_64
[root@node2 heartbeat2]#yum install heartbeat-ldirectord-2.1.4-12.el6.x86_64.rpm -y
依赖包如下:
2,LVS,DR模式配置
配置RS
node3 ,node4主机分别同样配置主机:
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
ifconfig eth0:0 192.168.0.199 broadcast 192.168.0.199 netmask 255.255.255.255
sysctl -p
route add -host 192.168.0.199 dev eth0:0
/etc/init.d/httpd start
curl 192.168.0.194
配置DR主机ipvs
ifconfig eth0:0 192.168.0.199 broadcast 192.168.0.199 netmask 255.255.255.255
route add -host 192.168.0.199 dev eth0:0
[root@node1 ~]# ipvsadm -A -t 192.168.0.199:80 -s rr
[root@node1 ~]# ipvsadm -a -t 192.168.0.199:80 -r 192.168.0.202 -g -w 1
[root@node1 ~]# ipvsadm -a -t 192.168.0.199:80 -r 192.168.0.194 -g -w 1
访问测试成功:
3,测试出成功后,删除ipvs规则;
[root@node1 ~]# ipvsadm -C
[root@node1 ~]# ipvsadm -L
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
[root@node1 ~]# route del -host 192.168.0.199
[root@node1 ~]# ifconfig eth0:0 down
4,使用ldirectord文件配置规则
cd /usr/share/doc/heartbeat-ldirectord-2.1.4/
cp ldirectord.cf /etc/ha.d/
配置文件说明:
# Global Directives
checktimeout=3 #超时时间间隔
checkinterval=1 #向后端检查的时间,即每1秒检查一次,3秒超时。
#fallback=127.0.0.1:80 #sorry page
autoreload=yes #自己不用做reload,文件改变后自动装载。
logfile="/var/log/ldirectord.log" #自己的日志
#logfile="local0"
#emailalert="admin@x.y.z"
#emailalertfreq=3600
#emailalertstatus=all
quiescent=yes
...
以ftp为列说明:
#virtual=192.168.6.240:21 #vip
# real=192.168.16.3:21 masq #rs
# real=192.168.16.5:21 masq #rs
# fallback=127.0.0.1:21 #sorry page
# service=ftp #表示用ftp协议检查
# checkport=21 #表示检查21号端口,在tcp层
# scheduler=wlc #调度算法
# scheduler=rr #调度算法
# #persistent=600 #持久连接时间为600秒。注视表示没开启持久连接
# #netmask=255.255.255.255
# protocol=tcp #集群服务协议类型
# checktype=negotiate #协商类型检查,表示下面的登录和密码
# login="anonymous" #用anonymous登录
# passwd="ldirectord@localhost" #密码
# request="welcome.msg" #请求获取到welcome.msg文件
# receive="test" #回答test字符串
以http说明:
virtual=192.168.6.240:80
real=192.168.6.2:80 gate
real=192.168.6.3:80 gate
real=192.168.6.6:80 gate
fallback=127.0.0.1:80 gate
service=http
request="index.html" #请求哪个页面
receive="Test Page" #必须返回哪个字符串,RS才算是正常的
virtualhost=some.domain.com.au #对虚拟主机单独检测
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
常用的检测类型:
checktype = connect|external|negotiate|off|on|ping|checktimeoutN
ip层:connect: syn ,ack就行了
网络层:ping
应用层:negotiate
配置文件修改:
# Sample for an http virtual service
virtual=192.168.0.199:80
real=192.168.0.194:80 gate
real=192.168.0.202:80 gate
fallback=127.0.0.1:80 gate
protocol=tcp
checkport=80
checktype=negotiate
service=http
request=".health.html"
receive="OK"
scheduler=rr
#persistent=600
#netmask=255.255.255.255
将配置文件复制到node2节点
[root@node1 ha.d]# scp ldirectord.cf node2:/etc/ha.d/
两台DR添加sorry page:
vim /var/www/html/index.html
node1 sorry server
两台RS 添加.health.html
vim /var/www/html/.health.html
测试网页都能访问。
5,配置hb_gui
定义组ipvs
定义集群ip clusterip
定义 ipvs规则 ipsrules (使用ldirectord定义)
启动组
6,测试
注意:两个HA-DR应该开机自动启动httpd,sorry page页面展示
sorry server页面,两台RS,httpd都stop,HA-LVS权重Weight 为1
通过设置权重为0来剔除RS。
本文出自 “行云流水” 博客,请务必保留此出处http://disheng.blog.51cto.com/2821957/1706848
L8.1 lvs+heartbeat-ldirectord实现高可用负载均衡
标签:lvs ipvs heartbeat 高可用 负载均衡
原文地址:http://disheng.blog.51cto.com/2821957/1706848