Keepalive

Keepalived是HA cluster的一种实现方案,其以vrrp协议(Virtual Router Redundancy Protocol,即虚拟路由冗余协议)为实现基础,在N台具有相同功能的路由器或服务器中选出一个master或多个backup,这些路由器或服务器会共用一个对外提供服务的VIP。在此HA cluster集群中,master主机会发送组播来跟backup主机进行通信确认双方是否存活。当backup主机在指定的时间内没有收到vrrp组播报文则认为master主机宕机了,此时就会在所有的backup主机中根据vrrp协议来选举出新的master主机来保证服务的高可用性。

1、域名指向,域名只能指向一个固定IP,如果该IP绑定的机器宕机了,那么这个域名便无法访问了;
2、数据库服务指向,应用是通过一个固定的IP连接到数据库,如果该IP宕机,也无法提供服务;

一般主要解决以上两个问题,即keepalived+lvs+nginx和keepalive+mysql等等


keepalived主要有三个模块,分别是ipvs wrapper、checkers和vrrp stack。

  • ipvs wrapper模块为keepalived的核心,负责主进程的启动、维护以及全局配置文件的加载和解析。
  • checkers负责健康检查,包括常见的各种检查方式。
  • vrrp stack模块是来实现VRRP协议的。
  • IPVS wrapper 用来发送设定的规则到内核IPVS代码。
  • Netlink Reflector 用来设定 vrrp 的vip地址等。

Mysql+keepalive高可用自动切换_服务器

 


1、安装

keepalived源码包下载地址:http://www.keepalived.org/download.html

说明文档:https://www.keepalived.org/LVS-NAT-Keepalived-HOWTO.html

安装环境

# yum install -y openssl-devel popt-devel  curl gcc  libnl3-devel net-snmp-devel  libnfnetlink-devel

下载安装包,主机备机都要安装

wget https://www.keepalived.org/software/keepalived-2.0.0.tar.gz 

解压缩、编译、安装,过程中提示缺什么库就安装什么库,然后再重新编译安装。

Mysql+keepalive高可用自动切换_服务器_02

# tar -zxf keepalived-2.0.0.tar.gz 
# cd keepalived-2.0.0
#  ./configure --prefix=/usr/local/keepalived
# make && make install
# echo $?
0
#
# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
# cp ./keepalived/etc/init.d/keepalived /etc/init.d/
# mkdir /etc/keepalived
# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/

Mysql+keepalive高可用自动切换_服务器_02


2、配置

keepalived 只有一个配置文件 keepalived.conf,其中包含了三类配置区域。

  • 全局配置 Global Configuration,包含了 global_defs(全局配置标识)、static_ipaddress(静态地址)、static_routes(静态路由) 区域配置项。
  • VRRP 配置,包含了 vrrp_instance(VRRP 实例)、vrrp_sync_group(VRRP 同步组)、vrrp_script(VRRP 脚本) 、virtual_server 区域配置项。

    • vrrp_instance 用来定义对外提供服务的 VIP 区域及其相关属性。
    • vrrp_rsync_group 用来定义 vrrp_intance 组,使得这个组内成员动作一致。例如两个 vrrp_instance 同属于一个 vrrp_rsync_group,那么其中一个vrrp_instance 发生故障切换时,另一个 vrrp_instance 也会跟着切换(即使这个 instance 没有发生故障)
  • vrrp_script 区域

    • 用来做健康检查,当时检查失败时会将 vrrp_instance 的 priority 减少相应的值。
    • 首先在 vrrp_script 区域定义脚本名字和脚本执行的间隔和脚本执行的优先级变更。然后在实例 vrrp_instance 里面引用,有点类似脚本里面的函数引用一样:先定义,后引用函数名。

 master

Mysql+keepalive高可用自动切换_服务器_02

[root@nginx ~]# cat /etc/keepalived/keepalived.conf
global_defs {
    notification_email {                  #故障发生时给谁发邮件通知。
        root@localhost
        root@192.168.10.18
    }
    notification_email_from keepalived@localhost      #通知邮件的发出地址。
    smtp_server 127.0.0.1         #发现Email的smtp地址
    smtp_connect_timeout 30       #超时时间
    router_id node1               #运行keepalived的机器标识号,主从机必须不同
}

