【需求】

根据需求需要搭建mysql主从架构数据库及加keepalived进行自动切换VIP

【环境介绍】
  系统环境:CentOS release 6.4 (Final) + Server version: 5.7.25-log MySQL Community Server (GPL) + Keepalived v1.2.7

系统

IP

主机名

备注

版本

xx系统

192.168.8.100

mysqldb1

主库

Server version: 5.7.25-log MySQL Community Server (GPL)

192.168.8.101

mysqldb2

备库

192.168.8.105

mysqldb1

主库(VIP)

【搭建步骤:mysql软件部署】

可参考之前mysql主从搭建步骤

【搭建步骤:keepalived软件部署】

安装步骤:

使用系统自带的keepalived版本或者下载其他版本rpm安装。yum -y install keepalived*

节点一(主库)

[root@mysqldb1 keepalived]# rpm -qa |grep keepalived
keepalived-1.2.7-3.el6.x86_64
[root@mysqldb1 keepalived]#

节点二(从库)

[root@mysqldb2 ~]# rpm -qa |grep keepalived
keepalived-1.2.7-3.el6.x86_64
[root@mysqldb2 ~]#

keepalived配置文件:

节点一配置:
[root@mysqldb1 keepalived]# cat keepalived.conf
! Configuration File for keepalived
global_defs {
   #notification_email {  
   #chenxxx@gmail.com
   #}
   #notification_email_from xxx@163.com
   #smtp_server smtp.163.com     
   smtp_connect_timeout 30
   router_id LVS_DEVEL   >>>可以自定义名字,跟从库一致
}
vrrp_instance VI_1 {      
    state MASTER   >>>表明为master节点        
    interface eth1     >>>指定主机IP挂载的接口与从库一致
    virtual_router_id 100    >>>指定ID标示,与从库一致
    garp_master_delay 1
    priority 100         >>>指定等级这里为100从库为99  
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.8.105/24 dev eth1   >>>VIP
    }
}
[root@mysqldb1 keepalived]#

监控mysql数据库状态,输出check_mysql.log日志

[root@mysqldb1 keepalived]# cat check_mysql.sh
#!/bin/bash
mysql=/var/lib/mysql/bin/mysql
mysql_host=localhost
mysql_user=root
mysql_password=mysql
check_time=3
mysql_ok=1
function check_mysql_health(){
$mysql -h $mysql_host -u$mysql_user -p$mysql_password -e 'show status;' >/dev/null 2>&1
if [ $? = 0 ] ;then
        mysql_ok=1
        echo 'mysql_ok'
else
        mysql_ok=0
        echo 'mysql_failed'
fi
        return $mysql_ok
}
while [ $check_time -ne 0 ]
do
        let "check_time -= 1"
        check_mysql_health
if [ $mysql_ok = 1 ] ;then
        check_time=0
        exit 0
fi
if [ $mysql_ok -eq 0 ] && [ $check_time -eq 0 ]
then
 pkill keepalived
fi
 sleep 1
done
[root@mysqldb1 keepalived]#

定时任务

#check_mysql
*/1 * * * * bash /etc/keepalived/check_mysql.sh >> /etc/keepalived/check_mysql.log

节点二配置:

[root@mysqldb2 keepalived]# cat  keepalived.conf
! Configuration File for keepalived
global_defs {
   #notification_email {  
   #chenxxx@gmail.com
   #}
   #notification_email_from myxxx@163.com
   #smtp_server smtp.163.com     
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {      
    state MASTER          
    interface eth1
    virtual_router_id 100   
    garp_master_delay 1
    priority 99           
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.8.105/24 dev eth1  
    }
}
[root@mysqldb2 keepalived]# cat check_mysql.sh
#!/bin/bash
mysql=/var/lib/mysql/bin/mysql
mysql_host=localhost
mysql_user=root
mysql_password=mysql
check_time=3
mysql_ok=1
function check_mysql_health(){
$mysql -h $mysql_host -u$mysql_user -p$mysql_password -e 'show status;' >/dev/null 2>&1
if [ $? = 0 ] ;then
        mysql_ok=1
        echo 'mysql_ok'
else
        mysql_ok=0
        echo 'mysql_failed'
fi
        return $mysql_ok
}
while [ $check_time -ne 0 ]
do
        let "check_time -= 1"
        check_mysql_health
