首页 > 其他分享 >keepalived-lvs-DR

keepalived-lvs-DR

时间:2024-08-29 08:53:32浏览次数:13  
标签:00 lvs root keepalived forever lft ff DR ens33

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

相关文章

  • keepalived简介
    一、keepalived概述官方网站:https://www.keepalived.org/keepalived:vrrp协议:virtualrouterredundancyprotocolvrrp是一种容错协议,它保证当lvs调度器MASTER出现故障时,由另一台lvs调度器BACKUP来代替出现故障的lvs调度器进行工作,从而保持提供服务的连续性和可靠性......
  • Android Qcom USB Driver学习(十一)
    基于TI的FirmwareUpdate固件升级的流程分析usbapplictionlayers的数据USBProtocolPackage①/②maptocheckpasswordcorrectPackageFormat:Byte[0]=ReportIdByte[1]=ValidLength(0x21=33)Byte[2]=BSLCoreCommands(0x11RXPassword)Byte[3]=Val......
  • Qdrant官方快速入门和教程简化版
    Qdrant官方快速入门和教程简化版说明:首次发表日期:2024-08-28Qdrant官方文档:https://qdrant.tech/documentation/关于阅读Qdrant一小部分的官方文档,并使用中文简化记录下,更多请阅读官方文档。使用Docker本地部署Qdrantdockerpullqdrant/qdrantdockerrun-d-p6333:6......
  • Android 常用的性能分析工具详解:GPU呈现模式
    此篇将重点介绍几种常用的Android性能分析工具:一、Logcat日志选取Tag=ActivityManager,可以粗略地知道界面Displaying的时间消耗。当我们打开一个Activity的时候,log会打印一串log如下:I/ActivityManager﹕Displayedxxx.xxx.xxx/TestActivity:+1s272ms(total+3s843ms)第一......
  • WPF draw thumbs on livecharts and drag drop thumb
    //xaml<Windowx:Class="WpfApp299.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.mi......
  • Android开发 - “效验和”效验数据在传输或存储过程中是否出错解析
    校验和的基本原理校验和的基本原理非常简单,就是把一组数据中的所有字节(或者其他单位)的数值相加,然后得到一个总和,这个总和就是所谓的“校验和”。在传输数据时,发送方会把数据和校验和一起发送出去;接收方收到数据后,也会计算一次校验和,然后与发送方提供的校验和进行比较。如果两个......
  • Android开发 - Runnable 类任务接口定义与后台任务待办解析
    什么是RunnableRunnable接口是用来定义一个任务的接口,这个任务可以在线程中执行。通俗地说,它就像一个“待办事项”,用来描述需要在一个单独的线程中完成的工作。Runnable接口非常简单,只定义了一个方法:run()。当一个类实现了Runnable接口时,它需要提供这个方法的实现,里面写上......
  • 如何在Android上恢复永久删除的照片?
    您是否曾经不小心从Android手机中删除了珍贵的照片,并以为它们已经永远消失了?不要恐慌。我们为您提供了有关如何在Android上恢复永久删除的照片的指南。无论是怀旧之旅还是您需要找回的重要记忆,我们都会引导您完成安全、轻松地取回这些照片的步骤。 第1部分:是否可以恢复......
  • WPF thumb Drag DragDelta,DragStarted,DragCompleted
    //xaml<Windowx:Class="WpfApp302.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.mi......
  • 使用跨平台库SixLabors.ImageSharp.Drawing生成图片验证码
     ///<summary>///绘制图片验证码///</summary>///<paramname="webRootPath"></param>///<paramname="width"></param>///<paramname="height"></param>///<returns>&......