Keepalive+双主
在mydb1,mydb2,mydb3服务器上分别执行:
ssh-keygen -t rsa
ssh-copy-id -i .ssh/id_rsa.pub root@192.168.1.101
ssh-copy-id -i .ssh/id_rsa.pub root@192.168.1.102
ssh-copy-id -i .ssh/id_rsa.pub root@192.168.1.103
cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.101 mydb1
192.168.1.102 mydb2
192.168.1.103 mydb3
在mydb1上操作
修改mysql配置文件:
vi /app/mysqldata/3306/my.cnf
在原有文件添加以下参数:
[mysqld]
server_id=1013306
log_slave_updates = 1
auto-increment-increment = 2
auto-increment-offset = 1
log-bin = /app/mysqldata/3306/binlog/mysql-bin
log-bin-index = /app/mysqldata/3306/binlog/mysql-bin.index
[root@mydb1 ~]# mysql_db_startup.sh 3306
[root@mydb1 ~]# mysqlplus.sh 3306
(root@localhost) [(none)]> create user xtrabk@'192.168.1.%' identified by 'onlybackup';
(root@localhost) [(none)]> grant reload,lock tables,process,Replication client,super on *.* to xtrabk@'192.168.1.%';
(root@localhost) [(none)]> create user rep1@'192.168.1.%' identified by 'rep1';
(root@localhost) [(none)]> grant replication slave on *.* to 'rep1'@'192.168.1.%';
(root@localhost) [(none)]> flush privileges;
(root@localhost) [(none)]> show VARIABLES LIKE 'have_dynamic_loading';
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| have_dynamic_loading | YES |
+----------------------+-------+
1 row in set (0.00 sec)
(root@localhost) [(none)]> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
(root@localhost) [(none)]> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
(root@localhost) [(none)]> show variables like '%semi%';
+-------------------------------------------+------------+
| Variable_name | Value |
+-------------------------------------------+------------+
| rpl_semi_sync_master_enabled | ON |
| rpl_semi_sync_master_timeout | 5000 |
| rpl_semi_sync_master_trace_level | 32 |
| rpl_semi_sync_master_wait_for_slave_count | 1 |
| rpl_semi_sync_master_wait_no_slave | ON |
| rpl_semi_sync_master_wait_point | AFTER_SYNC |
| rpl_semi_sync_slave_enabled | ON |
| rpl_semi_sync_slave_trace_level | 32 |
+-------------------------------------------+------------+
8 rows in set (0.00 sec)
SET GLOBAL rpl_semi_sync_master_timeout = 5000 ;
[root@mydb1 ~]# /app/mysqldata/scripts/my_full_backup.sh
复制和准备备份集
[root@mydb1 tmp]# scp -r xtrabackup/ mydb2:`pwd`
[root@mydb1 tmp]# scp -r xtrabackup/ mydb3:`pwd`
mysql配置文件:
vi /app/mysqldata/3306/my.cnf
在原有文件添加以下参数:
[mysqld]
server_id = 1023306
log_slave_updates = 1
auto-increment-increment = 2
auto-increment-offset = 2
log-bin = /app/mysqldata/3306/binlog/mysql-bin
log-bin-index = /app/mysqldata/3306/binlog/mysql-bin.index
[root@mydb2 ~]# /app/mysqldata/scripts/my_full_recover.sh
(root@localhost) [(none)]> show VARIABLES LIKE 'have_dynamic_loading';
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| have_dynamic_loading | YES |
+----------------------+-------+
1 row in set (0.00 sec)
(root@localhost) [(none)]> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
(root@localhost) [(none)]> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
(root@localhost) [(none)]> show variables like '%semi%';
+-------------------------------------------+------------+
| Variable_name | Value |
+-------------------------------------------+------------+
| rpl_semi_sync_master_enabled | ON |
| rpl_semi_sync_master_timeout | 5000 |
| rpl_semi_sync_master_trace_level | 32 |
| rpl_semi_sync_master_wait_for_slave_count | 1 |
| rpl_semi_sync_master_wait_no_slave | ON |
| rpl_semi_sync_master_wait_point | AFTER_SYNC |
| rpl_semi_sync_slave_enabled | ON |
| rpl_semi_sync_slave_trace_level | 32 |
+-------------------------------------------+------------+
8 rows in set (0.00 sec)
查看备份文件中的位置信息
[root@mydb2 full]# cat xtrabackup_binlog_info
mysql-bin.000002 236874 9831a804-8c25-11e8-9a69-000c2983201e:1-3,
a5d58971-9ee1-11e8-8767-000c2983201e:1-576
(root@localhost) [(none)]> prompt Slave>
Slave>stop slave;
Query OK, 0 rows affected (0.00 sec)
Slave>reset master;
Query OK, 0 rows affected (0.02 sec)
Slave>set global GTID_PURGED='9831a804-8c25-11e8-9a69-000c2983201e:1-3,a5d58971-9ee1-11e8-8767-000c2983201e:1-576';
Query OK, 0 rows affected (0.00 sec)
Slave > change master to master_host='192.168.1.101',master_port=3306,master_user='rep1',master_password='rep1',MASTER_AUTO_POSITION =1;
Slave > start slave;
Slave > show slave status\G
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Slave>show master status;
+------------------+----------+--------------+------------------+--------------------------------------------------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+--------------------------------------------------------------------------------------+
| mysql-bin.000001 | 154 | | | 9831a804-8c25-11e8-9a69-000c2983201e:1-3,
a5d58971-9ee1-11e8-8767-000c2983201e:1-576 |
+------------------+----------+--------------+------------------+--------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql配置文件:
vi /app/mysqldata/3306/my.cnf
在原有文件添加以下参数:
[mysqld]
server_id = 1033306
read_only = 1
relay_log_purge = 0
log_slave_updates = 1
relay_log = /data/mysqldata/3306/binlog/mysql-relay-bin
relay_log_index = /data/mysqldata/3306/binlog/mysql-relay-bin.index
log-bin = /data/mysqldata/3306/binlog/mysql-bin
log-bin-index = /data/mysqldata/3306/binlog/mysql-bin.index
[root@mydb3 ~]# /app/mysqldata/scripts/my_full_recover.sh
(root@localhost) [(none)]> show VARIABLES LIKE 'have_dynamic_loading';
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| have_dynamic_loading | YES |
+----------------------+-------+
1 row in set (0.00 sec)
(root@localhost) [(none)]> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
(root@localhost) [(none)]> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
(root@localhost) [(none)]> show variables like '%semi%';
+-------------------------------------------+------------+
| Variable_name | Value |
+-------------------------------------------+------------+
| rpl_semi_sync_master_enabled | ON |
| rpl_semi_sync_master_timeout | 5000 |
| rpl_semi_sync_master_trace_level | 32 |
| rpl_semi_sync_master_wait_for_slave_count | 1 |
| rpl_semi_sync_master_wait_no_slave | ON |
| rpl_semi_sync_master_wait_point | AFTER_SYNC |
| rpl_semi_sync_slave_enabled | ON |
| rpl_semi_sync_slave_trace_level | 32 |
+-------------------------------------------+------------+
8 rows in set (0.00 sec)
查看备份文件中的位置信息
[root@mydb3 full]# cat xtrabackup_binlog_info
mysql-bin.000002 236874 9831a804-8c25-11e8-9a69-000c2983201e:1-3,
a5d58971-9ee1-11e8-8767-000c2983201e:1-576
(root@localhost) [(none)]> prompt Slave>
Slave>stop slave;
Query OK, 0 rows affected (0.00 sec)
Slave>reset master;
Query OK, 0 rows affected (0.02 sec)
Slave>set global GTID_PURGED='9831a804-8c25-11e8-9a69-000c2983201e:1-3,a5d58971-9ee1-11e8-8767-000c2983201e:1-576';
Query OK, 0 rows affected (0.00 sec)
Slave > change master to master_host='192.168.1.101',master_port=3306,master_user='rep1',master_password='rep1',MASTER_AUTO_POSITION =1;
Slave > start slave;
Slave > show slave status\G
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
将主指向mydb2:
(root@localhost) [(none)]> prompt Slave>
Slave > change master to master_host='192.168.1.102',master_port=3306,master_user='rep1',master_password='rep1',MASTER_AUTO_POSITION =1;
Slave > start slave;
Slave > show slave status\G
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Keepalived主要功能:
实现IP地址的漂移
执行健康检查
[root@mydb1 /]# wget http://www.keepalived.org/software/keepalived-1.4.5.tar.gz
[root@mydb1 /]# tar xvfz keepalived-1.4.5.tar.gz
[root@mydb1 /]# cd keepalived-1.4.5
[root@mydb1 keepalived-1.4.5]# ./configure --prefix=/usr/local/keepalived
[root@mydb1 keepalived-1.4.5]# make && make install
复制文件到相关路径,以方便调用
[root@mydb1 /]# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
[root@mydb1 ~]# vim /etc/init.d/keepalived
#!/bin/sh
#
# Startup script for the Keepalived daemon
#
# processname: keepalived
# pidfile: /var/run/keepalived.pid
# config: /etc/keepalived/keepalived.conf
# chkconfig: - 21 79
# description: Start and stop Keepalived
. /etc/rc.d/init.d/functions
. /etc/sysconfig/keepalived
echo -n $"Starting $prog: "
daemon keepalived ${KEEPALIVED_OPTIONS}
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
}
echo -n $"Stopping $prog: "
killproc keepalived
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
}
echo -n $"Reloading $prog: "
killproc keepalived -1
RETVAL=$?
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
condrestart)
if [ -f /var/lock/subsys/$prog ]; then
stop
start
fi
;;
status)
status keepalived
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|reload|restart|condrestart|status}"
RETVAL=1
esac
[root@mydb1 /]# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
默认情况下Keepalived会查找/etc/keepalived/keepalived.conf文件
[root@mydb1 /]# mkdir -p /etc/keepalived
[root@mydb1 /]# vim /etc/keepalived/keepalived.conf
!Configuration File for keepalived
global_defs {
notification_email {
allenhu@sina.com
}
notification_email_from allenhu@sina.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id MySQL_HA
}
vrrp_script check_run {
script "/usr/local/keepalived/mysql.sh"
interval 5
}
vrrp_instance HA_1 {
state BACKUP
nopreempt
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 3306
}
track_script {
check_run
}
virtual_ipaddress {
192.168.1.205/24
}
}
[root@mydb1 /]# vim /usr/local/keepalived/mysql.sh
#!/bin/bash
MYSQL=/usr/local/mysql/bin/mysql
MYSQL_HOST=localhost
MYSQL_USER=root
MYSQL_PASSWORD=msds007
MYSQL_SOCKET=/app/mysqldata/3306/mysql.sock
CHECK_TIME=3
#mysql is working MYSQL_OK is 1 , mysql down MYSQL_OK is 0
MYSQL_OK=1
function check_mysql_helth (){
$MYSQL -h $MYSQL_HOST -u${MYSQL_USER} -p${MYSQL_PASSWORD} -S ${MYSQL_SOCKET} -e "show status;" >/dev/null 2>&1
if [ $? = 0 ] ;then
MYSQL_OK=1
else
MYSQL_OK=0
fi
return $MYSQL_OK
}
while [ $CHECK_TIME -ne 0 ]
do
let "CHECK_TIME -= 1"
check_mysql_helth
if [ $MYSQL_OK = 1 ] ; then
CHECK_TIME=0
exit 0
fi
if [ $MYSQL_OK -eq 0 ] && [ $CHECK_TIME -eq 0 ]
then
/etc/init.d/keepalived stop
exit 1
fi
sleep 1
done
[root@mydb1 /]# /etc/init.d/keepalived start
Aug 13 20:47:55 mydb1 systemd: Starting LVS and VRRP High Availability Monitor...
Aug 13 20:47:55 mydb1 Keepalived[22449]: Starting Keepalived v1.4.5 (05/26,2018)
Aug 13 20:47:55 mydb1 Keepalived[22449]: Running on Linux 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 (built for Linux 3.10.0)
Aug 13 20:47:55 mydb1 Keepalived[22449]: Opening file '/etc/keepalived/keepalived.conf'.
Aug 13 20:47:55 mydb1 systemd: PID file /var/run/keepalived.pid not readable (yet?) after start.
Aug 13 20:47:55 mydb1 Keepalived[22451]: Starting Healthcheck child process, pid=22452
Aug 13 20:47:55 mydb1 Keepalived[22451]: Starting VRRP child process, pid=22453
Aug 13 20:47:55 mydb1 systemd: Started LVS and VRRP High Availability Monitor.
Aug 13 20:47:55 mydb1 Keepalived_healthcheckers[22452]: Opening file '/etc/keepalived/keepalived.conf'.
Aug 13 20:47:55 mydb1 Keepalived_vrrp[22453]: Registering Kernel netlink reflector
Aug 13 20:47:55 mydb1 Keepalived_vrrp[22453]: Registering Kernel netlink command channel
Aug 13 20:47:55 mydb1 Keepalived_vrrp[22453]: Registering gratuitous ARP shared channel
Aug 13 20:47:55 mydb1 Keepalived_vrrp[22453]: Opening file '/etc/keepalived/keepalived.conf'.
Aug 13 20:47:55 mydb1 Keepalived_vrrp[22453]: WARNING - default user 'keepalived_script' for script execution does not exist - please create.
Aug 13 20:47:55 mydb1 Keepalived_vrrp[22453]: SECURITY VIOLATION - scripts are being executed but script_security not enabled.
Aug 13 20:47:55 mydb1 Keepalived_vrrp[22453]: VRRP_Instance(HA_1) removing protocol VIPs.
Aug 13 20:47:55 mydb1 Keepalived_vrrp[22453]: Using LinkWatch kernel netlink reflector...
Aug 13 20:47:55 mydb1 Keepalived_vrrp[22453]: VRRP_Instance(HA_1) Entering BACKUP STATE
Aug 13 20:47:55 mydb1 Keepalived_vrrp[22453]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
Aug 13 20:47:55 mydb1 Keepalived_vrrp[22453]: VRRP_Script(check_run) succeeded
Aug 13 20:47:59 mydb1 Keepalived_vrrp[22453]: VRRP_Instance(HA_1) Transition to MASTER STATE
Aug 13 20:48:00 mydb1 Keepalived_vrrp[22453]: VRRP_Instance(HA_1) Entering MASTER STATE
Aug 13 20:48:00 mydb1 Keepalived_vrrp[22453]: VRRP_Instance(HA_1) setting protocol VIPs.
Aug 13 20:48:00 mydb1 Keepalived_vrrp[22453]: Sending gratuitous ARP on ens33 for 192.168.1.205
Aug 13 20:48:00 mydb1 Keepalived_vrrp[22453]: VRRP_Instance(HA_1) Sending/queueing gratuitous ARPs on ens33 for 192.168.1.205
Aug 13 20:48:00 mydb1 Keepalived_vrrp[22453]: Sending gratuitous ARP on ens33 for 192.168.1.205
Aug 13 20:48:00 mydb1 Keepalived_vrrp[22453]: Sending gratuitous ARP on ens33 for 192.168.1.205
Aug 13 20:48:00 mydb1 Keepalived_vrrp[22453]: Sending gratuitous ARP on ens33 for 192.168.1.205
Aug 13 20:48:00 mydb1 Keepalived_vrrp[22453]: Sending gratuitous ARP on ens33 for 192.168.1.205
Aug 13 20:48:00 mydb1 avahi-daemon[797]: Registering new address record for 192.168.1.205 on ens33.IPv4.
Aug 13 20:48:05 mydb1 Keepalived_vrrp[22453]: Sending gratuitous ARP on ens33 for 192.168.1.205
Aug 13 20:48:05 mydb1 Keepalived_vrrp[22453]: VRRP_Instance(HA_1) Sending/queueing gratuitous ARPs on ens33 for 192.168.1.205
Aug 13 20:48:05 mydb1 Keepalived_vrrp[22453]: Sending gratuitous ARP on ens33 for 192.168.1.205
Aug 13 20:48:05 mydb1 Keepalived_vrrp[22453]: Sending gratuitous ARP on ens33 for 192.168.1.205
Aug 13 20:48:05 mydb1 Keepalived_vrrp[22453]: Sending gratuitous ARP on ens33 for 192.168.1.205
Aug 13 20:48:05 mydb1 Keepalived_vrrp[22453]: Sending gratuitous ARP on ens33 for 192.168.1.205
[root@mydb2 /]# tar xvfz keepalived-1.4.5.tar.gz
[root@mydb2 /]# cd keepalived-1.4.5
[root@mydb2 keepalived-1.4.5]# ./configure --prefix=/usr/local/keepalived
[root@mydb2 keepalived-1.4.5]# make && make install
复制文件到相关路径,以方便调用
[root@mydb2 /]# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
[root@mydb2 ~]# vim /etc/init.d/keepalived
#!/bin/sh
#
# Startup script for the Keepalived daemon
#
# processname: keepalived
# pidfile: /var/run/keepalived.pid
# config: /etc/keepalived/keepalived.conf
# chkconfig: - 21 79
# description: Start and stop Keepalived
. /etc/rc.d/init.d/functions
. /etc/sysconfig/keepalived
echo -n $"Starting $prog: "
daemon keepalived ${KEEPALIVED_OPTIONS}
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
}
echo -n $"Stopping $prog: "
killproc keepalived
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
}
echo -n $"Reloading $prog: "
killproc keepalived -1
RETVAL=$?
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
condrestart)
if [ -f /var/lock/subsys/$prog ]; then
stop
start
fi
;;
status)
status keepalived
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|reload|restart|condrestart|status}"
RETVAL=1
esac
[root@mydb2 /]# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
默认情况下Keepalived会查找/etc/keepalived/keepalived.conf文件
[root@mydb2 /]# mkdir -p /etc/keepalived
[root@mydb2 /]# vim /etc/keepalived/keepalived.conf
!Configuration File for keepalived
global_defs {
notification_email {
allenhu@sina.com
}
notification_email_from allenhu@sina.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id MySQL_HA
}
vrrp_script check_run {
script "/usr/local/keepalived/mysql.sh"
interval 5
}
vrrp_instance HA_1 {
state BACKUP
nopreempt
interface ens33
virtual_router_id 51
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 3306
}
track_script {
check_run
}
virtual_ipaddress {
192.168.1.205/24
}
}
[root@mydb2 /]# vim /usr/local/keepalived/mysql.sh
#!/bin/bash
MYSQL=/usr/local/mysql/bin/mysql
MYSQL_HOST=localhost
MYSQL_USER=root
MYSQL_PASSWORD=msds007
MYSQL_SOCKET=/app/mysqldata/3306/mysql.sock
CHECK_TIME=3
#mysql is working MYSQL_OK is 1 , mysql down MYSQL_OK is 0
MYSQL_OK=1
function check_mysql_helth (){
$MYSQL -h $MYSQL_HOST -u${MYSQL_USER} -p${MYSQL_PASSWORD} -S ${MYSQL_SOCKET} -e "show status;" >/dev/null 2>&1
if [ $? = 0 ] ;then
MYSQL_OK=1
else
MYSQL_OK=0
fi
return $MYSQL_OK
}
while [ $CHECK_TIME -ne 0 ]
do
let "CHECK_TIME -= 1"
check_mysql_helth
if [ $MYSQL_OK = 1 ] ; then
CHECK_TIME=0
exit 0
fi
if [ $MYSQL_OK -eq 0 ] && [ $CHECK_TIME -eq 0 ]
then
/etc/init.d/keepalived stop
exit 1
fi
sleep 1
done
[root@mydb2 /]# /etc/init.d/keepalived start
Aug 14 04:51:27 mydb2 systemd: Starting LVS and VRRP High Availability Monitor...
Aug 14 04:51:27 mydb2 Keepalived[13561]: Starting Keepalived v1.4.5 (05/26,2018)
Aug 14 04:51:27 mydb2 Keepalived[13561]: Running on Linux 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 (built for Linux 3.10.0)
Aug 14 04:51:27 mydb2 Keepalived[13561]: Opening file '/etc/keepalived/keepalived.conf'.
Aug 14 04:51:27 mydb2 systemd: PID file /var/run/keepalived.pid not readable (yet?) after start.
Aug 14 04:51:27 mydb2 Keepalived[13563]: Starting Healthcheck child process, pid=13564
Aug 14 04:51:27 mydb2 Keepalived[13563]: Starting VRRP child process, pid=13565
Aug 14 04:51:27 mydb2 systemd: Started LVS and VRRP High Availability Monitor.
Aug 14 04:51:27 mydb2 Keepalived_healthcheckers[13564]: Opening file '/etc/keepalived/keepalived.conf'.
Aug 14 04:51:27 mydb2 Keepalived_vrrp[13565]: Registering Kernel netlink reflector
Aug 14 04:51:27 mydb2 Keepalived_vrrp[13565]: Registering Kernel netlink command channel
Aug 14 04:51:27 mydb2 Keepalived_vrrp[13565]: Registering gratuitous ARP shared channel
Aug 14 04:51:27 mydb2 Keepalived_vrrp[13565]: Opening file '/etc/keepalived/keepalived.conf'.
Aug 14 04:51:27 mydb2 Keepalived_vrrp[13565]: WARNING - default user 'keepalived_script' for script execution does not exist - please create.
Aug 14 04:51:27 mydb2 Keepalived_vrrp[13565]: SECURITY VIOLATION - scripts are being executed but script_security not enabled.
Aug 14 04:51:27 mydb2 Keepalived_vrrp[13565]: VRRP_Instance(HA_1) removing protocol VIPs.
Aug 14 04:51:27 mydb2 Keepalived_vrrp[13565]: Using LinkWatch kernel netlink reflector...
Aug 14 04:51:27 mydb2 Keepalived_vrrp[13565]: VRRP_Instance(HA_1) Entering BACKUP STATE
Aug 14 04:51:27 mydb2 Keepalived_vrrp[13565]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
Aug 14 04:51:27 mydb2 Keepalived_vrrp[13565]: VRRP_Script(check_run) succeeded
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.7.22-log MySQL Community Server (GPL)
affiliates. Other names may be trademarks of their respective
owners.
+----------------+--------------------------------------+
| Variable_name | Value |
+----------------+--------------------------------------+
| server_id | 1013306 |
| server_id_bits | 32 |
| server_uuid | a5d58971-9ee1-11e8-8767-000c2983201e |
+----------------+--------------------------------------+
3 rows in set (0.00 sec)
通过查看/var/log/messges日志,看出主备切换过程
在192.168.1.101上关闭MySQL服务,看VIP是否会切换到192.168.1.102上
开启192.168.1.101上的MySQL和keepalived,然后关闭192.168.1.102上的MySQL,看VIP是否会切换到192.168.1.101上
主进程
healthcheck
Vrrp
先进入backup state,运行一次vrrp_script,成功后,发现没有主 -> master -> 拉起vip -> 完成启动
原keepalived master节点,运行检查脚本异常,则keepalived进入FAULT状态,释放vip,原backup的keepalived会接管vip
VRRP通信断掉了
MASTER
FAULT
Keepalive+双主的更多相关文章
- Keepalive双主搭建配置
Keepalive 双主搭建配置 keepalived保证双主数据库的可用性 环境说明 192.168.1.10 keepalive 主1 192.168.1.20 keepalive 主2 19 ...
- 生产环境中mysql+keepalive双主模式,keepalive守护进程实现双主切换提供数据库服务
mysql+keepalive实现浮动地址自动切换,由于keepalive无自带健康检查功能,所以必须自动编写健康检查守护进程(监控DB1和DB2数据库的监控状态,来保证浮动地址双机自动切换.) 一, ...
- haproxy+keepalive双主高可用实现负载均衡
转载自https://blog.51cto.com/3381847248/1977073 前面我已经介绍了haproxy结合keepalive做简单的双主高可用,如果不清楚的话,可以去我的上一 篇博客 ...
- Apache+lvs高可用+keepalive(主从+双主模型)
Apache+lvs高可用+keepalive(主从+双主模型) keepalive实验准备环境: httpd-2.2.15-39.el6.centos.x86_64 keepalived-1 ...
- lvs+keepalive实现双主模式(采用DR),同时实现TCP和UDP检测实现非web端的负载均衡,同时实现跨网段的通讯
因为公司领导需要,需要把lvs备机也使用上,故! 使用双主,相互是主的同时也相互是备机.本人用nat测试发现RS无法实现负载均衡,故采用DR模式来实现非web端的负载均衡 lvs1: DIP 10.6 ...
- Keepalived+MySQL双主
一.Keepalived+MySQL Replication的应用场景 MySQL的高可用方案有cluster,MMM,MHA等,这些高可用方案都要三台服务器以上,成本有点高,今天介绍一个低成本高可用 ...
- 高可用-mysql安装,双主模式+keepalived
mysql安装 1.添加用户 groupadd mysql useradd -r -g mysql mysql
- Mysql+Keepalived双主热备高可用操作记录
我们通常说的双机热备是指两台机器都在运行,但并不是两台机器都同时在提供服务.当提供服务的一台出现故障的时候,另外一台会马上自动接管并且提供服务,而且切换的时间非常短.MySQL双主复制,即互为Mast ...
- 高可用Mysql架构_Mycat集群部署(HAProxy + 两台Mycat+Mysql双主双从)
既然大家都知道了Mysql分布式在大型网站架构中的作用,在这里就不再阐述.本片博客文章是基于我曾经搭建过的一个Mysql集群基础上实现的,实现过双主热备.读写分离.分库分表. 博客链接:http:// ...
随机推荐
- 在CUDA8.0下指定位置编译安装OpenCV3.1.0来实现GPU加速(Compiling OpenCV3.1.0 with CUDA8.0 support)
在CUDA8.0下指定位置编译安装OpenCV3.1.0 一.本人电脑配置:ubuntu 14.04, NVIDIA GTX1060. 二.编译OpenCV3.1.0前,读者需要成功安装CUDA8.0 ...
- js base64编码,C#解码
JS: this.Base64 = function (str) { return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, fu ...
- 【零基础】搞定LAMP(linux、apache、mysql、php)环境安装图文教程(基于centos7)
一.前言 LAMP即:Linux.Apache.Mysql.Php,也就是在linux系统下运行php网站代码,使用的数据库是mysql.web服务软件是apache.之所以存在LAMP这种说法,倒不 ...
- CDN之Web Cache
1. Cache 的工作方式 Web Cache 作为一种网页缓存技术,可以在用户访问网站服务器的任何一个中间网元上实现.根据 HTTP 协议的定义,在一次网页访问中,用户从客户端发出请求到网站服务器 ...
- 线性dp,分层图思想
题目大意:给你一串数字,一串运算符,求递推用完运算符时答案的最大值----->线性dp dp[i][j] i表示所用数字的个数 j表示所用字符的个数 分层图思想 所有字符必须用完 所以取最后 ...
- legend3---12、DB::table('user_questions')和UserQuestion查询的结果的格式不一样
legend3---12.DB::table('user_questions')和UserQuestion查询的结果的格式不一样 一.总结 一句话总结: 推荐使用模型查找的方式,可以直接数组方式访问: ...
- 14 statefulset (sts)控制器
statefulset (sts)控制器 可以用于部署有状态的服务,比如说redis,mysql ,zk等等... 1. 稳定且唯一的网络标志符:2. 稳定且持久的存储3. 有序,平滑地部署和扩展:4 ...
- 001-软件架构概览、maven补充【分包工程、合并包、web容器插件】、git补充
一.整体概述 1.1.共性问题 技术瓶颈.不成体系.不能实际使用.不能落地.无法入门 1.2.目标-软件架构 专注于构建:高可扩展.高性能.大数据量.高并发.分布式的系统架构. 各项技术.组合构建分布 ...
- [Mac]安装pyspider的大坑
1.切记这是一个大坑. 2.我在用mac电脑安装pyspider的时候,原以为pip install pyspider 就万事大吉,合家欢乐了,but the question 比较多. 第一个问题: ...
- playbook常用操作
playbook常用操作 1.检查playbook语法错误 ansible-playbook -i hosts deploy_coredns.yaml --syntax-check 2.查看playb ...