系统环境
标题 |
版本 |
备注 |
系统版本 |
ubuntu 22.04.3 LTS (Jammy Jellyfish) |
- |
内核版本 |
5.15.0-88-generic #98-Ubuntu SMP Mon Oct 2 15:18:56 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux |
- |
Keepalived |
v2.2.8 |
- |
Master |
192.168.3.101 |
主节点 |
Backup |
192.168.3.102 |
备节点 |
VIP |
192.168.3.222 |
VIP 地址 |
先决条件
在 Master 和 Backup 机器上安装好 keepalived 服务(注意:无需启动服务)
主备配置
Master(192.168.3.101) 配置
1.编辑 keepalived 主配置文件 /usr/local/keepalived/etc/keepalived/keepalived.conf
,配置内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| $ sudo sh -c 'cat << EOF > /usr/local/keepalived/etc/keepalived/keepalived.conf ! Configuration File for keepalived
global_defs { notification_email { root@localhost } notification_email_from veazhi@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id veazhi101 vrrp_mcast_group4 224.0.0.111 }
vrrp_instance VI_1 { state MASTER interface enp1s0 virtual_router_id 101 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.3.222 }
notify_master "/usr/local/keepalived/etc/keepalived/notify.sh master" notify_backup "/usr/local/keepalived/etc/keepalived/notify.sh backup" notify_fault "/usr/local/keepalived/etc/keepalived/notify.sh fault" } EOF'
|
Backup(192.168.3.102) 配置
1.编辑 keepalived 主配置文件 /usr/local/keepalived/etc/keepalived/keepalived.conf
,配置内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| $ sudo sh -c 'cat << EOF > /usr/local/keepalived/etc/keepalived/keepalived.conf ! Configuration File for keepalived
global_defs { notification_email { root@localhost } notification_email_from veazhi@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id veazhi102 vrrp_mcast_group4 224.0.0.111 }
vrrp_instance VI_1 { state BACKUP interface enp1s0 virtual_router_id 101 priority 99 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.3.222 }
notify_master "/usr/local/keepalived/etc/keepalived/notify.sh master" notify_backup "/usr/local/keepalived/etc/keepalived/notify.sh backup" notify_fault "/usr/local/keepalived/etc/keepalived/notify.sh fault" } EOF'
|
注意事项
- 主备机参数
router_id
要不同(唯一);
- 主备机参数
state
要不同,主的为 Master,备的为 Backup;
- 主备机参数
virtual_router_id
要一致(即相同);
- 主备机参数
priority
要不同,主的值要大于备的值;
- 主备机参数
interface
要根据机器网卡实际名称进行配置;
- 主备机参数
virtual_ipaddress
要相同(即相同 VIP);
通知脚本
1.在 Master 和 Backup 的 /usr/local/keepalived/etc/keepalived/
目录下新建 notify.sh
文件,内容为(2 台机器上的脚本内容一样):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| $ sudo sh -c 'cat << EOF > /usr/local/keepalived/etc/keepalived/notify.sh #!/usr/bin/env bash
contact="root@localhost" notify() { local mailsubject="\$(hostname) to be \$1, vip floating" local 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 EOF'
|
2.赋予脚本可执行权限:
1
| $ sudo chmod +x /usr/local/keepalived/etc/keepalived/notify.sh
|
主备测试
在启动 keepalived 服务之前,先查看下 2 台机器上的 IP 情况:
Master(192.168.3.101)
1 2 3 4 5 6 7 8 9 10 11 12 13
| $ 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: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 52:54:00:99:26:6d brd ff:ff:ff:ff:ff:ff inet 192.168.3.101/24 brd 192.168.3.255 scope global enp1s0 valid_lft forever preferred_lft forever inet6 fe80::5054:ff:fe99:266d/64 scope link valid_lft forever preferred_lft forever
|
Backup(192.168.3.102)
1 2 3 4 5 6 7 8 9 10 11 12 13
| $ 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: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 52:54:00:2b:a8:e1 brd ff:ff:ff:ff:ff:ff inet 192.168.3.102/24 brd 192.168.3.255 scope global enp1s0 valid_lft forever preferred_lft forever inet6 fe80::5054:ff:fe2b:a8e1/64 scope link valid_lft forever preferred_lft forever
|
首次启动主备
Master(192.168.3.101)
1.启动 keepalived 服务:
1
| $ sudo systemctl start keepalived.service
|
同时,动态监听系统日志输出:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| $ tail -f /var/log/syslog Apr 1 23:07:53 vm001-ubuntu2204 systemd[1]: Starting LVS and VRRP High Availability Monitor... Apr 1 23:07:53 vm001-ubuntu2204 Keepalived[42566]: Starting Keepalived v2.2.8 (04/04,2023), git commit v2.2.7-154-g292b299e+ Apr 1 23:07:53 vm001-ubuntu2204 systemd[1]: Started LVS and VRRP High Availability Monitor. Apr 1 23:07:53 vm001-ubuntu2204 Keepalived[42566]: WARNING - keepalived was built for newer Linux 5.15.143, running on Linux 5.15.0-100-generic Apr 1 23:07:53 vm001-ubuntu2204 Keepalived[42566]: Command line: '/usr/local/keepalived/sbin/keepalived' '-D' Apr 1 23:07:53 vm001-ubuntu2204 Keepalived[42566]: Opening file '/usr/local/keepalived/etc/keepalived/keepalived.conf'. Apr 1 23:07:53 vm001-ubuntu2204 Keepalived[42566]: Configuration file /usr/local/keepalived/etc/keepalived/keepalived.conf Apr 1 23:07:53 vm001-ubuntu2204 Keepalived[42567]: NOTICE: setting config option max_auto_priority should result in better keepalived performance Apr 1 23:07:53 vm001-ubuntu2204 Keepalived[42567]: Starting VRRP child process, pid=42568 Apr 1 23:07:53 vm001-ubuntu2204 Keepalived_vrrp[42568]: Registering Kernel netlink reflector Apr 1 23:07:53 vm001-ubuntu2204 Keepalived_vrrp[42568]: Registering Kernel netlink command channel Apr 1 23:07:53 vm001-ubuntu2204 Keepalived_vrrp[42568]: Script user 'keepalived_script' does not exist Apr 1 23:07:53 vm001-ubuntu2204 Keepalived_vrrp[42568]: WARNING - script '/usr/local/keepalived/etc/keepalived/notify.sh' is not executable for uid:gid 0:0 - disabling. Apr 1 23:07:53 vm001-ubuntu2204 Keepalived_vrrp[42568]: message repeated 2 times: [ WARNING - script '/usr/local/keepalived/etc/keepalived/notify.sh' is not executable for uid:gid 0:0 - disabling.] Apr 1 23:07:53 vm001-ubuntu2204 Keepalived_vrrp[42568]: SECURITY VIOLATION - scripts are being executed but script_security not enabled. Apr 1 23:07:53 vm001-ubuntu2204 Keepalived_vrrp[42568]: Assigned address 192.168.3.101 for interface enp1s0 Apr 1 23:07:53 vm001-ubuntu2204 Keepalived_vrrp[42568]: Assigned address fe80::5054:ff:fe99:266d for interface enp1s0 Apr 1 23:07:53 vm001-ubuntu2204 Keepalived_vrrp[42568]: Registering gratuitous ARP shared channel Apr 1 23:07:53 vm001-ubuntu2204 Keepalived_vrrp[42568]: (VI_1) removing VIPs. Apr 1 23:07:53 vm001-ubuntu2204 Keepalived[42567]: Startup complete Apr 1 23:07:53 vm001-ubuntu2204 Keepalived_vrrp[42568]: (VI_1) Entering BACKUP STATE (init) Apr 1 23:07:53 vm001-ubuntu2204 Keepalived_vrrp[42568]: VRRP sockpool: [ifindex( 2), family(IPv4), proto(112), fd(12,13) multicast, address(224.0.0.111)] Apr 1 23:07:56 vm001-ubuntu2204 Keepalived_vrrp[42568]: (VI_1) Receive advertisement timeout Apr 1 23:07:56 vm001-ubuntu2204 Keepalived_vrrp[42568]: (VI_1) Entering MASTER STATE Apr 1 23:07:56 vm001-ubuntu2204 Keepalived_vrrp[42568]: (VI_1) setting VIPs. Apr 1 23:07:56 vm001-ubuntu2204 Keepalived_vrrp[42568]: (VI_1) Sending/queueing gratuitous ARPs on enp1s0 for 192.168.3.222 Apr 1 23:07:56 vm001-ubuntu2204 Keepalived_vrrp[42568]: Sending gratuitous ARP on enp1s0 for 192.168.3.222 Apr 1 23:07:56 vm001-ubuntu2204 Keepalived_vrrp[42568]: message repeated 4 times: [ Sending gratuitous ARP on enp1s0 for 192.168.3.222] Apr 1 23:08:01 vm001-ubuntu2204 Keepalived_vrrp[42568]: (VI_1) Sending/queueing gratuitous ARPs on enp1s0 for 192.168.3.222 Apr 1 23:08:01 vm001-ubuntu2204 Keepalived_vrrp[42568]: Sending gratuitous ARP on enp1s0 for 192.168.3.222
|
2.再次查看 IP :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| $ 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: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 52:54:00:99:26:6d brd ff:ff:ff:ff:ff:ff inet 192.168.3.101/24 brd 192.168.3.255 scope global enp1s0 valid_lft forever preferred_lft forever inet 192.168.3.222/32 scope global enp1s0 valid_lft forever preferred_lft forever inet6 fe80::5054:ff:fe99:266d/64 scope link valid_lft forever preferred_lft forever
|
可以看到,此时的网卡下面多处了一个 IP ,即我们配置的 VIP 地址!
Backup(192.168.3.102)
1.启动 keepalived 服务:
1
| $ sudo systemctl start keepalived.service
|
同时,动态监听系统日志输出:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| $ tail -f /var/log/syslog Apr 1 23:08:24 vm002-ubuntu systemd[1]: Starting LVS and VRRP High Availability Monitor... Apr 1 23:08:24 vm002-ubuntu systemd[1]: Started LVS and VRRP High Availability Monitor. Apr 1 23:08:24 vm002-ubuntu Keepalived[44316]: Starting Keepalived v2.2.8 (04/04,2023), git commit v2.2.7-154-g292b299e+ Apr 1 23:08:24 vm002-ubuntu Keepalived[44316]: WARNING - keepalived was built for newer Linux 5.15.143, running on Linux 5.15.0-100-generic Apr 1 23:08:24 vm002-ubuntu Keepalived[44316]: Command line: '/usr/local/keepalived/sbin/keepalived' '-D' Apr 1 23:08:24 vm002-ubuntu Keepalived[44316]: Opening file '/usr/local/keepalived/etc/keepalived/keepalived.conf'. Apr 1 23:08:24 vm002-ubuntu Keepalived[44316]: Configuration file /usr/local/keepalived/etc/keepalived/keepalived.conf Apr 1 23:08:24 vm002-ubuntu Keepalived[44317]: NOTICE: setting config option max_auto_priority should result in better keepalived performance Apr 1 23:08:24 vm002-ubuntu Keepalived[44317]: Starting VRRP child process, pid=44318 Apr 1 23:08:24 vm002-ubuntu Keepalived_vrrp[44318]: Registering Kernel netlink reflector Apr 1 23:08:24 vm002-ubuntu Keepalived_vrrp[44318]: Registering Kernel netlink command channel Apr 1 23:08:24 vm002-ubuntu Keepalived_vrrp[44318]: Script user 'keepalived_script' does not exist Apr 1 23:08:24 vm002-ubuntu Keepalived_vrrp[44318]: WARNING - script '/usr/local/keepalived/etc/keepalived/notify.sh' is not executable for uid:gid 0:0 - disabling. Apr 1 23:08:24 vm002-ubuntu Keepalived_vrrp[44318]: message repeated 2 times: [ WARNING - script '/usr/local/keepalived/etc/keepalived/notify.sh' is not executable for uid:gid 0:0 - disabling.] Apr 1 23:08:24 vm002-ubuntu Keepalived_vrrp[44318]: SECURITY VIOLATION - scripts are being executed but script_security not enabled. Apr 1 23:08:24 vm002-ubuntu Keepalived_vrrp[44318]: Assigned address 192.168.3.102 for interface enp1s0 Apr 1 23:08:24 vm002-ubuntu Keepalived_vrrp[44318]: Assigned address fe80::5054:ff:fe2b:a8e1 for interface enp1s0 Apr 1 23:08:24 vm002-ubuntu Keepalived_vrrp[44318]: Registering gratuitous ARP shared channel Apr 1 23:08:24 vm002-ubuntu Keepalived_vrrp[44318]: (VI_1) removing VIPs. Apr 1 23:08:24 vm002-ubuntu Keepalived[44317]: Startup complete Apr 1 23:08:24 vm002-ubuntu Keepalived_vrrp[44318]: (VI_1) Entering BACKUP STATE (init) Apr 1 23:08:24 vm002-ubuntu Keepalived_vrrp[44318]: VRRP sockpool: [ifindex( 2), family(IPv4), proto(112), fd(12,13) multicast, address(224.0.0.111)]
|
2.再次查看本机网卡:
1 2 3 4 5 6 7 8 9 10 11 12 13
| $ 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: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 52:54:00:2b:a8:e1 brd ff:ff:ff:ff:ff:ff inet 192.168.3.102/24 brd 192.168.3.255 scope global enp1s0 valid_lft forever preferred_lft forever inet6 fe80::5054:ff:fe2b:a8e1/64 scope link valid_lft forever preferred_lft forever
|
可以看到,此时的网卡内容并没有变动!
模拟主故障
Master(192.168.3.101)
1.停止 keepalived 服务:
1
| $ sudo systemctl stop keepalived.service
|
同时,动态监听系统日志输出:
1 2 3 4 5 6 7 8 9 10 11
| $ tail -f /var/log/syslog Apr 1 23:08:01 vm001-ubuntu2204 Keepalived_vrrp[42568]: message repeated 4 times: [ Sending gratuitous ARP on enp1s0 for 192.168.3.222] Apr 1 23:08:58 vm001-ubuntu2204 Keepalived[42567]: Stopping Apr 1 23:08:58 vm001-ubuntu2204 systemd[1]: Stopping LVS and VRRP High Availability Monitor... Apr 1 23:08:58 vm001-ubuntu2204 Keepalived_vrrp[42568]: (VI_1) sent 0 priority Apr 1 23:08:58 vm001-ubuntu2204 Keepalived_vrrp[42568]: (VI_1) removing VIPs. Apr 1 23:08:59 vm001-ubuntu2204 Keepalived_vrrp[42568]: Stopped - used 0.012644 user time, 0.000000 system time Apr 1 23:08:59 vm001-ubuntu2204 Keepalived[42567]: CPU usage (self/children) user: 0.000620/0.013198 system: 0.000000/0.000000 Apr 1 23:08:59 vm001-ubuntu2204 Keepalived[42567]: Stopped Keepalived v2.2.8 (04/04,2023), git commit v2.2.7-154-g292b299e+ Apr 1 23:08:59 vm001-ubuntu2204 systemd[1]: keepalived.service: Deactivated successfully. Apr 1 23:08:59 vm001-ubuntu2204 systemd[1]: Stopped LVS and VRRP High Availability Monitor.
|
2.再次查看本机网卡:
1 2 3 4 5 6 7 8 9 10 11 12 13
| $ 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: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 52:54:00:99:26:6d brd ff:ff:ff:ff:ff:ff inet 192.168.3.101/24 brd 192.168.3.255 scope global enp1s0 valid_lft forever preferred_lft forever inet6 fe80::5054:ff:fe99:266d/64 scope link valid_lft forever preferred_lft forever
|
可以看到,此时主上的 VIP 地址已经消失!!!!
Backup(192.168.3.102)
1.动态监控系统日志输出:
1 2 3 4 5 6 7 8 9 10 11
| $ tail -f /var/log/syslog Apr 1 23:08:58 vm002-ubuntu Keepalived_vrrp[44318]: (VI_1) Backup received priority 0 advertisement Apr 1 23:08:59 vm002-ubuntu Keepalived_vrrp[44318]: (VI_1) Receive advertisement timeout Apr 1 23:08:59 vm002-ubuntu Keepalived_vrrp[44318]: (VI_1) Entering MASTER STATE Apr 1 23:08:59 vm002-ubuntu Keepalived_vrrp[44318]: (VI_1) setting VIPs. Apr 1 23:08:59 vm002-ubuntu Keepalived_vrrp[44318]: (VI_1) Sending/queueing gratuitous ARPs on enp1s0 for 192.168.3.222 Apr 1 23:08:59 vm002-ubuntu Keepalived_vrrp[44318]: Sending gratuitous ARP on enp1s0 for 192.168.3.222 Apr 1 23:08:59 vm002-ubuntu Keepalived_vrrp[44318]: message repeated 4 times: [ Sending gratuitous ARP on enp1s0 for 192.168.3.222] Apr 1 23:09:04 vm002-ubuntu Keepalived_vrrp[44318]: (VI_1) Sending/queueing gratuitous ARPs on enp1s0 for 192.168.3.222 Apr 1 23:09:04 vm002-ubuntu Keepalived_vrrp[44318]: Sending gratuitous ARP on enp1s0 for 192.168.3.222 Apr 1 23:09:04 vm002-ubuntu Keepalived_vrrp[44318]: message repeated 4 times: [ Sending gratuitous ARP on enp1s0 for 192.168.3.222]
|
2.再次查看本机网卡:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| $ 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: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 52:54:00:2b:a8:e1 brd ff:ff:ff:ff:ff:ff inet 192.168.3.102/24 brd 192.168.3.255 scope global enp1s0 valid_lft forever preferred_lft forever inet 192.168.3.222/32 scope global enp1s0 valid_lft forever preferred_lft forever inet6 fe80::5054:ff:fe2b:a8e1/64 scope link valid_lft forever preferred_lft forever
|
可以看到,此时备上的网卡内容多处了 VIP 地址!!!!
模拟主恢复
Master(192.168.3.101)
1.启动 keepalived 服务:
1
| $ sudo systemctl start keepalived.service
|
同时,动态监控系统日志输出:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| $ tail -f /var/log/syslog Apr 1 23:50:58 vm001-ubuntu2204 systemd[1]: Starting LVS and VRRP High Availability Monitor... Apr 1 23:50:58 vm001-ubuntu2204 Keepalived[42642]: Starting Keepalived v2.2.8 (04/04,2023), git commit v2.2.7-154-g292b299e+ Apr 1 23:50:58 vm001-ubuntu2204 systemd[1]: Started LVS and VRRP High Availability Monitor. Apr 1 23:50:58 vm001-ubuntu2204 Keepalived[42642]: WARNING - keepalived was built for newer Linux 5.15.143, running on Linux 5.15.0-100-generic Apr 1 23:50:58 vm001-ubuntu2204 Keepalived[42642]: Command line: '/usr/local/keepalived/sbin/keepalived' '-D' Apr 1 23:50:58 vm001-ubuntu2204 Keepalived[42642]: Opening file '/usr/local/keepalived/etc/keepalived/keepalived.conf'. Apr 1 23:50:58 vm001-ubuntu2204 Keepalived[42642]: Configuration file /usr/local/keepalived/etc/keepalived/keepalived.conf Apr 1 23:50:58 vm001-ubuntu2204 Keepalived[42643]: NOTICE: setting config option max_auto_priority should result in better keepalived performance Apr 1 23:50:58 vm001-ubuntu2204 Keepalived[42643]: Starting VRRP child process, pid=42644 Apr 1 23:50:58 vm001-ubuntu2204 Keepalived_vrrp[42644]: Registering Kernel netlink reflector Apr 1 23:50:58 vm001-ubuntu2204 Keepalived_vrrp[42644]: Registering Kernel netlink command channel Apr 1 23:50:58 vm001-ubuntu2204 Keepalived_vrrp[42644]: Script user 'keepalived_script' does not exist Apr 1 23:50:58 vm001-ubuntu2204 Keepalived_vrrp[42644]: WARNING - script '/usr/local/keepalived/etc/keepalived/notify.sh' is not executable for uid:gid 0:0 - disabling. Apr 1 23:50:58 vm001-ubuntu2204 Keepalived_vrrp[42644]: message repeated 2 times: [ WARNING - script '/usr/local/keepalived/etc/keepalived/notify.sh' is not executable for uid:gid 0:0 - disabling.] Apr 1 23:50:58 vm001-ubuntu2204 Keepalived_vrrp[42644]: SECURITY VIOLATION - scripts are being executed but script_security not enabled. Apr 1 23:50:58 vm001-ubuntu2204 Keepalived_vrrp[42644]: Assigned address 192.168.3.101 for interface enp1s0 Apr 1 23:50:58 vm001-ubuntu2204 Keepalived_vrrp[42644]: Assigned address fe80::5054:ff:fe99:266d for interface enp1s0 Apr 1 23:50:58 vm001-ubuntu2204 Keepalived_vrrp[42644]: Registering gratuitous ARP shared channel Apr 1 23:50:58 vm001-ubuntu2204 Keepalived_vrrp[42644]: (VI_1) removing VIPs. Apr 1 23:50:58 vm001-ubuntu2204 Keepalived[42643]: Startup complete Apr 1 23:50:58 vm001-ubuntu2204 Keepalived_vrrp[42644]: (VI_1) Entering BACKUP STATE (init) Apr 1 23:50:58 vm001-ubuntu2204 Keepalived_vrrp[42644]: VRRP sockpool: [ifindex( 2), family(IPv4), proto(112), fd(12,13) multicast, address(224.0.0.111)] Apr 1 23:50:58 vm001-ubuntu2204 Keepalived_vrrp[42644]: (VI_1) received lower priority (99) advert from 192.168.3.102 - discarding Apr 1 23:51:01 vm001-ubuntu2204 Keepalived_vrrp[42644]: message repeated 3 times: [ (VI_1) received lower priority (99) advert from 192.168.3.102 - discarding] Apr 1 23:51:01 vm001-ubuntu2204 Keepalived_vrrp[42644]: (VI_1) Receive advertisement timeout Apr 1 23:51:01 vm001-ubuntu2204 Keepalived_vrrp[42644]: (VI_1) Entering MASTER STATE Apr 1 23:51:01 vm001-ubuntu2204 Keepalived_vrrp[42644]: (VI_1) setting VIPs. Apr 1 23:51:01 vm001-ubuntu2204 Keepalived_vrrp[42644]: (VI_1) Sending/queueing gratuitous ARPs on enp1s0 for 192.168.3.222 Apr 1 23:51:01 vm001-ubuntu2204 Keepalived_vrrp[42644]: Sending gratuitous ARP on enp1s0 for 192.168.3.222 Apr 1 23:51:01 vm001-ubuntu2204 Keepalived_vrrp[42644]: message repeated 4 times: [ Sending gratuitous ARP on enp1s0 for 192.168.3.222] Apr 1 23:51:06 vm001-ubuntu2204 Keepalived_vrrp[42644]: (VI_1) Sending/queueing gratuitous ARPs on enp1s0 for 192.168.3.222 Apr 1 23:51:06 vm001-ubuntu2204 Keepalived_vrrp[42644]: Sending gratuitous ARP on enp1s0 for 192.168.3.222
|
2.再次查看网卡:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| $ 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: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 52:54:00:99:26:6d brd ff:ff:ff:ff:ff:ff inet 192.168.3.101/24 brd 192.168.3.255 scope global enp1s0 valid_lft forever preferred_lft forever inet 192.168.3.222/32 scope global enp1s0 valid_lft forever preferred_lft forever inet6 fe80::5054:ff:fe99:266d/64 scope link valid_lft forever preferred_lft forever
|
可以看到,当主上的 keepalived 恢复后, VIP 又会主动漂移到主上!!!
Backup(192.168.3.102)
1.动态监控系统日志输出:
1 2 3 4
| $ tail -f /var/log/syslog Apr 1 23:51:01 vm002-ubuntu Keepalived_vrrp[44318]: (VI_1) Master received advert from 192.168.3.101 with higher priority 100, ours 99 Apr 1 23:51:01 vm002-ubuntu Keepalived_vrrp[44318]: (VI_1) Entering BACKUP STATE Apr 1 23:51:01 vm002-ubuntu Keepalived_vrrp[44318]: (VI_1) removing VIPs.
|
2.再次查看本机网卡:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| $ ip a $ 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: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 52:54:00:2b:a8:e1 brd ff:ff:ff:ff:ff:ff inet 192.168.3.102/24 brd 192.168.3.255 scope global enp1s0 valid_lft forever preferred_lft forever inet6 fe80::5054:ff:fe2b:a8e1/64 scope link valid_lft forever preferred_lft forever
|