keepalived实现lvs高可用
说明:lvs单实例
拓扑:
环境说明:
1、client网关指向Router,跨网段访问lvs-VIP,需要指定正确网关和路由,如果client和Route之间还有其他路由或防火墙设备,网关设置直连路由IP
2、虚拟机模拟路由器,Router需要开启路由转发ip_forward
3、实验环境模拟路由器直连client和lvs架构,Router可以不配置网关,虚拟路由器需配置不同于DIP、RIP网段的"IP2:1"(见图),并需要有到VIP网段的路由,且路由出口为IP2所在网卡,如果绑定再lo网卡,路由出不去,需要额外配置路由
4、ka1和ka2必须有网关:10.0.0.x;如果不配置网关,不接收 “源CIP--目VIP”的数据包,因为数据包到达时,发现CIP和自己不在同网段,假设自己返回响应则需要通过网关发出数据包,但是没有网关,响应返回不了,干脆不接受,此处因为需要提供sorry_server服务,网关设置位10.0.0.122
5、ka,rs,都需要配置VIP,VIP一般配置在lo上,VIP在lo上子网掩码一般是32位,如果在ensX端口,32位可以,24位也可以,会自动生成路由,但是lo上24位掩码不会自动生成路由,影响访问
6、避免arp广播VIP冲突,关闭rs内核参数,忽略arp广播对VIP的查询,忽略自己对自己VIP的arp广播宣告,
7、RS的GW可以是IP2,也可以是“IP2:1”(见图)
8、由于lvs调度请求时,源目IP不变"CIP-VIP",没有新的IP封装,调度给后端RIP时,依赖MAC地址转发,所以lvs调度器和RS需要在一个物理网络
9、lvs-DR模式,请求经过lvs,响应不经过lvs,RS的网关不指向lvs,而是“出口路由”
10、tcp握手有5次
示例:keepalived基于轮询算法、DR模式配置验证,实现lvs高可用
1、client端配置
[root@client ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 #客户端IP TYPE="Ethernet" BOOTPROTO="static" DEFROUTE="yes" NAME="ens33" DEVICE="ens33" ONBOOT="yes" IPADDR=192.168.43.121 PREFIX=24 GATEWAY=192.168.43.122 [root@client ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:50:56:25:c5:6f brd ff:ff:ff:ff:ff:ff inet 192.168.43.121/24 brd 192.168.43.255 scope global noprefixroute ens33 valid_lft forever preferred_lft forever inet6 fe80::250:56ff:fe25:c56f/64 scope link valid_lft forever preferred_lft forever [root@client ~]# route -n #客户端路由 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.43.122 0.0.0.0 UG 100 0 0 ens33 192.168.43.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
2、模拟路由器配置:
[root@router ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens37 #模拟路由器 IP TYPE="Ethernet" BOOTPROTO="static" NAME="ens37" DEVICE="ens37" ONBOOT="yes" IPADDR=192.168.43.122 PREFIX=24 #GATEWAY=192.168.43.121 [root@router ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 #模拟路由器 IP TYPE="Ethernet" BOOTPROTO="static" DEFROUTE="yes" NAME="ens33" DEVICE="ens33" ONBOOT="yes" IPADDR=10.0.0.122 PREFIX=24 DNS1=114.114.114.114 #非必要 [root@router ~]# ip a a 172.16.0.200/24 dev ens33:1 #VIP同网段 [root@router ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:50:56:29:49:d5 brd ff:ff:ff:ff:ff:ff inet 10.0.0.122/24 brd 10.0.0.255 scope global noprefixroute ens33 valid_lft forever preferred_lft forever inet 172.16.0.200/24 scope global ens33 valid_lft forever preferred_lft forever inet6 fe80::250:56ff:fe29:49d5/64 scope link valid_lft forever preferred_lft forever 3: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:dd:76:5c brd ff:ff:ff:ff:ff:ff inet 192.168.43.122/24 brd 192.168.43.255 scope global noprefixroute ens37 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fedd:765c/64 scope link valid_lft forever preferred_lft forever [root@router ~]# route -n #模拟路由器路由 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 172.16.0.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33 192.168.43.0 0.0.0.0 255.255.255.0 U 101 0 0 ens37 [root@router ~]# grep -i ip_forward /etc/sysctl.conf #开启路由转发 net.ipv4.ip_forward=1 [root@router ~]# sysctl -p net.ipv4.ip_forward = 1
3、配置ka1-keepalived服务:
[root@lvs-ka1 keepalived]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 #DIP TYPE="Ethernet" BOOTPROTO="static" DEFROUTE="yes" NAME="ens33" DEVICE="ens33" ONBOOT="yes" IPADDR=10.0.0.125 PREFIX=24 GATEWAY=10.0.0.122 DNS1=114.114.114.114 #非必要,yum按照需要 [root@lvs-ka1 ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:50:56:31:8a:01 brd ff:ff:ff:ff:ff:ff inet 10.0.0.125/24 brd 10.0.0.255 scope global noprefixroute ens33 valid_lft forever preferred_lft forever inet6 fe80::250:56ff:fe31:8a01/64 scope link valid_lft forever preferred_lft forever [root@lvs-ka1 ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 10.0.0.122 0.0.0.0 UG 100 0 0 ens33 10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 [root@lvs-ka1 keepalived]# yum install -y keepalived [root@lvs-ka1 keepalived]# cat /etc/keepalived/keepalived.conf #keealived服务管理VIP,LVS调度规则 ,MASTER ! Configuration File for keepalived global_defs { notification_email { [email protected] } notification_email_from [email protected] smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id ka1 vrrp_mcast_group4 224.100.100.100 #vrrp组播宣告IP } vrrp_instance VI_1 { #虚拟路由实例 state MASTER interface ens33 virtual_router_id 66 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 123456 } virtual_ipaddress { #VIP 172.16.0.100/24 dev ens33 label ens33:1 } notify_master "/etc/keepalived/notify.sh master" notify_backup "/etc/keepalived/notify.sh backup" notify_fault "/etc/keepalived/notify.sh fault" } virtual_server 172.16.0.100 80 { #LVS调度规则 delay_loop 3 lb_algo rr lb_kind DR protocol TCP sorry_server 127.0.0.1 80 real_server 10.0.0.123 80 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } real_server 10.0.0.124 80 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } } [root@lvs-ka1 ~]# cat /etc/hosts 10.0.0.125 ka1 10.0.0.126 ka2 [root@lvs-ka1 ~]# ssh-keygen [root@lvs-ka1 ~]# ssh-copy-id 10.0.0.126 [root@lvs-ka1 ~]# yum install -y httpd [root@lvs-ka1 ~]# echo Sorry Server1 > /var/www/html/index.html #sorry_server服务提示 [root@lvs-ka1 ~]# systemctl start httpd [root@lvs-ka1 ~]# yum install -y ipvsadm #用于查看keepalived服务管理实现的lvs调度规则
4、配置ka2-keepalived服务:
[root@lvs-ka2 keepalived]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE=Ethernet BOOTPROTO="static" DEFROUTE=yes NAME=ens33 DEVICE=ens33 ONBOOT=yes IPADDR=10.0.0.126 PREFIX=24 DNS1=114.114.114.114 #非必要,yum按照需要 GATEWAY=10.0.0.122 [root@lvs-ka2 keepalived]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:50:56:34:07:10 brd ff:ff:ff:ff:ff:ff inet 10.0.0.126/24 brd 10.0.0.255 scope global noprefixroute ens33 valid_lft forever preferred_lft forever inet6 fe80::250:56ff:fe34:710/64 scope link valid_lft forever preferred_lft forever [root@lvs-ka2 keepalived]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 10.0.0.122 0.0.0.0 UG 100 0 0 ens33 10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 [root@lvs-ka2 keepalived]# yum install -y keepalived [root@lvs-ka2 keepalived]# cat /etc/keepalived/keepalived.conf #keealived服务管理VIP,LVS调度规则 ,BACKUP ! Configuration File for keepalived global_defs { notification_email { [email protected] } notification_email_from [email protected] smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id ka1 vrrp_mcast_group4 224.100.100.100 #vrrp宣告的组播地址 } vrrp_instance VI_1 { state BACKUP interface ens33 virtual_router_id 66 #vrrp实例标识(0-255) priority 90 #优先级 advert_int 1 #vrrp宣告间隔 authentication { #同一个vrrp实例相互验证口令 auth_type PASS auth_pass 123456 } virtual_ipaddress { 172.16.0.100/32 dev ens33 label ens33:1 #VIP绑定到ens33 } notify_master "/etc/keepalived/notify.sh master" notify_backup "/etc/keepalived/notify.sh backup" notify_fault "/etc/keepalived/notify.sh fault" } virtual_server 172.16.0.100 80 { delay_loop 3 lb_algo rr #指定算法 lb_kind DR #指定DR模式 protocol TCP #指定协议类型,不加好像是UDP sorry_server 127.0.0.1 80 #rs都停止服务后,sorry_server提示 real_server 10.0.0.123 80 { weight 1 HTTP_GET { url { path / status_code 200 #根据服务状态码健康检查 } connect_timeout 3 #连接请求超时时长 nb_get_retry 3 #重复尝试连接3次 delay_before_retry 3 #重复尝试前延时时间 } } real_server 10.0.0.124 80 { weight 1 HTTP_GET { url { path / status_code 200 #根据服务状态码健康检查 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } } [root@lvs-ka2 ~]# cat /etc/hosts 10.0.0.125 ka1 10.0.0.126 ka2 [root@lvs-ka2 ~]# ssh-keygen [root@lvs-ka2 ~]# ssh-copy-id 10.0.0.125 [root@lvs-ka2 ~]# yum install -y httpd [root@lvs-ka2 ~]# echo Sorry Server2 > /var/www/html/index.html #sorry_server服务提示 [root@lvs-ka2 ~]# systemctl start httpd [root@lvs-ka2 ~]# yum install -y ipvsadm
5、配置rs1:
[root@rs1 data]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE="Ethernet" BOOTPROTO="static" DEFROUTE="yes" NAME="ens33" DEVICE="ens33" ONBOOT="yes" IPADDR=10.0.0.123 PREFIX=24 GATEWAY=10.0.0.122 DNS1=114.114.114.114 [root@rs1 data]# ip a a 172.16.0.100/32 dev lo:1 #添加临时VIP [root@rs1 data]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet 172.16.0.100/32 scope global lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:50:56:24:31:9e brd ff:ff:ff:ff:ff:ff inet 10.0.0.123/24 brd 10.0.0.255 scope global noprefixroute ens33 valid_lft forever preferred_lft forever inet6 fe80::250:56ff:fe24:319e/64 scope link valid_lft forever preferred_lft forever [root@rs1 data]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 10.0.0.122 0.0.0.0 UG 100 0 0 ens33 10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 [root@rs1 data]# yum install -y httpd [root@rs1 data]# echo httpd on RS1 >/var/www/html/index.html [root@rs1 data]# systemctl start httpd [root@rs1 data]# echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore [root@rs1 data]# echo 1 >/proc/sys/net/ipv4/conf/lo/arp_ignore [root@rs1 data]# echo 2 >/proc/sys/net/ipv4/conf/lo/arp_announce [root@rs1 data]# echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce
6、配置rs2:
[root@rs2 data]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE="Ethernet" BOOTPROTO="static" DEFROUTE="yes" NAME="ens33" DEVICE="ens33" ONBOOT="yes" IPADDR=10.0.0.124 PREFIX=24 GATEWAY=10.0.0.122 DNS1=114.114.114.114 [root@rs2 data]# ip a a 172.16.0.100/32 dev lo:1 #临时添加VIP [root@rs2 data]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet 172.16.0.100/32 scope global lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:50:56:3e:3c:3e brd ff:ff:ff:ff:ff:ff inet 10.0.0.124/24 brd 10.0.0.255 scope global noprefixroute ens33 valid_lft forever preferred_lft forever inet6 fe80::250:56ff:fe3e:3c3e/64 scope link valid_lft forever preferred_lft forever link/ether 52:54:00:75:fe:83 brd ff:ff:ff:ff:ff:ff [root@rs2 data]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 10.0.0.122 0.0.0.0 UG 100 0 0 ens33 10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 [root@rs2 data]# yum install -y httpd [root@rs2 data]# echo httpd on RS1 >/var/www/html/index.html [root@rs2 data]# systemctl start httpd [root@rs2 data]# echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore [root@rs2 data]# echo 1 >/proc/sys/net/ipv4/conf/lo/arp_ignore [root@rs2 data]# echo 2 >/proc/sys/net/ipv4/conf/lo/arp_announce [root@rs2 data]# echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce
7、验证keepalived高可用
1)开启lvs2 keepalived服务,VIP在ka2上,并生成lvs配置
[root@lvs-ka2 keepalived]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:50:56:34:07:10 brd ff:ff:ff:ff:ff:ff inet 10.0.0.126/24 brd 10.0.0.255 scope global noprefixroute ens33 valid_lft forever preferred_lft forever inet 172.16.0.100/32 scope global ens33:1 valid_lft forever preferred_lft forever inet6 fe80::250:56ff:fe34:710/64 scope link valid_lft forever preferred_lft forever [root@lvs-ka2 keepalived]# 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.0.100:80 rr -> 10.0.0.123:80 Route 1 0 0 -> 10.0.0.124:80 Route 1 0 0 [root@client ~]# while true;do curl 172.16.0.100 ;sleep 1;done #客户端验证keepalived管理lvs功能,实现服务调度 httpd on RS1 httpd on RS2
2)开启lvs1 keepalived服务,由于ka1的虚拟路由优先级高,抢占VIP,并生成lvs配置
[root@lvs-ka1 keepalived]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:50:56:31:8a:01 brd ff:ff:ff:ff:ff:ff inet 10.0.0.125/24 brd 10.0.0.255 scope global noprefixroute ens33 valid_lft forever preferred_lft forever inet 172.16.0.100/24 scope global ens33:1 valid_lft forever preferred_lft forever inet6 fe80::250:56ff:fe31:8a01/64 scope link valid_lft forever preferred_lft forever [root@lvs-ka2 keepalived]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:50:56:34:07:10 brd ff:ff:ff:ff:ff:ff inet 10.0.0.126/24 brd 10.0.0.255 scope global noprefixroute ens33 valid_lft forever preferred_lft forever inet6 fe80::250:56ff:fe34:710/64 scope link valid_lft forever preferred_lft forever [root@lvs-ka1 keepalived]# 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.0.100:80 rr -> 10.0.0.123:80 Route 1 0 0 -> 10.0.0.124:80 Route 1 0 0 [root@client ~]# while true;do curl 172.16.0.100 ;sleep 1;done #客户端验证keepalived HA高可用管理lvs功能,实现服务调度 httpd on RS2 httpd on RS1 httpd on RS2
3)关闭rs1 httpd服务,keepalived有对RS的健康检查,自动删除向rs1的调度规则
[root@rs1 data]# systemctl stop httpd [root@lvs-ka1 keepalived]# 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.0.100:80 rr -> 10.0.0.124:80 Route 1 0 47
4)关闭rs2 httpd服务,keepalived有对RS的健康检查,自动删除向rs2的调度规则,此时
rs1和rs2的httpd都停止服务,lvs-MASTER 提供sorry_server httpd服务
[root@rs2 data]# systemctl stop httpd [root@lvs-ka1 keepalived]# 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.0.100:80 rr -> 127.0.0.1:80 Route 1 0 1 关闭lvs1 keepalived服务,lvs2提供sorry_server httpd服务 [root@lvs-ka1 keepalived]# systemctl stop keepalived.service
*)上边整个验证过程状态体现:
[root@client ~]# while true;do curl 172.16.0.100 ;sleep 1;done #rs1和rs2正常轮询提供服务 httpd on RS1 httpd on RS2 httpd on RS1 httpd on RS2 httpd on RS1 httpd on RS2 httpd on RS1 httpd on RS2 curl: (7) Failed connect to 172.16.0.100:80; Connection refused #rs1停止服务后,有短暂问题 httpd on RS2 curl: (7) Failed connect to 172.16.0.100:80; Connection refused httpd on RS2 curl: (7) Failed connect to 172.16.0.100:80; Connection refused httpd on RS2 curl: (7) Failed connect to 172.16.0.100:80; Connection refused httpd on RS2 curl: (7) Failed connect to 172.16.0.100:80; Connection refused httpd on RS2 httpd on RS2 httpd on RS2 httpd on RS2 httpd on RS2 httpd on RS2 httpd on RS2 httpd on RS2 curl: (7) Failed connect to 172.16.0.100:80; Connection refused #rs1和rs2都停止服务后 curl: (7) Failed connect to 172.16.0.100:80; Connection refused curl: (7) Failed connect to 172.16.0.100:80; Connection refused curl: (7) Failed connect to 172.16.0.100:80; Connection refused curl: (7) Failed connect to 172.16.0.100:80; Connection refused curl: (7) Failed connect to 172.16.0.100:80; Connection refused curl: (7) Failed connect to 172.16.0.100:80; Connection refused curl: (7) Failed connect to 172.16.0.100:80; Connection refused curl: (7) Failed connect to 172.16.0.100:80; Connection refused curl: (7) Failed connect to 172.16.0.100:80; Connection refused curl: (7) Failed connect to 172.16.0.100:80; Connection refused Sorry Server1 #lvs1-MASTER 提供sorry_server服务 Sorry Server1 Sorry Server1 Sorry Server1 Sorry Server1 Sorry Server1 Sorry Server2 #lvs1 keepalived服务停止后,VIP飘逸至lvs2,lvs2提供sorry_server服务 Sorry Server2 Sorry Server2 Sorry Server2 Sorry Server2
附件:keepalived服务MASTER和BACKUP状态mail提示通知
[root@lvs-ka1 keepalived]# cat /etc/keepalived/notify.sh #!/bin/bash # contact='root@localhost' notify() { mailsubject="$(hostname) to be $1, vip floating" mailbody="$(date +'%F %T'): vrrp transition, $(hostname) changed to be $1" echo "$mailbody" | mail -s "$mailsubject" $contact } case $1 in master) notify master ;; backup) notify backup ;; fault) notify fault ;; *) echo "Usage: $(basename $0) {master|backup|fault}" exit 1 ;; esac
标签:00,lvs,root,keepalived,forever,lft,ff,DR,ens33 From: https://www.cnblogs.com/cnblogsfc/p/14279359.html