if [ $mysql_ok = 1 ] ;then
        check_time=0
        exit 0
fi
if [ $mysql_ok -eq 0 ] && [ $check_time -eq 0 ]
then
 pkill keepalived
fi
 sleep 1
done
[root@mysqldb2 keepalived]#

启动keepalived服务:

主库启动keepalived,VIP已经挂载,查看日志为MASTER STATE模式

[root@mysqldb1 keepalived]# service keepalived start
Starting keepalived: [  OK  ]
[root@mysqldb1 keepalived]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 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 08:00:27:62:61:3a brd ff:ff:ff:ff:ff:ff
    inet 192.168.8.100/24 brd 192.168.8.255 scope global eth1
    inet 192.168.8.105/24 scope global secondary eth1
    inet6 fe80::a00:27ff:fe62:613a/64 scope link
       valid_lft forever preferred_lft forever
[root@mysqldb1 keepalived]#

查看keepalived日志:

tail -f messages

Mar  6 02:33:09 mysqldb1 Keepalived[12767]: Stopping Keepalived v1.2.7 (02/21,2013)
Mar  6 02:33:09 mysqldb1 Keepalived_vrrp[12770]: VRRP_Instance(VI_1) sending 0 priority
Mar  6 02:33:12 mysqldb1 Keepalived[12814]: Starting Keepalived v1.2.7 (02/21,2013)
Mar  6 02:33:12 mysqldb1 Keepalived[12815]: Starting Healthcheck child process, pid=12817
Mar  6 02:33:12 mysqldb1 Keepalived[12815]: Starting VRRP child process, pid=12818
Mar  6 02:33:12 mysqldb1 Keepalived_vrrp[12818]: Interface queue is empty
Mar  6 02:33:12 mysqldb1 Keepalived_vrrp[12818]: Netlink reflector reports IP 192.168.8.100 added
Mar  6 02:33:12 mysqldb1 Keepalived_vrrp[12818]: Netlink reflector reports IP fe80::a00:27ff:fe62:613a added
Mar  6 02:33:12 mysqldb1 Keepalived_vrrp[12818]: Registering Kernel netlink reflector
Mar  6 02:33:12 mysqldb1 Keepalived_vrrp[12818]: Registering Kernel netlink command channel
Mar  6 02:33:12 mysqldb1 Keepalived_healthcheckers[12817]: Interface queue is empty
Mar  6 02:33:12 mysqldb1 Keepalived_healthcheckers[12817]: Netlink reflector reports IP 192.168.8.100 added
Mar  6 02:33:12 mysqldb1 Keepalived_healthcheckers[12817]: Netlink reflector reports IP fe80::a00:27ff:fe62:613a added
Mar  6 02:33:12 mysqldb1 Keepalived_healthcheckers[12817]: Registering Kernel netlink reflector
Mar  6 02:33:12 mysqldb1 Keepalived_vrrp[12818]: Registering gratuitous ARP shared channel
Mar  6 02:33:12 mysqldb1 Keepalived_healthcheckers[12817]: Registering Kernel netlink command channel
Mar  6 02:33:12 mysqldb1 Keepalived_vrrp[12818]: Opening file '/etc/keepalived/keepalived.conf'.
Mar  6 02:33:12 mysqldb1 Keepalived_healthcheckers[12817]: Opening file '/etc/keepalived/keepalived.conf'.
Mar  6 02:33:12 mysqldb1 Keepalived_healthcheckers[12817]: Configuration is using : 5627 Bytes
Mar  6 02:33:12 mysqldb1 Keepalived_vrrp[12818]: Configuration is using : 61320 Bytes
Mar  6 02:33:12 mysqldb1 Keepalived_vrrp[12818]: Using LinkWatch kernel netlink reflector...
Mar  6 02:33:12 mysqldb1 Keepalived_vrrp[12818]: VRRP sockpool: [ifindex(2), proto(112), fd(10,11)]
Mar  6 02:33:12 mysqldb1 Keepalived_healthcheckers[12817]: Using LinkWatch kernel netlink reflector...
Mar  6 02:33:13 mysqldb1 Keepalived_vrrp[12818]: VRRP_Instance(VI_1) Transition to MASTER STATE
Mar  6 02:33:14 mysqldb1 Keepalived_vrrp[12818]: VRRP_Instance(VI_1) Entering MASTER STATE
Mar  6 02:33:14 mysqldb1 Keepalived_vrrp[12818]: VRRP_Instance(VI_1) setting protocol VIPs.
Mar  6 02:33:14 mysqldb1 Keepalived_vrrp[12818]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.8.105
Mar  6 02:33:14 mysqldb1 Keepalived_healthcheckers[12817]: Netlink reflector reports IP 192.168.8.105 added
Mar  6 02:33:15 mysqldb1 Keepalived_vrrp[12818]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.8.105
Mar  6 02:34:04 mysqldb1 Keepalived_vrrp[12818]: VRRP_Instance(VI_1) Received lower prio advert, forcing new election
Mar  6 02:34:04 mysqldb1 Keepalived_vrrp[12818]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.8.105

