一、RS健康监测
1、 Director不可用,整个系统将不可用;SPoF
解决方案:高可用软件
keepalived
heartbeat/corosync
2、某RS不可用时,Director依然会调度请求至此RS;
解决方案:对各RS的健康状态做检查,失败时禁用,成功时启用;
Keepalived软件:既能高可用又能对后端服务器健康监测
Ldirectord软件:只能对后端服务器健康监测,并实施处理
检测方式:
(a) 网络层检测;
(b) 传输层检测,端口探测;
(c) 应用层检测,请求某关键资源;
二、Ldirectord软件实现健康监测
[root@vs-110 ~]# wget ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/x86_64/ldirectord-3.9.5-3.1.x86_64.rpm#下载idirectord安装包
[root@vs-110 ~]# yum install ldirectord-3.9.5-3.1.x86_64.rpm -y#安装
[root@vs-110 ~]# rpm -ql ldirectord
/etc/ha.d #主配置文件目录
/etc/init.d/ldirectord #启动脚本
[root@vs-110 ~]# cp /usr/share/doc/ldirectord-3.9.5/ldirectord.cf /etc/ha.d/#拷贝到配置文件目录下
[root@vs-110 ~]# cd /etc/ha.d
[root@vs-110 ha.d]# vim ldirectord.cf
# Global Directives #全局配置
checktimeout=3 #超时时长
checkinterval=1 #检测时长
#fallback=127.0.0.1:80 #全部离线后,由那个主机响应
#fallback6=[::1]:80 #全部离线后,由那个主机响应ipv6地址
autoreload=yes
#logfile="/var/log/ldirectord.log" #日志文件目录
#logfile="local0" #由rsyslog记录
#emailalert="admin@x.y.z" #修复邮件地址
#emailalertfreq=3600 #通知修复邮件时间周期
#emailalertstatus=all#什么状态邮件通知
quiescent=no#不要工作静默模式
# Sample for an http virtual service
virtual=172.16.15.99:80 #一个集群
real=172.16.15.111:80 gate #后端rs地址端口
real=172.16.15.112: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="test.html" #请求那个主页,这里我们指向测试页
# receive="Test Page"
#virtualhost=www.x.y.z #指明那个虚拟主机
[root@vs-110 ha.d]# service ldirectord start #启动ldirectord
Starting ldirectord (via systemctl): [ OK ]
[root@vs-110 ha.d]# ipvsadm -ln #查询状态
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.16.15.99:80 rr
-> 172.16.15.111:80 Route 1 0 0 #已检测成功rs1
-> 172.16.15.112:80 Route 1 0 0 #已检测成功rs2
将rs1和rs2的httpd服务关闭,则vs显示:
[root@vs-110 ha.d]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.16.15.99:80 rr
-> 127.0.0.1:80 Route 1 0 0 #rs1和rs2全部离线后,由此台主机响应
三、基于防火墙标记的健康监测
[root@vs-110 ~]# cd /etc/ha.d
[root@vs-110 ha.d]# vim ldirectord.cf
virtual=3 #防火墙标记为3
real=172.16.15.111 gate
real=172.16.15.112 gate
# real=192.168.6.6 gate
fallback=127.0.0.1:80 gate
service=http
scheduler=rr
# #persistent=600
# #netmask=255.255.255.255
protocol=fwm
checktype=negotiate
checkport=80
request="test.html"
# receive="Test Page"
# virtualhost=x.y.z
[root@vs-110 ha.d]# iptables -t mangle -A PREROUTING -d 172.16.15.99 -p tcp -m multiport --dports 80,443 -j MARK --set-mark 3 #防火墙标记
[root@vs-110 ha.d]# service ldirectord start #启动
Starting ldirectord (via systemctl): [ OK ]
[root@vs-110 ha.d]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
FWM 3 rr #防火墙标记
-> 172.16.15.111:0 Route 1 0 0 #已检测成功rs1
-> 172.16.15.112:0 Route 1 0 0 #已检测成功rs2