vrrp_script chk_port_3306 {
script"/opt/dtstack/dtagent/agent/mysqlha_check_alive.py 3306"
interval 11# check every 2 seconds
fall 3# require 2 failures for KO
rise 3# require 2 successes for OK
timeout 11
}
vrrp_instance mysql_3306 {
state MASTER
interface eth0 #检测eth0
garp_master_delay 5
virtual_router_id 231 #路由组
priority 251 #权重
advert_int 1
authentication {
auth_type PASS
auth_pass PASS3306
}
virtual_ipaddress {
192.168.40.231/24 dev eth0 # vip是192.168.40.231/24 起在eth0上
}
track_script {
chk_port_3306 # 检测3306端口
}
IP | 主机名 | 角色 | mha角色 |
---|---|---|---|
192.168.2.61 | node1 | 主库 | node |
192.168.2.62 | node2 | 从库1 | node |
192.168.2.63 | node3 | 从库2 | node , mha-master |
yum -y install keepalived
[root@node1 ~]# cat /etc/keepalived/keepalived.conf
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id MySQL-HA
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 150
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.6.66/24
}
}
[root@node2 ~]# cat /etc/keepalived/keepalived.conf
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id MySQL-HA
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 150
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.6.66/24
}
}
Fri Jul 1 13:35:33 2016 - [info] Dead Servers:
Fri Jul 1 13:35:33 2016 - [info] 192.168.118.63(192.168.118.63:3306)
Fri Jul 1 13:35:33 2016 - [info] Alive Servers:
Fri Jul 1 13:35:33 2016 - [info] 192.168.118.62(192.168.118.62:3306)
Fri Jul 1 13:35:33 2016 - [info] 192.168.118.64(192.168.118.64:3306)
Fri Jul 1 13:35:33 2016 - [info] Alive Slaves:
Fri Jul 1 13:35:33 2016 - [info] 192.168.118.62(192.168.118.62:3306) Version=5.6.28-log (oldest major version between slaves) log-bin:enabled
Fri Jul 1 13:35:33 2016 - [info] GTID ON
Fri Jul 1 13:35:33 2016 - [info] Replicating from 192.168.118.63(192.168.118.63:3306)
Fri Jul 1 13:35:33 2016 - [info] Primary candidate for the new Master (candidate_master is set)
Fri Jul 1 13:35:33 2016 - [info] 192.168.118.64(192.168.118.64:3306) Version=5.6.28-log (oldest major version between slaves) log-bin:enabled
Fri Jul 1 13:35:33 2016 - [info] GTID ON
Fri Jul 1 13:35:33 2016 - [info] Replicating from 192.168.118.63(192.168.118.63:3306)
Fri Jul 1 13:35:33 2016 - [info] Primary candidate for the new Master (candidate_master is set)
Fri Jul 1 13:35:33 2016 - [info] Checking slave configurations..
Fri Jul 1 13:35:33 2016 - [info] read_only=1 is not set on slave 192.168.118.62(192.168.118.62:3306).
Fri Jul 1 13:35:33 2016 - [info] read_only=1 is not set on slave 192.168.118.64(192.168.118.64:3306).
Fri Jul 1 13:35:33 2016 - [info] Checking replication filtering settings..
Fri Jul 1 13:35:33 2016 - [info] Replication filtering check ok.
[info] ** Phase 1: Configuration Check Phase completed.
检查项目如下:
Query SELECT @@global.server_id As Value
Query SELECT VERSION() AS Value #如果是GTID模式,版本不得小于5.6,如果是普通模式,版本不得小于5.0.45
Query SELECT @@global.gtid_mode As Value #MHA0.56版本开始支持GTID,之前的版本不支持
Query SHOW GLOBAL VARIABLES LIKE 'log_bin' #binlog必须开启
Query SHOW MASTER STATUS
Query SELECT @@global.datadir AS Value
Query SELECT @@global.slave_parallel_workers AS Value #确定slave是不是多线程并行复制,这个参数的影响还没整明白,再研究下
Query SHOW SLAVE STATUS
Query SELECT @@global.read_only As Value #确定read_only的设置,如果要转为新的master,这个值要设为0
Query SELECT @@global.relay_log_purge As Value #确定relay_log是否可自动删除,默认是可以
Query SELECT @@global.relay_log_info_repository AS Value #确定relay_log是以file还是table格式存放的,默认是file
Query SELECT @@global.datadir AS Value #确定数据存放位置
Query SELECT @@global.relay_log_info_file AS Value #确定relay_log的文件名,为后面slave之间的relay_log应用做准备
备注:1. 默认情况下,从服务器上的中继日志在SQL线程执行完后会被自动删除的。但是这些中继日志在恢复其他从服务器时候可能会被用到,因此需要禁用中继日志的自动清除和定期清除旧的中继日志
2. binlog-do-db和replicate-ignore-db设置必须相同。MHA在启动时候会检测过滤规则,如果过滤规则不同,MHA不启动监控和故障转移
[info] * Phase 2: Dead Master Shutdown Phase..
具体关闭命令是:
/etc/masterha/master_ip_failover --orig_master_host=192.168.118.3 --orig_master_ip=192.168.118.3 --orig_master_port=3306 --command=stopssh --ssh_user=root
关闭完成后给出报告
[info] * Phase 2: Dead Master Shutdown Phase completed.
[info] * Phase 3: Master Recovery Phase..
Fri Jul 1 13:35:33 2016 - [info] Getting new master's binlog name and position..
Fri Jul 1 13:35:33 2016 - [info] mysql-bin.000004:191
Fri Jul 1 13:35:33 2016 - [info] All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='192.168.118.2', MASTER_PORT=3306, MAST
ER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='xxx';
/etc/masterha/master_ip_failover --command=start --ssh_user=root --orig_master_host=192.168.118.3 --orig_master_ip=192.168.118.3 --orig_master_port=3306 --new_master_host=192.168.118.2 --new_master_ip=192.168.118.2 --new_master_port=3306 --new_master_user='user' --new_master_password='password'
Fri Jul 1 13:35:33 2016 - [info] ** Finished master recovery successfully.
Fri Jul 1 13:35:33 2016 - [info] * Phase 3: Master Recovery Phase completed.
[info] * Phase 4: Slaves Recovery Phase..
Query SHOW SLAVE STATUS
Query STOP SLAVE IO_THREAD
Query SHOW SLAVE STATUS
Query SHOW SLAVE STATUS
Query STOP SLAVE
Query SHOW SLAVE STATUS
Query RESET SLAVE
Query CHANGE MASTER TO MASTER_HOST = '192.168.118.62' MASTER_USER = 'repl' MASTER_PASSWORD = MASTER_PORT = 3306
Query START SLAVE
Connect Out [email protected]:3306
Query SHOW SLAVE STATUS
reset slave all;
https://blog.csdn.net/Mryiyi/article/details/73822952