keepalived-lvs-DR

news/2024/11/15 13:47:48/文章来源:https://www.cnblogs.com/cnblogsfc/p/14279359.html

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 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft foreverinet6 ::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 1000link/ether 00:50:56:25:c5:6f brd ff:ff:ff:ff:ff:ffinet 192.168.43.121/24 brd 192.168.43.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft foreverinet6 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 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft foreverinet6 ::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 1000link/ether 00:50:56:29:49:d5 brd ff:ff:ff:ff:ff:ffinet 10.0.0.122/24 brd 10.0.0.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft foreverinet 172.16.0.200/24 scope global ens33
       valid_lft forever preferred_lft foreverinet6 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 1000link/ether 00:0c:29:dd:76:5c brd ff:ff:ff:ff:ff:ffinet 192.168.43.122/24 brd 192.168.43.255 scope global noprefixroute ens37
       valid_lft forever preferred_lft foreverinet6 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 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft foreverinet6 ::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 1000link/ether 00:50:56:31:8a:01 brd ff:ff:ff:ff:ff:ffinet 10.0.0.125/24 brd 10.0.0.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft foreverinet6 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 keepalivedglobal_defs {notification_email {root@lvs.localdomain}notification_email_from keepaliced@lvs.localdomainsmtp_server 127.0.0.1smtp_connect_timeout 30router_id ka1vrrp_mcast_group4 224.100.100.100                                             #vrrp组播宣告IP
}vrrp_instance VI_1 {                                                             #虚拟路由实例state MASTERinterface ens33virtual_router_id 66priority 100advert_int 1authentication {auth_type PASSauth_pass 123456}virtual_ipaddress {                                                          #VIP172.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 3lb_algo rrlb_kind DRprotocol TCPsorry_server 127.0.0.1 80  real_server 10.0.0.123 80 {weight 1HTTP_GET {url {path /status_code 200}connect_timeout 3nb_get_retry 3delay_before_retry 3}}real_server 10.0.0.124 80 {weight 1HTTP_GET {url {path /status_code 200} connect_timeout 3nb_get_retry 3delay_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 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft foreverinet6 ::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 1000link/ether 00:50:56:34:07:10 brd ff:ff:ff:ff:ff:ffinet 10.0.0.126/24 brd 10.0.0.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft foreverinet6 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 keepalivedglobal_defs {notification_email {root@lvs.localdomain}notification_email_from keepaliced@lvs.localdomainsmtp_server 127.0.0.1smtp_connect_timeout 30router_id ka1vrrp_mcast_group4 224.100.100.100                        #vrrp宣告的组播地址
}vrrp_instance VI_1 {state BACKUPinterface ens33virtual_router_id 66                                     #vrrp实例标识(0-255)priority 90                                              #优先级advert_int 1                                             #vrrp宣告间隔authentication {                                         #同一个vrrp实例相互验证口令auth_type PASSauth_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 3lb_algo rr                                                #指定算法lb_kind DR                                                #指定DR模式protocol TCP                                              #指定协议类型,不加好像是UDPsorry_server 127.0.0.1 80                                 #rs都停止服务后,sorry_server提示real_server 10.0.0.123 80 {weight 1HTTP_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 1HTTP_GET {url {path /status_code 200                                    #根据服务状态码健康检查}connect_timeout 3nb_get_retry 3delay_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 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft foreverinet 172.16.0.100/32 scope global lo
       valid_lft forever preferred_lft foreverinet6 ::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 1000link/ether 00:50:56:24:31:9e brd ff:ff:ff:ff:ff:ffinet 10.0.0.123/24 brd 10.0.0.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft foreverinet6 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 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft foreverinet 172.16.0.100/32 scope global lo
       valid_lft forever preferred_lft foreverinet6 ::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 1000link/ether 00:50:56:3e:3c:3e brd ff:ff:ff:ff:ff:ffinet 10.0.0.124/24 brd 10.0.0.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft foreverinet6 fe80::250:56ff:fe3e:3c3e/64 scope link 
       valid_lft forever preferred_lft foreverlink/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 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft foreverinet6 ::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 1000link/ether 00:50:56:34:07:10 brd ff:ff:ff:ff:ff:ffinet 10.0.0.126/24 brd 10.0.0.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft foreverinet 172.16.0.100/32 scope global ens33:1
       valid_lft forever preferred_lft foreverinet6 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 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft foreverinet6 ::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 1000link/ether 00:50:56:31:8a:01 brd ff:ff:ff:ff:ff:ffinet 10.0.0.125/24 brd 10.0.0.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft foreverinet 172.16.0.100/24 scope global ens33:1
       valid_lft forever preferred_lft foreverinet6 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 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft foreverinet6 ::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 1000link/ether 00:50:56:34:07:10 brd ff:ff:ff:ff:ff:ffinet 10.0.0.126/24 brd 10.0.0.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft foreverinet6 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

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/788962.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

LVS之NAT模式

LVS之NAT模式实现原理图: 拓扑图: 环境说明: 1、基于DNAT实现lvs,LVS需要开启ip_forward 2、lvs和RS之间可以跨路由 3、本实验基于虚拟机实验,client与VIP直连,不用配置网关;实际环境client和lvs之间有路由,client需要配置直连路由的为网关 4、client端无法ping通RS,…

MySQL联表查询

按功能分内连接等值连接 非等值连接 自连接外连接左外连接 右外连接 全外连接交叉连接1. 内连接(INNER JOIN) 获取所有的员工名和其对应的部门名 SELECT e.last_name, d.department_name FROM employees e INNER JOIN departments dON e.department_id = d.department_id;查询…

网络防火墙之SNAT

网络防火墙 NAT NAT: network address translationPREROUTING,INPUT,OUTPUT,POSTROUTING请求报文:修改源/目标IP,由定义如何修改响应报文:修改源/目标IP,根据跟踪机制自动实现 SNAT:source NAT POSTROUTING, INPUT让本地网络中的主机通过某一特定地址访问外部网络,实现…

网络防火墙之自定义chain

网络防火墙 自定义链 链管理:-N:new, 自定义一条新的规则链-X:delete,删除自定义的空的规则链-P:Policy,设置默认策略;对filter表中的链而言,其默认策略有:ACCEPT:接受DROP:丢弃-E:重命名自定义链;引用计数不为0的自定义链不能够被重命名,也不能被删除iptables/n…

网络防火墙之DNAT

网络防火墙 NAT NAT: network address translationPREROUTING,INPUT,OUTPUT,POSTROUTING请求报文:修改源/目标IP,由定义如何修改响应报文:修改源/目标IP,根据跟踪机制自动实现DNAT:destination NAT PREROUTING , OUTPUT把本地网络中的主机上的某服务开放给外部网络访问…

Windows 10 on ARM, version 22H2 (updated Aug 2024) ARM64 AArch64 中文版、英文版下载

Windows 10 on ARM, version 22H2 (updated Aug 2024) ARM64 AArch64 中文版、英文版下载Windows 10 on ARM, version 22H2 (updated Aug 2024) ARM64 AArch64 中文版、英文版下载 基于 ARM 的 Windows 10 请访问原文链接:https://sysin.org/blog/windows-10-arm/,查看最新版…

Linux监控性能调优分析-perf(上)

1 简介 Linux perf一个轻量级命令行工具,用于剖析和监控Linux系统的CPU性能。该工具虽然简单,却能提供有助于分析CPU的丰富信息。该命令包含许多用于收集、跟踪和分析CPU事件数据的子命令。1.1 安装perf perf程序并没有预装在Linux系统中 # Ubuntu/Debian $ sudo apt install…

基于Ubuntu部署企业级kubernetes集群---k8s集群容部署

1.下载用于Kubernetes软件包仓库的公共签名秘钥#如果 `/etc/apt/keyrings` 目录不存在,则应在 curl 命令之前创建它。 sudo mkdir -p -m 755 /etc/apt/keyrings curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrin…

什么是算法?一切皆算法

如果有人问我什么算法?我就一句话:算法就是对一类问题的最优求解路径。如果有人问我什么算法?我就一句话:算法就是对一类问题的最优求解路径。 1、计算机领域的算法概念 算法一直都是计算机领域非常重要的概念,具备极高的地位,各个公司对算法的考察也非常热衷。 我们只有…

Adobe After Effects 2024 v24.6 (macOS, Windows) - 后期特效

Adobe After Effects 2024 v24.6 (macOS, Windows) - 后期特效Adobe After Effects 2024 v24.6 (macOS, Windows) - 后期特效 Acrobat、After Effects、Animate、Audition、Bridge、Character Animator、Dimension、Dreamweaver、Illustrator、InCopy、InDesign、Lightroom C…

在SimpleRAG中使用SiliconCloud快速测试Function Calling

Funcion Calling介绍 函数调用允许您将模型如gpt-4o与外部工具和系统连接起来。这对于许多事情都很有用,比如为AI助手赋能,或者在你的应用程序与模型之间建立深度集成。 如果您了解或者使用过Semantic Kernel可能会发现除了OpenAI支持Function Calling的模型之外,自动函数调…

Semantic Kernel/C#:一种通用的Function Calling方法,文末附经测试可用的大模型

Funcion Calling介绍 函数调用允许您将模型如gpt-4o与外部工具和系统连接起来。这对于许多事情都很有用,比如为AI助手赋能,或者在你的应用程序与模型之间建立深度集成。 如果您了解或者使用过Semantic Kernel可能会发现除了OpenAI支持Function Calling的模型之外,自动函数调…