查看mysql数据库监控日志

[root@mysqldb1 keepalived]# tail -f check_mysql.log
mysql_ok
mysql_ok
mysql_ok
mysql_ok
mysql_ok
mysql_ok
mysql_ok
mysql_ok
mysql_ok
mysql_ok

从库启动keepalived,查看日志为BACKUP STATE模式

[root@mysqldb2 keepalived]# service keepalived start
Starting keepalived: [  OK  ]
[root@mysqldb2 keepalived]#

tail -f messages

Mar  6 02:34:42 mysqldb2 Keepalived[12288]: Starting Keepalived v1.2.7 (02/21,2013)
Mar  6 02:34:42 mysqldb2 Keepalived[12289]: Starting Healthcheck child process, pid=12291
Mar  6 02:34:42 mysqldb2 Keepalived[12289]: Starting VRRP child process, pid=12292
Mar  6 02:34:42 mysqldb2 Keepalived_vrrp[12292]: Interface queue is empty
Mar  6 02:34:42 mysqldb2 Keepalived_healthcheckers[12291]: Interface queue is empty
Mar  6 02:34:42 mysqldb2 Keepalived_healthcheckers[12291]: Netlink reflector reports IP 192.168.8.101 added
Mar  6 02:34:42 mysqldb2 Keepalived_healthcheckers[12291]: Netlink reflector reports IP fe80::a00:27ff:fe53:eeca added
Mar  6 02:34:42 mysqldb2 Keepalived_healthcheckers[12291]: Registering Kernel netlink reflector
Mar  6 02:34:42 mysqldb2 Keepalived_healthcheckers[12291]: Registering Kernel netlink command channel
Mar  6 02:34:42 mysqldb2 Keepalived_vrrp[12292]: Netlink reflector reports IP 192.168.8.101 added
Mar  6 02:34:42 mysqldb2 Keepalived_vrrp[12292]: Netlink reflector reports IP fe80::a00:27ff:fe53:eeca added
Mar  6 02:34:42 mysqldb2 Keepalived_vrrp[12292]: Registering Kernel netlink reflector
Mar  6 02:34:42 mysqldb2 Keepalived_vrrp[12292]: Registering Kernel netlink command channel
Mar  6 02:34:42 mysqldb2 Keepalived_vrrp[12292]: Registering gratuitous ARP shared channel
Mar  6 02:34:42 mysqldb2 Keepalived_healthcheckers[12291]: Opening file '/etc/keepalived/keepalived.conf'.
Mar  6 02:34:42 mysqldb2 Keepalived_vrrp[12292]: Opening file '/etc/keepalived/keepalived.conf'.
Mar  6 02:34:42 mysqldb2 Keepalived_healthcheckers[12291]: Configuration is using : 5610 Bytes
Mar  6 02:34:42 mysqldb2 Keepalived_vrrp[12292]: Configuration is using : 61303 Bytes
Mar  6 02:34:42 mysqldb2 Keepalived_vrrp[12292]: Using LinkWatch kernel netlink reflector...
Mar  6 02:34:42 mysqldb2 Keepalived_vrrp[12292]: VRRP sockpool: [ifindex(2), proto(112), fd(10,11)]
Mar  6 02:34:42 mysqldb2 Keepalived_healthcheckers[12291]: Using LinkWatch kernel netlink reflector...
Mar  6 02:34:43 mysqldb2 Keepalived_vrrp[12292]: VRRP_Instance(VI_1) Transition to MASTER STATE
Mar  6 02:34:43 mysqldb2 Keepalived_vrrp[12292]: VRRP_Instance(VI_1) Received higher prio advert
Mar  6 02:34:43 mysqldb2 Keepalived_vrrp[12292]: VRRP_Instance(VI_1) Entering BACKUP STATE

