1,C/V模块
1)重点参数
ssh mysql@xxx.xxx.xxx.xxx -p 61935 -i /home/mysql/.ssh/id_rsa "sudo ls -lah'
ssh_user=mysql
ssh_port=52722
ssh_options="-i /home/mysql/.ssh/id_rsa"
ping_interval=3
ping_type=INSERT
用来检查master是否正常(需要注意若从库readonly,会主从不同步)
2)mha命令
测试ssh/usr/local/bin/masterha_check_ssh --conf=/usr/local/mha/app.cnf
测试主从复制/usr/local/bin/masterha_check_repl --conf=/usr/local/mha/app.cnf
查看mha运行状态/usr/local/bin/masterha_check_status --conf=/usr/local/mha/app.cnf
MHA停止/usr/local/bin/masterha_stop --conf=/usr/local/mha/app.cnf
当前session(后台进程)运行mha/usr/local/bin/masterha_manager --conf=/usr/local/mha/app.cnf &
,当退出当前session,mha停止。[info] Got terminate signal. Exit.
后台守护进程运行mhanohup masterha_manager --conf=/usr/local/mha/app.cnf > /usr/local/mha/logs/manager.log 2>&1 &
不能直接关闭item,需要使用ctrl +D logout
2)mha故障切,mha在线切
mha在线切(需要注意,如果new_master_host参数传错,会导致主从异常)/usr/local/bin/masterha_master_switch --conf=/usr/local/mha/app.cnf --master_state=alive --new_master_host=10.103.131.40 --orig_master_is_new_slave --interactive=0
mha故障切(需要注意master必须处于dead状态)/usr/local/bin/masterha_master_switch --conf=/usr/local/mha/app.cnf --master_state=dead --dead_master_host=10.103.131.39 --new_master_host=10.103.131.40 --interactive=0
故障切需要手动恢复cat -n /usr/local/mha/logs/manager.log | grep "CHANGE MASTER TO" | tail -1
CHANGE MASTER TO MASTER_HOST='10.103.131.40', MASTER_PORT=3306, MASTER_LOG_FILE='mysql-master-bin.000044', MASTER_LOG_POS=154, MASTER_USER='root', MASTER_PASSWORD='root';
3)mha二次检测
/usr/local/bin/masterha_secondary_check -s 10.103.131.40 -s 10.103.131.38 --port=52722 --user=mysql --master_host=l-qa-duobeitest-db1.cls.beta.ali.dm --master_ip=10.103.131.39 --master_port=3306
2,手动MHA在线切
1)su mysql
停止mha/usr/local/bin/masterha_stop --conf=/usr/local/mha/app.cnf
二次检测masterha_secondary_check -s 10.103.131.40 -s 10.103.131.38 --port=52722 --user=mysql --master_host=l-qa-duobeitest-db1.cls.beta.ali.dm --master_ip=10.103.131.39 --master_port=3306
在线切/usr/local/bin/masterha_master_switch --conf=/usr/local/mha/app.cnf --master_state=alive --orig_master_is_new_slave --interactive=0 --new_master_host=10.103.131.40
修改app.cnf
中二次检测的配置
启动mhanohup masterha_manager --conf=/usr/local/mha/app.cnf > /usr/local/mha/logs/manager.log 2>&1 &
主库pt-kill慢查询工具迁移到新主/usr/bin/pt-kill --user root --password xxx --busy-time 2 --match-command Query --print --kill --victims all --interval 1 --log /opt/mysql_slow_query.txt --daemonize
主库事务lock检测slowTrxKill
迁移到新主information_schema.INNODB_TRX;information_schema.INNODB_LOCKS;information_schema.INNODB_LOCK_WAITS
使用kill ID,结束INNODB_TRX中一直未提交的事务。
3,坑
1)mha检测改为 INSERT
从库新增infra,master上binlog-do-db 中增加infra数据库。
slave 1read_only ON
CREATE DATABASE
infraDEFAULT CHARACTER SET utf8mb4
slave 2read_only ON
CREATE DATABASE
infraDEFAULT CHARACTER SET utf8mb4
2)当数据库中设置了binlog-do-db时,在不同的binlog_format=statement | row | mixed 下对binlog的写入影响,这个在主从复制中会有一些坑,由于binlog的写入不完全,极有可能会导致主从不一致的情况