vrrp_instance VI_1 {
    state MASTER               #可以是 MASTER 或 BACKUP,不过当其他节点 keepalived 启动时
                               #会将 Priority(优先级)比较大的节点选举为 MASTER,因此该项其实没有实质用途。
    interface eth1             #本机物理网卡,节点固有 IP(非 VIP)的网卡,用来发 VRRP 包。
    lvs_sync_daemon_inteface eth1    #绑定 lvs syncd 的网卡。
    virtual_router_id 151            #虚拟路由,主从机必需一致。设置 VRID,取值在 0-255 之间,用来区分多个 instance 的 VRRP 组播
                                     #(同一网段中 virtual_router_id 的值不能重复,否则会出错)。
                                     #将决定多播的 MAC 地址
    priority 100          #用来选举 master,要成为 master,这个选项的值最好高于其他机器 50 个点,
                          #该项取值范围是 1-255(在此范围之外会被识别成默认值 100)。
    advert_int 5          #发 VRRP 包的时间间隔,即多久进行一次 master 选举(可以认为是健康查检时间间隔,默认为 1 秒)。
    authentication {       #认证区域,保持master和backup一致
        auth_type PASS
        auth_pass 123456
    }
    virtual_ipaddress {          #VIP(虚拟 IP 地址),随着 state 的变化而增加删除,
                                 #当 state 为 master 的时候就添加,当 state 为 backup 的时候删除,
                                 #主要由优先级来决定的,和 state 设置的值没有多大关系,可以设置多个 IP 地址。
        192.168.100.100 dev eth1   
    }
}

virtual_server 192.168.100.100 3306 {           #LVS配置,VIP
    delay_loop 6                                #服务轮询的时间间隔
    lb_algo wrr                                 #LVS 调度算法
    lb_kind DR                     #LVS 集群算法
    persistence_timeout 60                       #同一IP的链接50秒内被分配到同一台realserver
    protocol TCP                                 #用TCP协议检查realserver状态
    real_server 192.168.10.18 3306 {        #实际服务器的IP和端口
        weight 100
        notify_down /data/sh/mysql.sh
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 3306
        }
    }

}
[root@nginx ~]# 

Mysql+keepalive高可用自动切换_服务器_02

backup

Mysql+keepalive高可用自动切换_服务器_02

[root@mysql ~]# 
[root@mysql ~]# cat /etc/keepalived/keepalived.conf
global_defs {
    notification_email {
        root@localhost
        root@192.168.10.18
    }
    notification_email_from keepalived@localhost
    smtp_server 127.0.0.1
    smtp_connect_timeout 30
    router_id node2
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth1
    lvs_sync_daemon_inteface eth1
    virtual_router_id 151
    priority 90
    advert_int 5
    authentication {
        auth_type PASS
        auth_pass 123456
    }
    virtual_ipaddress {
        192.168.100.100 dev eth1
    }
}

virtual_server 192.168.100.100 3306 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    persistence_timeout 60
    protocol TCP
    real_server 192.168.10.23 3306 {
        weight 100
        notify_down /data/sh/mysql.sh
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 3306
        }
    }

}
[root@mysql ~]# 

Mysql+keepalive高可用自动切换_服务器_02

在两端/data/sh/mysql.sh建立关闭keepalived的脚本

[root@mysql ~]# cat /data/sh/mysql.sh 
pkill keepalived
[root@mysql ~]# 

3、启动

master和backup都启动keepalived服务

Mysql+keepalive高可用自动切换_服务器_02

[root@nginx ~]# service keepalived start
Starting keepalived:                                       [  OK  ]
[root@nginx ~]# 
[root@nginx ~]# ps -ef | grep keep 
root     127942      1  0 12:27 ?        00:00:00 keepalived -D
root     127944 127942  0 12:27 ?        00:00:00 keepalived -D
root     127945 127942  0 12:27 ?        00:00:00 keepalived -D
root     130062 130014  0 14:27 pts/0    00:00:00 grep keep
[root@nginx ~]# 
[root@nginx ~]# 
[root@nginx ~]# netstat -lantup | grep keep
[root@nginx ~]# 