查看数据库监控日志

[root@mysqldb2 keepalived]# tail -f check_mysql.log
mysql_ok
mysql_ok
mysql_ok
mysql_ok
mysql_ok
mysql_ok
mysql_ok
mysql_ok
mysql_ok
mysql_ok

【进行远程连接】

连接为VIP,端口为3306,schema为test

查看连接是为节点一主机

至此keepalived搭建完成

【进行keepalived模拟自动切换】

停止节点一mysql主数据库

[root@mysqldb1 keepalived]# mysqladmin --defaults-file=/etc/my.cnf -P3306 shutdown -uroot -pmysql
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
[1]+  Done                    mysqld --defaults-file=/etc/my.cnf --user=mysql 
[root@mysqldb1 keepalived]#

查看节点一mysql进程监控日志

[root@mysqldb1 keepalived]# tail -f check_mysql.log
mysql_ok
mysql_ok
mysql_ok
mysql_ok
mysql_failed
mysql_failed
mysql_failed

查看节点一keepalived日志信息

Mar  6 02:33:12 mysqldb1 Keepalived_healthcheckers[12817]: Using LinkWatch kernel netlink reflector...
Mar  6 02:33:13 mysqldb1 Keepalived_vrrp[12818]: VRRP_Instance(VI_1) Transition to MASTER STATE
Mar  6 02:33:14 mysqldb1 Keepalived_vrrp[12818]: VRRP_Instance(VI_1) Entering MASTER STATE
Mar  6 02:33:14 mysqldb1 Keepalived_vrrp[12818]: VRRP_Instance(VI_1) setting protocol VIPs.
Mar  6 02:33:14 mysqldb1 Keepalived_vrrp[12818]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.8.105
Mar  6 02:33:14 mysqldb1 Keepalived_healthcheckers[12817]: Netlink reflector reports IP 192.168.8.105 added
Mar  6 02:33:15 mysqldb1 Keepalived_vrrp[12818]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.8.105
Mar  6 02:34:04 mysqldb1 Keepalived_vrrp[12818]: VRRP_Instance(VI_1) Received lower prio advert, forcing new election
Mar  6 02:34:04 mysqldb1 Keepalived_vrrp[12818]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.8.105
Mar  6 02:34:42 mysqldb1 Keepalived_vrrp[12818]: VRRP_Instance(VI_1) Received lower prio advert, forcing new election
Mar  6 02:34:42 mysqldb1 Keepalived_vrrp[12818]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.8.105

Mar  6 02:54:03 mysqldb1 Keepalived[12815]: Stopping Keepalived v1.2.7 (02/21,2013) 》》》keepalived进程已经停止

查看节点一keepalived进程状态

[root@mysqldb1 keepalived]# service keepalived status
keepalived dead but subsys locked
[root@mysqldb1 keepalived]#

查看节点二备库keepalived日志信息,VIP已经漂移过来

