数据库运维
记录DBA学习成长历程

MySQL MHA binlog server部署

binlogserver配置

找一台额外的机器,必须要和原库的版本一致,支持gtid并开启,我们直接用的第二个slave(db03)
vim /etc/mha/app1.cnf 
[binlog1]
no_master=1
hostname=10.0.0.203
master_binlog_dir=/data/binserver

创建必要目录并授权

[root@db03 ~]# mkdir -p /data/binserver
[root@db03 ~]# chown -R mysql.mysql /data/*
提前创建好,这个目录不能和原有的binlog一致

拉取主库binlog日志

注意:
拉取日志的起点,需要按照目前从库的已经获取到的二进制日志点为起点
[root@db03 binserver]# pwd
/data/binserver
[root@db03 binserver]#mysqlbinlog -R --host=10.0.0.201 --user=mha --password=mha --raw --stop-never mysql-bin.000002 &
[root@db03 binserver]# ll
total 8
-rw-r----- 1 root root 753 Oct 25 17:34 mysql-bin.000002
-rw-r----- 1 root root 194 Oct 25 17:34 mysql-bin.000003
主库滚动日志,从库自动拉取日志:
db02 [(none)]>show master status;
+------------------+----------+--------------+------------------+------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+------------------------------------------+
| mysql-bin.000003 | 194 | | | 503faaf1-15ca-11eb-9634-000c29159620:1-2 |
+------------------+----------+--------------+------------------+------------------------------------------+
1 row in set (0.00 sec)
db02 [(none)]>flush logs;
db02 [(none)]>flush logs;
[root@db03 binserver]# ll
total 36
-rw-r----- 1 root root 753 Oct 25 17:34 mysql-bin.000002
-rw-r----- 1 root root 241 Oct 25 17:37 mysql-bin.000003
-rw-r----- 1 root root 241 Oct 25 17:37 mysql-bin.000004
-rw-r----- 1 root root 241 Oct 25 17:37 mysql-bin.000005

重启MHA

masterha_stop --conf=/etc/mha/app1.cnf
nohup masterha_manager --conf=/etc/mha/app1.cnf --remove_dead_master_conf 
--ignore_last_failover < /dev/null > /var/log/mha/app1/manager.log 2>&1 &
[root@db03 ~]# masterha_check_status --conf=/etc/mha/app1.cnf

故障处理

主库宕机,binlogserver 自动停掉,manager 也会自动停止。
处理思路:
1、重新获取新主库的binlog到binlogserver中
2、重新配置文件binlog server节点信息
3、最后再启动MHA
赞(0)
MySQL学习笔记 » MySQL MHA binlog server部署