1.主节点检查
[root@K8S8 keepalived-2.2.7]# systemctl status keepalived
● keepalived.service - Keepalived
Loaded: loaded (/usr/lib/systemd/system/keepalived.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2024-07-15 18:06:29 CST; 3min 6s ago
Process: 10840 ExecStart=/usr/sbin/keepalived -D (code=exited, status=0/SUCCESS)
Main PID: 10841 (keepalived)
Tasks: 2 (limit: 23492)
Memory: 1.4M
CGroup: /system.slice/keepalived.service
├─10841 /usr/sbin/keepalived -D
└─10842 /usr/sbin/keepalived -D
Jul 15 18:06:36 K8S8 Keepalived_vrrp[10842]: Sending gratuitous ARP on ens160 for 192.168.1.60
Jul 15 18:06:36 K8S8 Keepalived_vrrp[10842]: Sending gratuitous ARP on ens160 for 192.168.1.60
Jul 15 18:06:36 K8S8 Keepalived_vrrp[10842]: Sending gratuitous ARP on ens160 for 192.168.1.60
Jul 15 18:06:36 K8S8 Keepalived_vrrp[10842]: Sending gratuitous ARP on ens160 for 192.168.1.60
Jul 15 18:06:41 K8S8 Keepalived_vrrp[10842]: (VI_1) Sending/queueing gratuitous ARPs on ens160 for 192.168.1.60
Jul 15 18:06:41 K8S8 Keepalived_vrrp[10842]: Sending gratuitous ARP on ens160 for 192.168.1.60
Jul 15 18:06:41 K8S8 Keepalived_vrrp[10842]: Sending gratuitous ARP on ens160 for 192.168.1.60
Jul 15 18:06:41 K8S8 Keepalived_vrrp[10842]: Sending gratuitous ARP on ens160 for 192.168.1.60
Jul 15 18:06:41 K8S8 Keepalived_vrrp[10842]: Sending gratuitous ARP on ens160 for 192.168.1.60
Jul 15 18:06:41 K8S8 Keepalived_vrrp[10842]: Sending gratuitous ARP on ens160 for 192.168.1.60
--从节点检查。
[root@K8S7 keepalived-2.2.7]# systemctl status keepalived
● keepalived.service - Keepalived
Loaded: loaded (/usr/lib/systemd/system/keepalived.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2024-07-15 18:06:59 CST; 2min 43s ago
Process: 10283 ExecStart=/usr/sbin/keepalived -D (code=exited, status=0/SUCCESS)
Main PID: 10284 (keepalived)
Tasks: 2 (limit: 23492)
Memory: 1.4M
CGroup: /system.slice/keepalived.service
├─10284 /usr/sbin/keepalived -D
└─10285 /usr/sbin/keepalived -D
Jul 15 18:06:59 K8S7 systemd[1]: Started Keepalived.
Jul 15 18:06:59 K8S7 Keepalived_vrrp[10285]: Script user 'keepalived_script' does not exist
Jul 15 18:06:59 K8S7 Keepalived_vrrp[10285]: Script /etc/keepalived/check_k8s_api.sh cannot be accessed - No such file or d>
Jul 15 18:06:59 K8S7 Keepalived_vrrp[10285]: Disabling track script check_k8s_api since not found/accessible
Jul 15 18:06:59 K8S7 Keepalived_vrrp[10285]: Assigned address 192.168.1.18 for interface ens160
Jul 15 18:06:59 K8S7 Keepalived_vrrp[10285]: Registering gratuitous ARP shared channel
Jul 15 18:06:59 K8S7 Keepalived_vrrp[10285]: (VI_1) removing VIPs.
Jul 15 18:06:59 K8S7 Keepalived_vrrp[10285]: (VI_1) Entering BACKUP STATE (init)
Jul 15 18:06:59 K8S7 Keepalived_vrrp[10285]: VRRP sockpool: [ifindex( 2), family(IPv4), proto(112), fd(14,15) multicast, a>
Jul 15 18:06:59 K8S7 Keepalived[10284]: Startup complete
2.高可用测试。
主库关闭keepalived;
[root@K8S8 keepalived-2.2.7]# systemctl stop keepalived
[root@K8S8 keepalived-2.2.7]# ip a|grep inet
inet 127.0.0.1/8 scope host lo
inet 192.168.1.19/24 brd 192.168.1.255 scope global noprefixroute ens160
inet6 240e:39a:344:3880:20c:29ff:fea9:cad5/64 scope global dynamic noprefixroute
inet6 fe80::20c:29ff:fea9:cad5/64 scope link noprefixroute
--备库检查
---果然VIP漂移到了从库。
[root@K8S7 keepalived-2.2.7]# ip a|grep inet
inet 127.0.0.1/8 scope host lo
inet 192.168.1.18/24 brd 192.168.1.255 scope global noprefixroute ens160
inet 192.168.1.60/32 scope global ens160
[root@K8S7 keepalived-2.2.7]# systemctl status keepalived
● keepalived.service - Keepalived
Loaded: loaded (/usr/lib/systemd/system/keepalived.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2024-07-15 18:06:59 CST; 5min ago
Process: 10283 ExecStart=/usr/sbin/keepalived -D (code=exited, status=0/SUCCESS)
Main PID: 10284 (keepalived)
Tasks: 2 (limit: 23492)
Memory: 1.4M
CGroup: /system.slice/keepalived.service
├─10284 /usr/sbin/keepalived -D
└─10285 /usr/sbin/keepalived -D
Jul 15 18:11:33 K8S7 Keepalived_vrrp[10285]: Sending gratuitous ARP on ens160 for 192.168.1.60
Jul 15 18:11:33 K8S7 Keepalived_vrrp[10285]: Sending gratuitous ARP on ens160 for 192.168.1.60
Jul 15 18:11:33 K8S7 Keepalived_vrrp[10285]: Sending gratuitous ARP on ens160 for 192.168.1.60
Jul 15 18:11:33 K8S7 Keepalived_vrrp[10285]: Sending gratuitous ARP on ens160 for 192.168.1.60
Jul 15 18:11:38 K8S7 Keepalived_vrrp[10285]: (VI_1) Sending/queueing gratuitous ARPs on ens160 for 192.168.1.60
Jul 15 18:11:38 K8S7 Keepalived_vrrp[10285]: Sending gratuitous ARP on ens160 for 192.168.1.60
Jul 15 18:11:38 K8S7 Keepalived_vrrp[10285]: Sending gratuitous ARP on ens160 for 192.168.1.60
Jul 15 18:11:38 K8S7 Keepalived_vrrp[10285]: Sending gratuitous ARP on ens160 for 192.168.1.60
Jul 15 18:11:38 K8S7 Keepalived_vrrp[10285]: Sending gratuitous ARP on ens160 for 192.168.1.60
Jul 15 18:11:38 K8S7 Keepalived_vrrp[10285]: Sending gratuitous ARP on ens160 for 192.168.1.60
3.重新启动原来的主库
[root@K8S8 keepalived-2.2.7]# systemctl start keepalived
[root@K8S8 keepalived-2.2.7]# ip a|grep inet
inet 127.0.0.1/8 scope host lo
inet 192.168.1.19/24 brd 192.168.1.255 scope global noprefixroute ens160
inet6 240e:39a:344:3880:20c:29ff:fea9:cad5/64 scope global dynamic noprefixroute
inet6 fe80::20c:29ff:fea9:cad5/64 scope link noprefixroute
--由于设置,非抢占模式:nopreemt ,所以,原来的主库启动后,不会将VIP抢占。