Mar  6 02:34:42 mysqldb2 Keepalived_healthcheckers[12291]: Using LinkWatch kernel netlink reflector...
Mar  6 02:34:43 mysqldb2 Keepalived_vrrp[12292]: VRRP_Instance(VI_1) Transition to MASTER STATE
Mar  6 02:34:43 mysqldb2 Keepalived_vrrp[12292]: VRRP_Instance(VI_1) Received higher prio advert
Mar  6 02:34:43 mysqldb2 Keepalived_vrrp[12292]: VRRP_Instance(VI_1) Entering BACKUP STATE
Mar  6 02:54:06 mysqldb2 Keepalived_vrrp[12292]: VRRP_Instance(VI_1) Transition to MASTER STATE
Mar  6 02:54:07 mysqldb2 Keepalived_vrrp[12292]: VRRP_Instance(VI_1) Entering MASTER STATE
Mar  6 02:54:07 mysqldb2 Keepalived_vrrp[12292]: VRRP_Instance(VI_1) setting protocol VIPs.
Mar  6 02:54:07 mysqldb2 Keepalived_vrrp[12292]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.8.105
Mar  6 02:54:07 mysqldb2 Keepalived_healthcheckers[12291]: Netlink reflector reports IP 192.168.8.105 added
Mar  6 02:54:08 mysqldb2 Keepalived_vrrp[12292]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.8.105

测试远程连接VIP则连接到节点二数据库

【回切mysql主节点keepalived服务】

启动节点一主数据库

[root@mysqldb1 keepalived]# mysqld --defaults-file=/etc/my.cnf --user=mysql &
[1] 13039
[root@mysqldb1 keepalived]# ps -ef |grep mysql
root     12836  4599  0 02:35 pts/2    00:00:00 tail -f check_mysql.log
mysql    13039  1999  8 02:55 pts/0    00:00:00 mysqld --defaults-file=/etc/my.cnf --user=mysql
root     13073  1999  0 02:55 pts/0    00:00:00 grep mysql
[root@mysqldb1 keepalived]#

查看节点一keepalived的mysql数据库监控日志,已经为正常

[root@mysqldb1 keepalived]# tail -f check_mysql.log
mysql_ok
mysql_ok
mysql_ok
mysql_failed
mysql_failed
mysql_failed
mysql_failed
mysql_failed
mysql_failed
mysql_ok
mysql_ok
mysql_ok
mysql_ok

手动启动节点一keepalived进程,VIP已经回切

[root@mysqldb1 keepalived]# service keepalived start
Starting keepalived: [  OK  ]
[root@mysqldb1 keepalived]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 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 08:00:27:62:61:3a brd ff:ff:ff:ff:ff:ff
    inet 192.168.8.100/24 brd 192.168.8.255 scope global eth1
    inet 192.168.8.105/24 scope global secondary eth1
    inet6 fe80::a00:27ff:fe62:613a/64 scope link
       valid_lft forever preferred_lft forever
[root@mysqldb1 keepalived]# service keepalived status
keepalived (pid  13139) is running...
[root@mysqldb1 keepalived]#

查看节点一的keepalived日志,VIIP已经回切

