[iyunv@Server1 ~]# id mysql
uid=498(mysql) gid=500(mysql) groups=500(mysql)
[iyunv@Server1 ~]# ls /usr/local/mysql/
bin COPYING data docs include lib man mysql-test README scripts share sql-bench support-files
[iyunv@Server2 ~]# id mysql
uid=498(mysql) gid=500(mysql) groups=500(mysql)
[iyunv@Server2 ~]# ls /usr/local/mysql/
bin COPYING data docs include lib man mysql-test README scripts share sql-bench support-files
Jan 22 16:14:36 Server1 Keepalived[21561]: Opening file '/etc/keepalived/keepalived.conf'.
Jan 22 16:14:36 Server1 Keepalived[21562]: Starting Healthcheck child process, pid=21563
Jan 22 16:14:36 Server1 Keepalived[21562]: Starting VRRP child process, pid=21564
Jan 22 16:14:36 Server1 Keepalived_healthcheckers[21563]: Netlink reflector reports IP 10.17.83.174 added
Jan 22 16:14:36 Server1 Keepalived_healthcheckers[21563]: Netlink reflector reports IP 192.168.6.174 added
Jan 22 16:14:36 Server1 Keepalived_healthcheckers[21563]: Netlink reflector reports IP fe80::250:56ff:feb5:725f added
Jan 22 16:14:36 Server1 Keepalived_healthcheckers[21563]: Netlink reflector reports IP fe80::250:56ff:feb5:5a15 added
Jan 22 16:14:36 Server1 Keepalived_healthcheckers[21563]: Registering Kernel netlink reflector
Jan 22 16:14:36 Server1 Keepalived_healthcheckers[21563]: Registering Kernel netlink command channel
Jan 22 16:14:36 Server1 Keepalived_healthcheckers[21563]: Opening file '/etc/keepalived/keepalived.conf'.
Jan 22 16:14:36 Server1 Keepalived_vrrp[21564]: Netlink reflector reports IP 10.17.83.174 added
Jan 22 16:14:36 Server1 Keepalived_vrrp[21564]: Netlink reflector reports IP 192.168.6.174 added
Jan 22 16:14:36 Server1 Keepalived_vrrp[21564]: Netlink reflector reports IP fe80::250:56ff:feb5:725f added
Jan 22 16:14:36 Server1 Keepalived_vrrp[21564]: Netlink reflector reports IP fe80::250:56ff:feb5:5a15 added
Jan 22 16:14:36 Server1 Keepalived_vrrp[21564]: Registering Kernel netlink reflector
Jan 22 16:14:36 Server1 Keepalived_vrrp[21564]: Registering Kernel netlink command channel
Jan 22 16:14:36 Server1 Keepalived_vrrp[21564]: Registering gratuitous ARP shared channel
Jan 22 16:14:36 Server1 Keepalived_vrrp[21564]: Opening file '/etc/keepalived/keepalived.conf'.
Jan 22 16:14:36 Server1 Keepalived_vrrp[21564]: Truncating auth_pass to 8 characters
Jan 22 16:14:51 Server1 Keepalived_vrrp[21564]: VRRP_Instance(MySQL_HA_1) removing protocol VIPs.
Jan 22 16:14:51 Server1 Keepalived_vrrp[21564]: SECURITY VIOLATION - scripts are being executed but script_security not enabled.
Jan 22 16:14:51 Server1 Keepalived_vrrp[21564]: Sync group MySQL_HA_G1 has only 1 virtual router(s) - removing
Jan 22 16:14:51 Server1 Keepalived_vrrp[21564]: Using LinkWatch kernel netlink reflector...
Jan 22 16:14:51 Server1 Keepalived_vrrp[21564]: VRRP_Instance(MySQL_HA_1) Entering BACKUP STATE
Jan 22 16:14:51 Server1 Keepalived_vrrp[21564]: VRRP sockpool: [ifindex(3), proto(112), unicast(0), fd(10,11)]
Jan 22 16:14:51 Server1 Keepalived_healthcheckers[21563]: Using LinkWatch kernel netlink reflector...
Jan 22 16:14:51 Server1 Keepalived_vrrp[21564]: pid 21567 exited with status 1
Jan 22 16:14:51 Server1 Keepalived_vrrp[21564]: VRRP_Script(chage_status) succeeded
Jan 22 16:14:57 Server1 Keepalived_vrrp[21564]: VRRP_Script(chk_mysql) succeeded
Jan 22 16:14:58 Server1 Keepalived_vrrp[21564]: VRRP_Instance(MySQL_HA_1) Transition to MASTER STATE
Jan 22 16:14:59 Server1 Keepalived_vrrp[21564]: VRRP_Instance(MySQL_HA_1) Changing effective priority from 100 to 120
Jan 22 16:15:00 Server1 Keepalived_vrrp[21564]: VRRP_Instance(MySQL_HA_1) Entering MASTER STATE
Jan 22 16:15:00 Server1 Keepalived_vrrp[21564]: VRRP_Instance(MySQL_HA_1) setting protocol VIPs.
Jan 22 16:15:00 Server1 Keepalived_vrrp[21564]: Sending gratuitous ARP on eth1 for 192.168.6.176
Jan 22 16:15:00 Server1 Keepalived_healthcheckers[21563]: Netlink reflector reports IP 192.168.6.176 added
Jan 22 16:15:00 Server1 Keepalived_vrrp[21564]: VRRP_Instance(MySQL_HA_1) Sending/queueing gratuitous ARPs on eth1 for 192.168.6.176
Jan 22 16:15:00 Server1 Keepalived_vrrp[21564]: Sending gratuitous ARP on eth1 for 192.168.6.176
然后再启动Server2的keepalived服务,查看keepalived日志
1
2
3
4
5
6
7
8
9
10
11
12
13
Jan 22 16:14:57 localhost Keepalived[26882]: Opening file '/etc/keepalived/keepalived.conf'.
Jan 22 16:14:57 localhost Keepalived[26882]: daemon is already running
Jan 22 16:15:01 localhost Keepalived_vrrp[26875]: VRRP_Instance(MySQL_HA_1) removing protocol VIPs.
Jan 22 16:15:01 localhost Keepalived_vrrp[26875]: SECURITY VIOLATION - scripts are being executed but script_security not enabled.
Jan 22 16:15:01 localhost Keepalived_vrrp[26875]: Sync group MySQL_HA_G1 has only 1 virtual router(s) - removing
Jan 22 16:15:01 localhost Keepalived_vrrp[26875]: Using LinkWatch kernel netlink reflector...
Jan 22 16:15:01 localhost Keepalived_vrrp[26875]: VRRP_Instance(MySQL_HA_1) Entering BACKUP STATE
Jan 22 16:15:01 localhost Keepalived_vrrp[26875]: VRRP sockpool: [ifindex(3), proto(112), unicast(0), fd(10,11)]
Jan 22 16:15:01 localhost Keepalived_healthcheckers[26874]: Using LinkWatch kernel netlink reflector...
Jan 22 16:15:01 localhost Keepalived_vrrp[26875]: VRRP_Script(chage_status) succeeded
Jan 22 16:15:01 localhost Keepalived_vrrp[26875]: pid 26885 exited with status 1
Jan 22 16:15:07 localhost Keepalived_vrrp[26875]: VRRP_Script(chk_mysql) succeeded
Jan 22 16:15:09 localhost Keepalived_vrrp[26875]: VRRP_Instance(MySQL_HA_1) Changing effective priority from 90 to 110
Jan 22 16:29:58 Server1 Keepalived_vrrp[21564]: VRRP_Script(chk_mysql) failed
Jan 22 16:29:58 Server1 Keepalived_vrrp[21564]: VRRP_Instance(MySQL_HA_1) Changing effective priority from 120 to 100
Jan 22 16:29:58 Server1 Keepalived_vrrp[21564]: VRRP_Instance(MySQL_HA_1) Received advert with higher priority 110, ours 100
Jan 22 16:29:58 Server1 Keepalived_vrrp[21564]: VRRP_Instance(MySQL_HA_1) Entering BACKUP STATE
Jan 22 16:29:58 Server1 Keepalived_vrrp[21564]: VRRP_Instance(MySQL_HA_1) removing protocol VIPs.
Jan 22 16:29:58 Server1 Keepalived_healthcheckers[21563]: Netlink reflector reports IP 192.168.6.176 removed
Jan 22 16:30:04 Server1 Keepalived_vrrp[21564]: pid 23227 exited with status 1
Jan 22 16:30:10 Server1 Keepalived_vrrp[21564]: pid 23233 exited with status 1
Jan 22 16:30:16 Server1 Keepalived_vrrp[21564]: VRRP_Script(chk_mysql) succeeded
Jan 22 16:30:16 Server1 Keepalived_vrrp[21564]: VRRP_Instance(MySQL_HA_1) Changing effective priority from 100 to 120
查看Server2的keepalived日志
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Jan 22 16:15:09 localhost Keepalived_vrrp[26875]: VRRP_Instance(MySQL_HA_1) Changing effective priority from 90 to 110
Jan 22 16:17:01 localhost Keepalived_vrrp[26875]: pid 27059 exited with status 126
Jan 22 16:29:57 localhost Keepalived_vrrp[26875]: VRRP_Instance(MySQL_HA_1) forcing a new MASTER election
Jan 22 16:29:59 localhost Keepalived_vrrp[26875]: VRRP_Instance(MySQL_HA_1) Transition to MASTER STATE
Jan 22 16:30:01 localhost Keepalived_vrrp[26875]: VRRP_Instance(MySQL_HA_1) Entering MASTER STATE
Jan 22 16:30:01 localhost Keepalived_vrrp[26875]: VRRP_Instance(MySQL_HA_1) setting protocol VIPs.
Jan 22 16:30:01 localhost Keepalived_vrrp[26875]: Sending gratuitous ARP on eth1 for 192.168.6.176
Jan 22 16:30:01 localhost Keepalived_healthcheckers[26874]: Netlink reflector reports IP 192.168.6.176 added
Jan 22 16:30:01 localhost Keepalived_vrrp[26875]: VRRP_Instance(MySQL_HA_1) Sending/queueing gratuitous ARPs on eth1 for 192.168.6.176
Jan 22 16:30:01 localhost Keepalived_vrrp[26875]: Sending gratuitous ARP on eth1 for 192.168.6.176
Jan 22 16:30:01 localhost Keepalived_vrrp[26875]: Sending gratuitous ARP on eth1 for 192.168.6.176
Jan 22 16:30:01 localhost Keepalived_vrrp[26875]: Sending gratuitous ARP on eth1 for 192.168.6.176
Jan 22 16:30:01 localhost Keepalived_vrrp[26875]: Sending gratuitous ARP on eth1 for 192.168.6.176
Jan 22 16:30:01 localhost kernel: EXT4-fs (sdb1): warning: mounting fs with errors, running e2fsck is recommended
Jan 22 16:30:01 localhost kernel: EXT4-fs (sdb1): mounted filesystem with ordered data mode. Opts:
Jan 22 16:30:06 localhost Keepalived_vrrp[26875]: Sending gratuitous ARP on eth1 for 192.168.6.176
Jan 22 16:30:06 localhost Keepalived_vrrp[26875]: VRRP_Instance(MySQL_HA_1) Sending/queueing gratuitous ARPs on eth1 for 192.168.6.176
Jan 22 16:30:06 localhost Keepalived_vrrp[26875]: Sending gratuitous ARP on eth1 for 192.168.6.176
[iyunv@Server1 ~]# ip addr | grep eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
inet 192.168.6.174/24 brd 192.168.6.255 scope global eth1
[iyunv@Server1 ~]# ps -ef | grep mysql
root 23617 25788 0 16:34 pts/1 00:00:00 grep mysql
3、再测试Server2异常时,是否将服务转移至Server1上
1
2
[iyunv@Server2 ~]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
[iyunv@Server1 ~]# ip addr | grep eth1
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN qlen 1000
inet 192.168.6.174/24 brd 192.168.6.255 scope global eth1
[iyunv@Server1 ~]# ps -ef | grep mysql
root 24553 25788 0 16:42 pts/1 00:00:00 grep mysql
[iyunv@Server2 ~]# ip a | grep eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
inet 192.168.6.175/24 brd 192.168.6.255 scope global eth1