Mysql+keepalive高可用自动切换_服务器_02

Mysql+keepalive高可用自动切换_服务器_02

[root@mysql ~]# /etc/init.d/keepalived restart
Stopping keepalived:                                       [  OK  ]
Starting keepalived:                                       [  OK  ]
[root@mysql ~]# ps -ef | grep keep
root      49218      1  0 12:01 ?        00:00:00 keepalived -D
root      49220  49218  0 12:01 ?        00:00:00 keepalived -D
root      49221  49218  0 12:01 ?        00:00:00 keepalived -D
root      49223  48581  0 12:01 pts/3    00:00:00 grep keep
[root@mysql ~]# 
[root@mysql ~]# netstat -lantup | grep keep
tcp        0      1 192.168.10.23:58138         192.168.33.23:3306          SYN_SENT    49220/keepalived    
[root@mysql ~]# 

Mysql+keepalive高可用自动切换_服务器_02

查看两端的虚拟IP启动情况,系统日志

Master端

Mysql+keepalive高可用自动切换_服务器_02

[root@nginx ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:69:6e:c1 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.18/24 brd 192.168.10.255 scope global eth1
    inet 192.168.100.100/32 scope global eth1
    inet6 fe80::20c:29ff:fe69:6ec1/64 scope link 
       valid_lft forever preferred_lft forever
[root@nginx ~]#

Mysql+keepalive高可用自动切换_服务器_02

虚拟IP:192.168.100.100已经成功启动

Mysql+keepalive高可用自动切换_服务器_02

[root@nginx ~]# tail -fn 10 /var/log/messages6
Sep 20 15:13:22 nginx Keepalived_healthcheckers[419]: TCP connection to [192.168.10.18]:tcp:3306 success.
Sep 20 15:13:32 nginx Keepalived_vrrp[420]: (VI_1) Entering MASTER STATE
Sep 20 15:13:32 nginx Keepalived_vrrp[420]: (VI_1) setting protocol VIPs.
Sep 20 15:13:32 nginx Keepalived_vrrp[420]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:13:32 nginx Keepalived_vrrp[420]: (VI_1) Sending/queueing gratuitous ARPs on eth1 for 192.168.100.100
Sep 20 15:13:32 nginx Keepalived_vrrp[420]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:13:32 nginx Keepalived_vrrp[420]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:13:32 nginx Keepalived_vrrp[420]: Sending gratuitous ARP on eth1 for 192.168.100.100

Mysql+keepalive高可用自动切换_服务器_02

说明已经成功作为MASTER启动,且发送ARP包传输

backup端

Mysql+keepalive高可用自动切换_服务器_02

[root@mysql ~]# tail -fn 10 /var/log/messages
Sep 20 15:25:37 mysql Keepalived_healthcheckers[52339]: WARNING - default user 'keepalived_script' for script execution does not exist - please create.
Sep 20 15:25:37 mysql Keepalived_healthcheckers[52339]: Unknown keyword 'nb_get_retry'
Sep 20 15:25:37 mysql Keepalived_healthcheckers[52339]: Please add a #! shebang to script /data/sh/mysql.sh
Sep 20 15:25:37 mysql Keepalived_vrrp[52340]: (VI_1) removing protocol VIPs.
Sep 20 15:25:37 mysql Keepalived_vrrp[52340]: (VI_1) Entering BACKUP STATE (init)
Sep 20 15:25:37 mysql Keepalived_healthcheckers[52339]: SECURITY VIOLATION - check scripts are being executed but script_security not enabled.
Sep 20 15:25:37 mysql Keepalived_healthcheckers[52339]: Gained quorum 1+0=1 <= 100 for VS [192.168.100.100]:tcp:3306
Sep 20 15:25:37 mysql Keepalived_healthcheckers[52339]: Activating healthchecker for service [192.168.10.23]:tcp:3306 for VS [192.168.100.100]:tcp:3306
Sep 20 15:25:37 mysql Keepalived_vrrp[52340]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(8,9)]
Sep 20 15:25:43 mysql Keepalived_healthcheckers[52339]: TCP connection to [192.168.10.23]:tcp:3306 success.

