keepalived在組播模式下全部的信息都會向224.0.0.18的組播地址發送,產生衆多的無用信息,而且會產生干擾和衝突,因此須要將其組播的模式改成單撥。這是一種安全的方法,避免局域網內有大量的keepalived形成虛擬路由id的衝突。
單薄模式須要關閉vrrp_strict,嚴格遵照vrrp協議這個選項
單薄須要在VIP實例配置段加入單播的源地址和目標地址linux
準備主機2臺vim
server | hostname | ip |
---|---|---|
keepalived | s1 | 172.20.27.10 |
keepalived | s2 | 172.20.27.11 |
1.修改keepalived配置安全
[root@s1 ~]# vim /etc/keepalived/keepalived.conf notification_email { root@mylinuxops.com } smtp_server 127.0.0.1 ! Configuration File for keepalived global_defs { notification_email { notification_email_from root@mylinuxops.com smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id s1.mylinuxops.com vrrp_skip_check_adv_addr #vrrp_strict #將嚴格遵照vrrp協議這一項關閉,不然會由於不是組播而沒法啓動keepalived vrrp_iptables vrrp_garp_interval 0 vrrp_gna_interval 0 } vrrp_instance VI_1 { state MASTER interface ens33 virtual_router_id 27 priority 100 advert_int 2 authentication { auth_type PASS auth_pass 1111 } unicast_src_ip 172.20.27.10 #配置單薄的源地址 unicast_peer { 172.20.27.11 #配置單薄的目標地址 } virtual_ipaddress { 172.20.27.100 dev ens33 label ens33:0 } }
重啓服務bash
[root@s1 ~]# systemctl restart keepalived
修改同s1節點相同的配置
修改haproxy配置文件tcp
[root@s2 ~]# vim /etc/keepalived/keepalived.conf global_defs { notification_email { root@mylinuxops.com } notification_email_from root@mylinuxops.com smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id s2.mylinuxops.com vrrp_skip_check_adv_addr #vrrp_strict vrrp_iptables vrrp_garp_interval 0 vrrp_gna_interval 0 } vrrp_instance VI_1 { state BACKUP interface ens33 virtual_router_id 27 priority 80 advert_int 2 authentication { auth_type PASS auth_pass 1111 } unicast_src_ip 172.20.27.11 #此處配置時候須要注意 unicast_peer { #地址要和s1節點上 172.20.27.10 #的地址進行互換 } virtual_ipaddress { 172.20.27.100 dev ens33 label ens33:0 } }
重啓服務ide
[root@s2 ~]# systemctl restart keepalived
在s1上抓包查看心跳信息是否發送給了s2oop
[root@s1 ~]# tcpdump -i ens33 host -nn 172.20.27.11 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes 20:28:45.733836 IP 172.20.27.10 > 172.20.27.11: VRRPv2, Advertisement, vrid 27, prio 100, authtype simple, intvl 2s, length 20 20:28:47.737157 IP 172.20.27.10 > 172.20.27.11: VRRPv2, Advertisement, vrid 27, prio 100, authtype simple, intvl 2s, length 20
將s1上的keepalive服務中止測試
[root@s1 ~]# systemctl stop keepalived
在s2主機上查看地址是否已經漂移過去rest
[root@s2 ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.20.27.11 netmask 255.255.0.0 broadcast 172.20.255.255 inet6 fe80::20c:29ff:fe4d:1ce3 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:4d:1c:e3 txqueuelen 1000 (Ethernet) RX packets 95675 bytes 8093610 (7.7 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 2172 bytes 183327 (179.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.20.27.100 netmask 255.255.255.255 broadcast 0.0.0.0 ether 00:0c:29:4d:1c:e3 txqueuelen 1000 (Ethernet) lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 6 bytes 482 (482.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 6 bytes 482 (482.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0