1.环境规划
192.168.12.131 node01 192.168.12.132 node02 192.168.12.133 node03
2.环境准备
一主两从GTID,略。
3.配置关键程序软连接(所有节点)
ln -s /usr/local/mysql/bin/mysqlbinlog /usr/bin/mysqlbinlog ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
4.配置各节点互信(密钥对)
node01: rm ‐rf /root/.ssh ssh‐keygen cd /root/.ssh mv id_rsa.pub authorized_keys scp ‐r /root/.ssh 192.168.12.132:/root scp ‐r /root/.ssh 192.168.12.133:/root 验证: node01: ssh 192.168.12.132 date ssh 192.168.12.133 date node02: ssh 192.168.12.131 date ssh 192.168.12.133 date node03: ssh 192.168.12.131 date ssh 192.168.12.132 date
5.安装软件
#node软件和manager软件下载连接: https://github.com/yoshinorim/mha4mysql-manager/releases/tag/v0.58 https://github.com/yoshinorim/mha4mysql-node/releases/tag/v0.58 #所有节点安装node软件依赖包 yum install perl‐DBD‐MySQL ‐y #安装node软件 rpm -ivh mha4mysql-node-0.58-0.el7.centos.noarch #在主库中创建mha需要的用户 grant all privileges on *.* to mha@'192.168.12.%' identified by 'mha'; #node03节点安装manager软件依赖包 yum install ‐y perl‐Config‐Tiny epel‐release perl‐Log‐Dispatch perl‐Parallel‐ForkManager perl‐Time‐HiRes #安装manager软件 rpm -ivh mha4mysql-manager-0.58-0.el7.centos.noarch
6.Manager配置文件准备
#创建配置文件目录 mkdir ‐p /etc/mha #创建日志目录 mkdir ‐p /var/log/mha/app1 #编辑mha配置文件 [root@node03 ~]# vim /etc/mha/app1.cnf [server default] manager_log=/var/log/mha/app1/manager manager_workdir=/var/log/mha/app1 master_binlog_dir=/mysql/binlog user=mha password=mysql ping_interval=2 repl_password=mysql repl_user=repl ssh_user=mysql [server1] hostname=192.168.12.131 port=3306 [server2] hostname=192.168.12.132 port=3306 [server3] hostname=192.168.12.133 port=3306
7.状态检查
检查互信: [root@node03 ~]$ masterha_check_ssh --conf=/etc/mha/app1.cnf Sat Jul 11 20:02:04 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping. Sat Jul 11 20:02:04 2020 - [info] Reading application default configuration from /etc/mha/app1.cnf.. Sat Jul 11 20:02:04 2020 - [info] Reading server configuration from /etc/mha/app1.cnf.. Sat Jul 11 20:02:04 2020 - [info] Starting SSH connection tests.. Sat Jul 11 20:02:05 2020 - [debug] Sat Jul 11 20:02:04 2020 - [debug] Connecting via SSH from root@192.168.12.131(192.168.12.131:22) to root@192.168.12.132(192.168.12.132:22).. Sat Jul 11 20:02:05 2020 - [debug] ok. Sat Jul 11 20:02:05 2020 - [debug] Connecting via SSH from root@192.168.12.131(192.168.12.131:22) to root@192.168.12.133(192.168.12.133:22).. Sat Jul 11 20:02:05 2020 - [debug] ok. Sat Jul 11 20:02:06 2020 - [debug] Sat Jul 11 20:02:05 2020 - [debug] Connecting via SSH from root@192.168.12.132(192.168.12.132:22) to root@192.168.12.131(192.168.12.131:22).. Sat Jul 11 20:02:05 2020 - [debug] ok. Sat Jul 11 20:02:05 2020 - [debug] Connecting via SSH from root@192.168.12.132(192.168.12.132:22) to root@192.168.12.133(192.168.12.133:22).. Sat Jul 11 20:02:06 2020 - [debug] ok. Sat Jul 11 20:02:07 2020 - [debug] Sat Jul 11 20:02:05 2020 - [debug] Connecting via SSH from root@192.168.12.133(192.168.12.133:22) to root@192.168.12.131(192.168.12.131:22).. Sat Jul 11 20:02:06 2020 - [debug] ok. Sat Jul 11 20:02:06 2020 - [debug] Connecting via SSH from root@192.168.12.133(192.168.12.133:22) to root@192.168.12.132(192.168.12.132:22).. Sat Jul 11 20:02:06 2020 - [debug] ok. Sat Jul 11 20:02:07 2020 - [info] All SSH connection tests passed successfully. 检查主从复制状态: [root@node03 ~]$ masterha_check_repl --conf=/etc/mha/app1.cnf Sat Jul 11 20:03:29 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping. Sat Jul 11 20:03:29 2020 - [info] Reading application default configuration from /etc/mha/app1.cnf.. Sat Jul 11 20:03:29 2020 - [info] Reading server configuration from /etc/mha/app1.cnf.. Sat Jul 11 20:03:29 2020 - [info] MHA::MasterMonitor version 0.58. Sat Jul 11 20:03:30 2020 - [info] GTID failover mode = 1 Sat Jul 11 20:03:30 2020 - [info] Dead Servers: Sat Jul 11 20:03:30 2020 - [info] Alive Servers: Sat Jul 11 20:03:30 2020 - [info] 192.168.12.131(192.168.12.131:3306) Sat Jul 11 20:03:30 2020 - [info] 192.168.12.132(192.168.12.132:3306) Sat Jul 11 20:03:30 2020 - [info] 192.168.12.133(192.168.12.133:3306) Sat Jul 11 20:03:30 2020 - [info] Alive Slaves: Sat Jul 11 20:03:30 2020 - [info] 192.168.12.132(192.168.12.132:3306) Version=5.7.29-log (oldest major version between slaves) log-bin:enabled Sat Jul 11 20:03:30 2020 - [info] GTID ON Sat Jul 11 20:03:30 2020 - [info] Replicating from 192.168.12.131(192.168.12.131:3306) Sat Jul 11 20:03:30 2020 - [info] 192.168.12.133(192.168.12.133:3306) Version=5.7.29-log (oldest major version between slaves) log-bin:enabled Sat Jul 11 20:03:30 2020 - [info] GTID ON Sat Jul 11 20:03:30 2020 - [info] Replicating from 192.168.12.131(192.168.12.131:3306) Sat Jul 11 20:03:30 2020 - [info] Current Alive Master: 192.168.12.131(192.168.12.131:3306) Sat Jul 11 20:03:30 2020 - [info] Checking slave configurations.. Sat Jul 11 20:03:30 2020 - [info] read_only=1 is not set on slave 192.168.12.132(192.168.12.132:3306). Sat Jul 11 20:03:30 2020 - [info] read_only=1 is not set on slave 192.168.12.133(192.168.12.133:3306). Sat Jul 11 20:03:30 2020 - [info] Checking replication filtering settings.. Sat Jul 11 20:03:30 2020 - [info] binlog_do_db= , binlog_ignore_db= Sat Jul 11 20:03:30 2020 - [info] Replication filtering check ok. Sat Jul 11 20:03:30 2020 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking. Sat Jul 11 20:03:30 2020 - [info] Checking SSH publickey authentication settings on the current master.. Sat Jul 11 20:03:31 2020 - [info] HealthCheck: SSH to 192.168.12.131 is reachable. Sat Jul 11 20:03:31 2020 - [info] 192.168.12.131(192.168.12.131:3306) (current master) +--192.168.12.132(192.168.12.132:3306) +--192.168.12.133(192.168.12.133:3306) Sat Jul 11 20:03:31 2020 - [info] Checking replication health on 192.168.12.132.. Sat Jul 11 20:03:31 2020 - [info] ok. Sat Jul 11 20:03:31 2020 - [info] Checking replication health on 192.168.12.133.. Sat Jul 11 20:03:31 2020 - [info] ok. Sat Jul 11 20:03:31 2020 - [warning] master_ip_failover_script is not defined. Sat Jul 11 20:03:31 2020 - [warning] shutdown_script is not defined. Sat Jul 11 20:03:31 2020 - [info] Got exit code 0 (Not master dead). MySQL Replication Health is OK.
8.开启MHA-manager
[root@node03 ~]#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 &
10.查看MHA状态
[root@node03 ~]# masterha_check_status --conf=/etc/mha/app1.cnf app1 (pid:1827) is running(0:PING_OK), master:192.168.12.131