hangkk2008

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

复制+keepalived 切换

在主服务器关闭MySQL服务

# /etc/init.d/mysql stop

查看MySQL01 日志

# tail -f -n 100 /var/log/messages
Jul  8 17:05:56 centos02 Keepalived[3146]: Starting Keepalived v1.2.13 (03/19,2015)
Jul  8 17:05:57 centos02 Keepalived[3147]: Starting Healthcheck child process, pid=3148
Jul  8 17:05:57 centos02 Keepalived[3147]: Starting VRRP child process, pid=3149
Jul  8 17:05:57 centos02 Keepalived_vrrp[3149]: Netlink reflector reports IP 192.168.11.129 added
Jul  8 17:05:57 centos02 Keepalived_vrrp[3149]: Netlink reflector reports IP fe80::20c:29ff:fe80:315 added
Jul  8 17:05:57 centos02 Keepalived_vrrp[3149]: Registering Kernel netlink reflector
Jul  8 17:05:57 centos02 Keepalived_vrrp[3149]: Registering Kernel netlink command channel
Jul  8 17:05:57 centos02 Keepalived_vrrp[3149]: Registering gratuitous ARP shared channel
Jul  8 17:05:57 centos02 kernel: IPVS: Registered protocols (TCP, UDP, SCTP, AH, ESP)
Jul  8 17:05:57 centos02 kernel: IPVS: Connection hash table configured (size=4096, memory=64Kbytes)
Jul  8 17:05:57 centos02 kernel: IPVS: ipvs loaded.
Jul  8 17:05:57 centos02 Keepalived_healthcheckers[3148]: Netlink reflector reports IP 192.168.11.129 added
Jul  8 17:05:57 centos02 Keepalived_healthcheckers[3148]: Netlink reflector reports IP fe80::20c:29ff:fe80:315 added
Jul  8 17:05:57 centos02 Keepalived_healthcheckers[3148]: Registering Kernel netlink reflector
Jul  8 17:05:57 centos02 Keepalived_healthcheckers[3148]: Registering Kernel netlink command channel
Jul  8 17:05:57 centos02 Keepalived_vrrp[3149]: Opening file '/etc/keepalived/keepalived.conf'.
Jul  8 17:05:57 centos02 Keepalived_vrrp[3149]: Configuration is using : 62852 Bytes
Jul  8 17:05:57 centos02 Keepalived_vrrp[3149]: Using LinkWatch kernel netlink reflector...
Jul  8 17:05:57 centos02 Keepalived_vrrp[3149]: VRRP_Instance(VI_100) Entering BACKUP STATE
Jul  8 17:05:57 centos02 Keepalived_vrrp[3149]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
Jul  8 17:05:58 centos02 Keepalived_healthcheckers[3148]: Opening file '/etc/keepalived/keepalived.conf'.
Jul  8 17:05:58 centos02 Keepalived_healthcheckers[3148]: Configuration is using : 5150 Bytes
Jul  8 17:05:58 centos02 Keepalived_healthcheckers[3148]: Using LinkWatch kernel netlink reflector...
Jul  8 17:05:58 centos02 Keepalived_vrrp[3149]: VRRP_Script(vs_mysql_100) succeeded
Jul  8 17:06:13 centos02 Keepalived_vrrp[3149]: VRRP_Instance(VI_100) Transition to MASTER STATE
Jul  8 17:06:18 centos02 Keepalived_vrrp[3149]: VRRP_Instance(VI_100) Entering MASTER STATE
Jul  8 17:06:18 centos02 Keepalived_vrrp[3149]: VRRP_Instance(VI_100) setting protocol VIPs.
Jul  8 17:06:18 centos02 Keepalived_vrrp[3149]: VRRP_Instance(VI_100) Sending gratuitous ARPs on eth2 for 192.168.11.100
Jul  8 17:06:18 centos02 Keepalived_healthcheckers[3148]: Netlink reflector reports IP 192.168.11.100 added
Jul  8 17:06:23 centos02 Keepalived_vrrp[3149]: VRRP_Instance(VI_100) Sending gratuitous ARPs on eth2 for 192.168.11.100
Jul  8 17:12:50 centos02 dhclient[1001]: DHCPREQUEST on eth2 to 192.168.11.254 port 67 (xid=0x44f27ae6)
Jul  8 17:12:50 centos02 dhclient[1001]: DHCPACK from 192.168.11.254 (xid=0x44f27ae6)
Jul  8 17:12:52 centos02 dhclient[1001]: bound to 192.168.11.129 -- renewal in 855 seconds.
Jul  8 17:27:07 centos02 dhclient[1001]: DHCPREQUEST on eth2 to 192.168.11.254 port 67 (xid=0x44f27ae6)
Jul  8 17:27:07 centos02 dhclient[1001]: DHCPACK from 192.168.11.254 (xid=0x44f27ae6)
Jul  8 17:27:09 centos02 dhclient[1001]: bound to 192.168.11.129 -- renewal in 705 seconds.
Jul  8 17:38:54 centos02 dhclient[1001]: DHCPREQUEST on eth2 to 192.168.11.254 port 67 (xid=0x44f27ae6)
Jul  8 17:38:54 centos02 dhclient[1001]: DHCPACK from 192.168.11.254 (xid=0x44f27ae6)
Jul  8 17:38:56 centos02 dhclient[1001]: bound to 192.168.11.129 -- renewal in 833 seconds.
Jul  8 17:50:58 centos02 Keepalived_vrrp[3149]: VRRP_Script(vs_mysql_100) failed
Jul  8 17:50:59 centos02 Keepalived_vrrp[3149]: VRRP_Instance(VI_100) Entering FAULT STATE
Jul  8 17:50:59 centos02 Keepalived_vrrp[3149]: VRRP_Instance(VI_100) removing protocol VIPs.
Jul  8 17:50:59 centos02 Keepalived_vrrp[3149]: VRRP_Instance(VI_100) Now in FAULT state
Jul  8 17:50:59 centos02 Keepalived_healthcheckers[3148]: Netlink reflector reports IP 192.168.11.100 removed