Mar  6 02:54:03 mysqldb1 Keepalived[12815]: Stopping Keepalived v1.2.7 (02/21,2013)
Mar  6 02:57:56 mysqldb1 Keepalived[13138]: Starting Keepalived v1.2.7 (02/21,2013)
Mar  6 02:57:56 mysqldb1 Keepalived[13139]: Starting Healthcheck child process, pid=13141
Mar  6 02:57:56 mysqldb1 Keepalived[13139]: Starting VRRP child process, pid=13142
Mar  6 02:57:56 mysqldb1 Keepalived_vrrp[13142]: Interface queue is empty
Mar  6 02:57:56 mysqldb1 Keepalived_vrrp[13142]: Netlink reflector reports IP 192.168.8.100 added
Mar  6 02:57:56 mysqldb1 Keepalived_vrrp[13142]: Netlink reflector reports IP 192.168.8.105 added
Mar  6 02:57:56 mysqldb1 Keepalived_vrrp[13142]: Netlink reflector reports IP fe80::a00:27ff:fe62:613a added
Mar  6 02:57:56 mysqldb1 Keepalived_vrrp[13142]: Registering Kernel netlink reflector
Mar  6 02:57:56 mysqldb1 Keepalived_vrrp[13142]: Registering Kernel netlink command channel
Mar  6 02:57:56 mysqldb1 Keepalived_vrrp[13142]: Registering gratuitous ARP shared channel
Mar  6 02:57:56 mysqldb1 Keepalived_healthcheckers[13141]: Interface queue is empty
Mar  6 02:57:56 mysqldb1 Keepalived_healthcheckers[13141]: Netlink reflector reports IP 192.168.8.100 added
Mar  6 02:57:56 mysqldb1 Keepalived_vrrp[13142]: Opening file '/etc/keepalived/keepalived.conf'.
Mar  6 02:57:56 mysqldb1 Keepalived_healthcheckers[13141]: Netlink reflector reports IP 192.168.8.105 added
Mar  6 02:57:56 mysqldb1 Keepalived_healthcheckers[13141]: Netlink reflector reports IP fe80::a00:27ff:fe62:613a added
Mar  6 02:57:56 mysqldb1 Keepalived_healthcheckers[13141]: Registering Kernel netlink reflector
Mar  6 02:57:56 mysqldb1 Keepalived_healthcheckers[13141]: Registering Kernel netlink command channel
Mar  6 02:57:56 mysqldb1 Keepalived_vrrp[13142]: Configuration is using : 61320 Bytes
Mar  6 02:57:56 mysqldb1 Keepalived_vrrp[13142]: Using LinkWatch kernel netlink reflector...
Mar  6 02:57:56 mysqldb1 Keepalived_healthcheckers[13141]: Opening file '/etc/keepalived/keepalived.conf'.
Mar  6 02:57:56 mysqldb1 Keepalived_healthcheckers[13141]: Configuration is using : 5627 Bytes
Mar  6 02:57:56 mysqldb1 Keepalived_vrrp[13142]: VRRP sockpool: [ifindex(2), proto(112), fd(10,11)]
Mar  6 02:57:56 mysqldb1 Keepalived_healthcheckers[13141]: Using LinkWatch kernel netlink reflector...
Mar  6 02:57:56 mysqldb1 Keepalived_vrrp[13142]: VRRP_Instance(VI_1) Transition to MASTER STATE
Mar  6 02:57:57 mysqldb1 Keepalived_vrrp[13142]: VRRP_Instance(VI_1) Entering MASTER STATE
Mar  6 02:57:57 mysqldb1 Keepalived_vrrp[13142]: VRRP_Instance(VI_1) setting protocol VIPs.
Mar  6 02:57:57 mysqldb1 Keepalived_vrrp[13142]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.8.105
Mar  6 02:57:58 mysqldb1 Keepalived_vrrp[13142]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.8.105

查看节点二keepalived日志,keepalived为BACKUP STATE,VIP已经移除

Mar  6 02:54:07 mysqldb2 Keepalived_vrrp[12292]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.8.105
Mar  6 02:54:07 mysqldb2 Keepalived_healthcheckers[12291]: Netlink reflector reports IP 192.168.8.105 added
Mar  6 02:54:08 mysqldb2 Keepalived_vrrp[12292]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 192.168.8.105
Mar  6 02:57:57 mysqldb2 Keepalived_vrrp[12292]: VRRP_Instance(VI_1) Received higher prio advert
Mar  6 02:57:57 mysqldb2 Keepalived_vrrp[12292]: VRRP_Instance(VI_1) Entering BACKUP STATE
Mar  6 02:57:57 mysqldb2 Keepalived_vrrp[12292]: VRRP_Instance(VI_1) removing protocol VIPs.
Mar  6 02:57:57 mysqldb2 Keepalived_healthcheckers[12291]: Netlink reflector reports IP 192.168.8.105 removed

测试远程VIP连接数据库为节点一