Mysql+keepalive高可用自动切换_服务器_02

 (VI_1) Entering BACKUP STATE (init)已作为backup机启用

Mysql+keepalive高可用自动切换_服务器_02

[root@mysql ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:ad:ad:54 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.23/24 brd 192.168.10.255 scope global eth1
    inet6 fe80::20c:29ff:fead:ad54/64 scope link 
       valid_lft forever preferred_lft forever
[root@mysql ~]#

Mysql+keepalive高可用自动切换_服务器_02

backup的IP情况


 

4、测试

当Master的MySQL服务意外挂掉后,会自动启用backup的Mysql继续为系统提供支持。

Mysql+keepalive高可用自动切换_服务器_02

[root@nginx ~]# service mysqld stop
Stopping mysqld:                                           [  OK  ]
[root@nginx ~]# 
[root@nginx ~]# 
[root@nginx ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:69:6e:c1 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.18/24 brd 192.168.10.255 scope global eth1
    inet6 fe80::20c:29ff:fe69:6ec1/64 scope link 
       valid_lft forever preferred_lft forever
[root@nginx ~]# 
[root@nginx ~]# 
[root@nginx ~]# 
[root@nginx ~]# tail -fn 10 /var/log/messages
Sep 20 15:36:44 nginx Keepalived_healthcheckers[419]: Error processing RCPT cmd on SMTP server [127.0.0.1]:25. SMTP status code = 501
Sep 20 15:36:44 nginx Keepalived_healthcheckers[419]: Can not read data from remote SMTP server [127.0.0.1]:25.
Sep 20 15:36:44 nginx Keepalived[417]: Stopping
Sep 20 15:36:44 nginx kernel: IPVS: __ip_vs_del_service: enter
Sep 20 15:36:44 nginx Keepalived_vrrp[420]: (VI_1) sent 0 priority
Sep 20 15:36:44 nginx Keepalived_vrrp[420]: (VI_1) removing protocol VIPs.
Sep 20 15:36:44 nginx Keepalived_healthcheckers[419]: Shutting down service [192.168.10.18]:tcp:3306 from VS [192.168.100.100]:tcp:3306
Sep 20 15:36:44 nginx Keepalived_healthcheckers[419]: Stopped
Sep 20 15:36:45 nginx Keepalived_vrrp[420]: Stopped
Sep 20 15:36:45 nginx Keepalived[417]: Stopped Keepalived v2.0.0 (05/27,2018)
^C
[root@nginx ~]# ps -ef  | grep keep
root       1127 130014  0 15:40 pts/0    00:00:00 grep keep
[root@nginx ~]# 

Mysql+keepalive高可用自动切换_服务器_02

Master 测试关闭mysql服务,虚拟IP停止发送ARP包,keepalived服务终止

Mysql+keepalive高可用自动切换_服务器_02

[root@mysql ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:ad:ad:54 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.23/24 brd 192.168.10.255 scope global eth1
    inet 192.168.100.100/32 scope global eth1
    inet6 fe80::20c:29ff:fead:ad54/64 scope link 
       valid_lft forever preferred_lft forever
[root@mysql ~]# 
[root@mysql ~]# tail -fn 20 /var/log/messages
Sep 20 15:25:37 mysql Keepalived_healthcheckers[52339]: SECURITY VIOLATION - check scripts are being executed but script_security not enabled.
Sep 20 15:25:37 mysql Keepalived_healthcheckers[52339]: Gained quorum 1+0=1 <= 100 for VS [192.168.100.100]:tcp:3306
Sep 20 15:25:37 mysql Keepalived_healthcheckers[52339]: Activating healthchecker for service [192.168.10.23]:tcp:3306 for VS [192.168.100.100]:tcp:3306
Sep 20 15:25:37 mysql Keepalived_vrrp[52340]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(8,9)]
Sep 20 15:25:43 mysql Keepalived_healthcheckers[52339]: TCP connection to [192.168.10.23]:tcp:3306 success.
Sep 20 15:36:44 mysql Keepalived_vrrp[52340]: (VI_1) Backup received priority 0 advertisement
Sep 20 15:36:45 mysql Keepalived_vrrp[52340]: (VI_1) Entering MASTER STATE
Sep 20 15:36:45 mysql Keepalived_vrrp[52340]: (VI_1) setting protocol VIPs.
Sep 20 15:36:45 mysql Keepalived_vrrp[52340]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:36:45 mysql Keepalived_vrrp[52340]: (VI_1) Sending/queueing gratuitous ARPs on eth1 for 192.168.100.100
Sep 20 15:36:45 mysql Keepalived_vrrp[52340]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:36:45 mysql Keepalived_vrrp[52340]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:36:45 mysql Keepalived_vrrp[52340]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:36:45 mysql Keepalived_vrrp[52340]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:36:50 mysql Keepalived_vrrp[52340]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:36:50 mysql Keepalived_vrrp[52340]: (VI_1) Sending/queueing gratuitous ARPs on eth1 for 192.168.100.100
Sep 20 15:36:50 mysql Keepalived_vrrp[52340]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:36:50 mysql Keepalived_vrrp[52340]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:36:50 mysql Keepalived_vrrp[52340]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:36:50 mysql Keepalived_vrrp[52340]: Sending gratuitous ARP on eth1 for 192.168.100.100
ps^C
[root@mysql ~]# 
[root@mysql ~]# ps -ef | grep keepalived
root      52337      1  0 15:25 ?        00:00:00 keepalived -D
root      52339  52337  0 15:25 ?        00:00:00 keepalived -D
root      52340  52337  0 15:25 ?        00:00:00 keepalived -D
root      52760  51101  0 15:42 pts/0    00:00:00 grep keepalived
[root@mysql ~]# 

Mysql+keepalive高可用自动切换_服务器_02

(VI_1) Entering MASTER STATE,backup机成为Master,继续为系统提供mysql服务,测试成功。
重启Master主机的mysql服务后,Master主机重新成为master,备机重新成为备机

Mysql+keepalive高可用自动切换_服务器_02

[root@nginx ~]# 
[root@nginx ~]# service keepalived restasrt
Usage: /etc/init.d/keepalived {start|stop|reload|restart|condrestart|status}
[root@nginx ~]# service keepalived restart
Stopping keepalived:                                       [FAILED]
Starting keepalived:                                       [  OK  ]
[root@nginx ~]# 
[root@nginx ~]# 
[root@nginx ~]# 
[root@nginx ~]# tail -fn 10 /var/log/messages
Sep 20 15:44:35 nginx Keepalived_healthcheckers[1409]: Gained quorum 1+0=1 <= 100 for VS [192.168.100.100]:tcp:3306
Sep 20 15:44:35 nginx Keepalived_vrrp[1410]: Unknown keyword 'lvs_sync_daemon_inteface'
Sep 20 15:44:35 nginx Keepalived_vrrp[1410]: Assigned address 192.168.10.18 for interface eth1
Sep 20 15:44:35 nginx Keepalived_healthcheckers[1409]: Activating healthchecker for service [192.168.10.18]:tcp:3306 for VS [192.168.100.100]:tcp:3306
Sep 20 15:44:35 nginx Keepalived_vrrp[1410]: Assigned address fe80::20c:29ff:fe69:6ec1 for interface eth1
Sep 20 15:44:35 nginx Keepalived_vrrp[1410]: Registering gratuitous ARP shared channel
Sep 20 15:44:35 nginx Keepalived_vrrp[1410]: (VI_1) removing protocol VIPs.
Sep 20 15:44:35 nginx Keepalived_vrrp[1410]: (VI_1) Entering BACKUP STATE (init)
Sep 20 15:44:35 nginx Keepalived_vrrp[1410]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(8,9)]
Sep 20 15:44:36 nginx Keepalived_vrrp[1410]: (VI_1) received lower priority (90) advert from 192.168.10.23 - discarding
Sep 20 15:44:41 nginx Keepalived_vrrp[1410]: (VI_1) received lower priority (90) advert from 192.168.10.23 - discarding
Sep 20 15:44:41 nginx Keepalived_healthcheckers[1409]: TCP connection to [192.168.10.18]:tcp:3306 success.
Sep 20 15:44:46 nginx Keepalived_vrrp[1410]: (VI_1) received lower priority (90) advert from 192.168.10.23 - discarding
Sep 20 15:44:50 nginx Keepalived_vrrp[1410]: (VI_1) Entering MASTER STATE
Sep 20 15:44:50 nginx Keepalived_vrrp[1410]: (VI_1) setting protocol VIPs.
Sep 20 15:44:50 nginx Keepalived_vrrp[1410]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:44:50 nginx Keepalived_vrrp[1410]: (VI_1) Sending/queueing gratuitous ARPs on eth1 for 192.168.100.100
Sep 20 15:44:50 nginx Keepalived_vrrp[1410]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:44:50 nginx Keepalived_vrrp[1410]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:44:50 nginx Keepalived_vrrp[1410]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:44:50 nginx Keepalived_vrrp[1410]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:44:55 nginx Keepalived_vrrp[1410]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:44:55 nginx Keepalived_vrrp[1410]: (VI_1) Sending/queueing gratuitous ARPs on eth1 for 192.168.100.100
Sep 20 15:44:55 nginx Keepalived_vrrp[1410]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:44:55 nginx Keepalived_vrrp[1410]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:44:55 nginx Keepalived_vrrp[1410]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:44:55 nginx Keepalived_vrrp[1410]: Sending gratuitous ARP on eth1 for 192.168.100.100
^C
[root@nginx ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:69:6e:c1 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.18/24 brd 192.168.10.255 scope global eth1
    inet 192.168.100.100/32 scope global eth1
    inet6 fe80::20c:29ff:fe69:6ec1/64 scope link 
       valid_lft forever preferred_lft forever
[root@nginx ~]# 

Mysql+keepalive高可用自动切换_服务器_02

Mysql+keepalive高可用自动切换_服务器_02

[root@mysql ~]# 
[root@mysql ~]# tail -fn 20 /var/log/messages
Sep 20 15:25:37 mysql Keepalived_vrrp[52340]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(8,9)]
Sep 20 15:25:43 mysql Keepalived_healthcheckers[52339]: TCP connection to [192.168.10.23]:tcp:3306 success.
Sep 20 15:36:44 mysql Keepalived_vrrp[52340]: (VI_1) Backup received priority 0 advertisement
Sep 20 15:36:45 mysql Keepalived_vrrp[52340]: (VI_1) Entering MASTER STATE
Sep 20 15:36:45 mysql Keepalived_vrrp[52340]: (VI_1) setting protocol VIPs.
Sep 20 15:36:45 mysql Keepalived_vrrp[52340]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:36:45 mysql Keepalived_vrrp[52340]: (VI_1) Sending/queueing gratuitous ARPs on eth1 for 192.168.100.100
Sep 20 15:36:45 mysql Keepalived_vrrp[52340]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:36:45 mysql Keepalived_vrrp[52340]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:36:45 mysql Keepalived_vrrp[52340]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:36:45 mysql Keepalived_vrrp[52340]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:36:50 mysql Keepalived_vrrp[52340]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:36:50 mysql Keepalived_vrrp[52340]: (VI_1) Sending/queueing gratuitous ARPs on eth1 for 192.168.100.100
Sep 20 15:36:50 mysql Keepalived_vrrp[52340]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:36:50 mysql Keepalived_vrrp[52340]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:36:50 mysql Keepalived_vrrp[52340]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:36:50 mysql Keepalived_vrrp[52340]: Sending gratuitous ARP on eth1 for 192.168.100.100
Sep 20 15:44:50 mysql Keepalived_vrrp[52340]: (VI_1) Master received advert from 192.168.10.18 with higher priority 100, ours 90
Sep 20 15:44:50 mysql Keepalived_vrrp[52340]: (VI_1) Entering BACKUP STATE
Sep 20 15:44:50 mysql Keepalived_vrrp[52340]: (VI_1) removing protocol VIPs.
^C
[root@mysql ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:ad:ad:54 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.23/24 brd 192.168.10.255 scope global eth1
    inet6 fe80::20c:29ff:fead:ad54/64 scope link 
       valid_lft forever preferred_lft forever
[root@mysql ~]# 

Mysql+keepalive高可用自动切换_服务器_02