LVS高可用性
Director不可用,整个系统将不可用;SPoF Single Point of Failure
解决方案:高可用
keepalived heartbeat/corosync
某RS不可用时,Director依然会调度请求至此RS
解决方案: 由Director对各RS健康状态进行检查,失败时禁用,成功时启用
keepalived heartbeat/corosync ldirectord
检测方式:
(a) 网络层检测,icmp (b) 传输层检测,端口探测 (c) 应用层检测,请求某关键资源
RS全不用时:backup server, sorry server
ldirectord
?ldirectord:监控和控制LVS守护进程,可管理LVS规则
?包名:ldirectord-3.9.6-0rc1.1.1.x86_64.rpm
?下载:http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-7/x86_64/
?文件:
/etc/ha.d/ldirectord.cf 主配置文件 /usr/share/doc/ldirectord-3.9.6/ldirectord.cf 配置模版 /usr/lib/systemd/system/ldirectord.service 服务 /usr/sbin/ldirectord 主程序,Perl实现 /var/log/ldirectord.log 日志 /var/run/ldirectord.ldirectord.pid pid文件
ldirectord实战演练:
1、在LVS服务器上下载ldirectord包,并安装此包
[[email protected]]#wget http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-7/x86_64/ldirectord-3.9.6-0rc1.1.2.x86_64.rpm [[email protected]]#yum install ldirectord-3.9.6-0rc1.1.2.x86_64.rpm -y
2、查看安装后的包
[[email protected]]#rpm -ql ldirectord-3.9.6-0rc1.1.2 /etc/ha.d /etc/ha.d/resource.d /etc/ha.d/resource.d/ldirectord /etc/logrotate.d/ldirectord /usr/lib/ocf/resource.d/heartbeat/ldirectord /usr/lib/systemd/system/ldirectord.service /usr/sbin/ldirectord /usr/share/doc/ldirectord-3.9.6 /usr/share/doc/ldirectord-3.9.6/COPYING /usr/share/doc/ldirectord-3.9.6/ldirectord.cf /usr/share/man/man8/ldirectord.8.gz
3、在LVS服务器上,将配置文件复制到/etc/ha.d目录下
[[email protected]]#cp /usr/share/doc/ldirectord-3.9.6/ldirectord.cf /etc/ha.d/
4、在LVS服务器上安装httpd服务,并启动
[[email protected]]#yum install httpd -y [[email protected]]#echo Sorry Server > /var/www/html/index.html [[email protected]]#systemctl start httpd
5、在原有搭建好的LVS负载均衡调度基础上,修改此配置文件
virtual=10.0.0.100:80 添加VIP地址 real=192.168.37.19:80 gate 添加RS1IP地址 real=192.168.37.20:80 gate 添加RS2IP地址 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 注释掉
6、删除原有绑定在lo网卡上的IP地址以及ipvsadm规则,并手动添加新的IP地址,绑定在回环网卡上。
[[email protected]~]#bash lvs_dr_vs.sh stop [[email protected]~]#ifconfig lo:1 10.0.0.100/24
7、启动ldirectord,此时就会自动添加ipvsad规则。
[[email protected]]#systemctl start ldirectord [[email protected]]#ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 10.0.0.100:80 rr -> 192.168.37.19:80 Route 1 0 0 -> 192.168.37.20:80 Route 1 0 0
8、此时停止RS1服务器的httpd服务
[[email protected]~]#systemctl stop httpd
9、在LVS服务器上查看掉线之后被踢掉的ipvsadm调度规则
[[email protected]]#ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 10.0.0.100:80 rr -> 192.168.37.20:80 Route 1 0 35
10、此时在客户端查看访问页面是RS2的页面
[[email protected] network-scripts]# while : ;do curl 10.0.0.100;sleep 0.5;done 192.168.37.20 RS2 192.168.37.20 RS2 192.168.37.20 RS2 192.168.37.20 RS2
11、此时再恢复RS1服务器的httpd服务
[[email protected]~]#systemctl start httpd
12、ldirectord软件会自动启动RS1的ipvsadm规则。
[[email protected]]#ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 10.0.0.100:80 rr -> 192.168.37.19:80 Route 1 0 71 -> 192.168.37.20:80 Route 1 0 97
13、在客户端访问的httpd服务页面,此时就会恢复两个RS服务器的信息。
[[email protected] network-scripts]# while : ;do curl 10.0.0.100;sleep 0.5;done 192.168.37.19 RS1 192.168.37.20 RS2 192.168.37.19 RS1
14、此时RS1和RS2的httpd服务都停掉
[[email protected]~]#systemctl stop httpd [[email protected]~]#systemctl stop httpd
15、此时的ipvsadm规则的回环网卡就会显示。
[[email protected]]#ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 10.0.0.100:80 rr -> 127.0.0.1:80 Route 1 0 0
16、此时客户端就会显示LVS调度器httpd服务里边的index.html信息。
[[email protected] network-scripts]# while : ;do curl 10.0.0.100;sleep 0.5;done Sorry Server Sorry Server Sorry Server Sorry Server
17、修改LVS服务器的ldirectord配置文件,重启服务,就会将开启httpd服务的作为优先级高的在客户端进行访问。
[[email protected]]#vim /etc/ha.d/ldirectord.cf quiescent=yes [[email protected]]#systemctl restart ldirectord.service
18、此时查看ipvsadm规则优先级情况,此时RS2的服务是开启的,就会只访问RS2服务器。
19、在客户端访问LVS调度器,此时调度访问的是RS2服务器。
[[email protected] network-scripts]# while : ;do curl 10.0.0.100;sleep 0.5;done 192.168.37.20 RS2 192.168.37.20 RS2 192.168.37.20 RS2
20、而如果此时RS1的httpd服务开启之后,此时LVS服务器的ipvsadm规则中RS服务器两者的优先级就会一样,两个权重一致,就会都去访问。
[[email protected]~]#systemctl start httpd
21、在客户端访问LVS调度器的IP地址。
[[email protected] network-scripts]# while : ;do curl 10.0.0.100;sleep 0.5;done 192.168.37.20 RS2 192.168.37.19 RS1 192.168.37.20 RS2 192.168.37.19 RS1
原文地址:https://www.cnblogs.com/struggle-1216/p/12011870.html