从服务器查看日志

# tail -f -n 100 /var/log/messages
Jul  9 01:14:46 centos03 Keepalived[3057]: Stopping Keepalived v1.2.13 (03/19,2015)
Jul  9 01:16:22 centos03 Keepalived[3086]: Starting Keepalived v1.2.13 (03/19,2015)
Jul  9 01:16:22 centos03 Keepalived[3087]: Starting Healthcheck child process, pid=3089
Jul  9 01:16:22 centos03 Keepalived[3087]: Starting VRRP child process, pid=3090
Jul  9 01:16:22 centos03 Keepalived_vrrp[3090]: Netlink reflector reports IP 192.168.11.140 added
Jul  9 01:16:22 centos03 Keepalived_healthcheckers[3089]: Netlink reflector reports IP 192.168.11.140 added
Jul  9 01:16:22 centos03 Keepalived_vrrp[3090]: Netlink reflector reports IP fe80::20c:29ff:fe78:d7d1 added
Jul  9 01:16:22 centos03 Keepalived_vrrp[3090]: Registering Kernel netlink reflector
Jul  9 01:16:22 centos03 Keepalived_vrrp[3090]: Registering Kernel netlink command channel
Jul  9 01:16:22 centos03 Keepalived_vrrp[3090]: Registering gratuitous ARP shared channel
Jul  9 01:16:22 centos03 Keepalived_healthcheckers[3089]: Netlink reflector reports IP fe80::20c:29ff:fe78:d7d1 added
Jul  9 01:16:22 centos03 Keepalived_healthcheckers[3089]: Registering Kernel netlink reflector
Jul  9 01:16:22 centos03 Keepalived_healthcheckers[3089]: Registering Kernel netlink command channel
Jul  9 01:16:23 centos03 Keepalived_vrrp[3090]: Opening file '/etc/keepalived/keepalived.conf'.
Jul  9 01:16:23 centos03 Keepalived_healthcheckers[3089]: Opening file '/etc/keepalived/keepalived.conf'.
Jul  9 01:16:23 centos03 Keepalived_healthcheckers[3089]: Configuration is using : 5150 Bytes
Jul  9 01:16:23 centos03 Keepalived_vrrp[3090]: Configuration is using : 62852 Bytes
Jul  9 01:16:23 centos03 Keepalived_vrrp[3090]: Using LinkWatch kernel netlink reflector...
Jul  9 01:16:23 centos03 Keepalived_healthcheckers[3089]: Using LinkWatch kernel netlink reflector...
Jul  9 01:16:23 centos03 Keepalived_vrrp[3090]: VRRP_Instance(VI_100) Entering BACKUP STATE
Jul  9 01:16:23 centos03 Keepalived_vrrp[3090]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
Jul  9 01:16:23 centos03 Keepalived_vrrp[3090]: VRRP_Script(vs_mysql_100) succeeded
Jul  9 01:25:18 centos03 dhclient[1030]: DHCPREQUEST on eth1 to 192.168.11.254 port 67 (xid=0x4d11bb52)
Jul  9 01:25:18 centos03 dhclient[1030]: DHCPACK from 192.168.11.254 (xid=0x4d11bb52)
Jul  9 01:25:20 centos03 dhclient[1030]: bound to 192.168.11.140 -- renewal in 876 seconds.
Jul  9 01:39:56 centos03 dhclient[1030]: DHCPREQUEST on eth1 to 192.168.11.254 port 67 (xid=0x4d11bb52)
Jul  9 01:39:56 centos03 dhclient[1030]: DHCPACK from 192.168.11.254 (xid=0x4d11bb52)
Jul  9 01:39:58 centos03 dhclient[1030]: bound to 192.168.11.140 -- renewal in 745 seconds.
Jul  9 01:52:05 centos03 Keepalived_vrrp[3090]: VRRP_Instance(VI_100) Transition to MASTER STATE
Jul  9 01:52:10 centos03 Keepalived_vrrp[3090]: VRRP_Instance(VI_100) Entering MASTER STATE
Jul  9 01:52:10 centos03 Keepalived_vrrp[3090]: VRRP_Instance(VI_100) setting protocol VIPs.
Jul  9 01:52:10 centos03 Keepalived_vrrp[3090]: VRRP_Instance(VI_100) Sending gratuitous ARPs on eth1 for 192.168.11.100
Jul  9 01:52:10 centos03 Keepalived_healthcheckers[3089]: Netlink reflector reports IP 192.168.11.100 added
Jul  9 01:52:15 centos03 Keepalived_vrrp[3090]: VRRP_Instance(VI_100) Sending gratuitous ARPs on eth1 for 192.168.11.100

通过VIP 连接mysql,中间可能会有1分钟的断开时间,后面就可以连接上新的主服务器

root@192.168.11.100:3306  02:02:35 [(none)]>show variables like '%server_id%';
+----------------+---------+
| Variable_name  | Value   |
+----------------+---------+
| server_id      | 1773306 |
| server_id_bits | 32      |
+----------------+---------+
2 rows in set (0.00 sec)

 

第二部分

给keepalived.conf添加新脚本

 

# vi /etc/keepalived/shutdown_keepalived.sh

 

posted on 2016-07-08 19:22  鱼儿也疯狂  阅读(197)  评论(0)    收藏  举报