一次mysql主从加keepalived配置搭建及切换演示的更多相关文章

  1. mysql主从双机keepalived配置

    1.关闭selinux SELINUX=disabled 2.yum安装keepalived yum install -y keepalived 3.修改配置文件 主库配置文件: ! Configur ...

  2. MYSQL主从库同步配置过程

    MYSQL主从库同步配置过程 为了实现网站数据库的异地备份,采用了MySQL数据库主从同步配置,需要两台服务器分别作为主从库,当主库发生增删改等操作,会实时反映到从库,我的个人服务器配置如下: 主库为 ...

  3. mysql 8.0.18 mgr 搭建及其切换

    mysql 8.0.18 mgr 搭建及其切换 一.系统安装包 yum -y install make gcc-c++ cmake bison-devel ncurses-devel readline ...

  4. mysql主从备份+keepalived自动切换

    数据库这一层需要做到避免单点故障可以是主从备份和主主备份,主主备份可能有性能损耗和数据同步的问题.这里记录下主从备份, mysql进行备份之前确保mysql的版本是一样的,我这里用的都是mysql5. ...

  5. mysql主从备份功能配置与測试

    在高訪问量服务环境下,单机配置mysql服务将无法满足频繁快速的数据读写操作. 一旦mysql出现故障造成数据丢失.无法恢复. 因此.在mysql服务上启用主从备份功能,支持读写分离技术.最靠可的是搭 ...

  6. mysql主从服务器的配置

    使用mysql主从复制的好处有: 1.采用主从服务器这种架构,稳定性得以提升.如果主服务器发生故障,我们可以使用从服务器来提供服务. 2.在主从服务器上分开处理用户的请求,可以提升数据处理效率. 3. ...

  7. MySQL主从介绍、配置主从、测试主从同步

    6月28日任务 说明:有不少同学不能一次性把实验做成功,这是因为还不熟悉,建议至少做3遍17.1 MySQL主从介绍17.2 准备工作17.3 配置主17.4 配置从17.5 测试主从同步有的同学,遇 ...

  8. Linux Centos下MySQL主从Replication同步配置(一主一从)

    MySQL 主从复制概念MySQL 主从复制是指数据可以从一个MySQL数据库服务器主节点复制到一个或多个从节点.MySQL 默认采用异步复制方式,这样从节点不用一直访问主服务器来更新自己的数据,数据 ...

  9. 在现有的mysql主从基础上,搭建mycat实现数据的读写分离

    环境准备:MySQL服务器做好主从复制:centos6的系统 主:192.168.164.131 从:192.168.164.144 mycat服务器:192.168.164.141 a.将MySQL ...

随机推荐

  1. Oracle函数——日期函数

    Oracle中的时间类型只有date和TIMESTAMP,TIMESTAMP是比date更精确的类型.日期时间函数用于处理时间类型的数据,Oracle以7位数字格式来存放日期数据,包括世纪.年.月.日 ...

  2. 随心测试_数据库_003 <数据库存储结构>

    接上篇:了解了_数据库系统组成,继续理解必备知识点:数据库存储_逻辑结构 快速理解 数据存储结构:数据库系统_数据库_表 1. 理解什么是数据库 数据库发展:大致由 人工管理.文件系统.数据库系统(高 ...

  3. Quick Sort(三向切分的快速排序)(Java)

    //三向切分的快速排序 //这种切分方法对于数组中有大量重复元素的情况有比较大的性能提升 public static void main(String[] args) { Scanner input ...

  4. Python----数据预处理

    导入标准库 import numpy as np import matplotlib.pyplot as plt import pandas as pd 导入数据集 dataset = pd.read ...

  5. IntelliJ IDEA中Mapper接口通过@Autowired注入报错的正确解决方式

    转载请注明来源:四个空格 » IntelliJ IDEA中Mapper接口通过@Autowired注入报错的正确解决方式: 环境 ideaIU-2018.3.4.win: 错误提示: Could no ...

  6. [转载] .NET 中可以有类似 JVM 的幻像引用吗?

    近日发现一篇不错的文章,文中列举了一些 GC 场景,探讨了 在 .NET 中是需要实现像 JVM 的中的幻像引用.有人质疑其不切实际,也有像 Ayende 大神一言不合就自己做了个 demo. Do ...

  7. nginx springboot配置

    1.下载安装nginx 2.nginx.conf文件修改参数 上方是代理后的端口,代理的server.下方是需要代理的路径 3.windows 下操作指令 启动 直接点击Nginx目录下的nginx. ...

  8. 如何获得select被选中option的value和text

    如何获得select被选中option的value和text 一:JavaScript原生的方法 1:拿到select对象: var myselect=document.getElementById( ...

  9. Xcode 打包(Shell)

    1. xcodebuild 1.1 查当前可用的 sdk $xcodebuild -showsdks 1.2 查看所支持的target $xcodebuild -target 1.2 清空当前编译的a ...

  10. Android List 排序

    Collections.sort(list, (l1, l2) -> l1.getID().compareTo(l2.getID())); list:泛型集合 l1:比较的前一个泛型 l2:比较 ...