系统:centos
[root@c7-mysql-5 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
数据库:
mysql> select version();
+------------+
| version() |
+------------+
| 5.7.17-log |
+------------+
1 row in set (0.00 sec)
部署MHA步骤:
1 主从复制配置
2 MHA安装
2.1 免验证登录ssh
2.2 安装
部署node(所有节点)
yum install -y epel-release
yum install -y perl-DBD-MySQL.x86_64 perl-DBI.x86_64 ncftp.x86_64
部署manager
yum install -y epel-release
yum install -y perl-Config-Tiny.noarch perl-Time-HiRes.x86_64 perl-Parallel-ForkManager.noarch
perl-Log-Dispatch perl-DBD-MySQL.x86_64 ncftp.x86_64
所有节点创建mha用户
create user 'mha'@'192.168.40.%' identified by '123456';
grant all privileges on *.* to 'mha'@'192.168.40.%';
所有节点创建
mkdir -p /home/mysql_mha
将/usr/bin/master_ip_failover 复制到manager的/usr/bin
配置manager
[root@c7-mysql-5 mha]# pwd
/etc/mha
[root@c7-mysql-5 mha]# cat mysql_mha.cnf
[server default]
user=mha
password=123456
manager_workdir=/home/mysql_mha
manager_log=/home/mysql_mha/manager.log
remote_workdir=/home/mysql_mha
ssh_user=root
repl_user=repl
repl_password=123456
ping_interval=1
master_binlog_dir=/usr/local/mysql/data
master_ip_failover_script=/usr/bin/master_ip_failover
secondary_check_script=/usr/bin/masterha_secondary_check -s 192.168.40.10 -s 192.168.40.11 -s 192.168.40.12
[server1]
hostname=192.168.40.10
candidate_master=1
[server2]
hostname=192.168.40.11
candidate_master=1
[server3]
hostname=192.168.40.12
no_master=1
[root@c7-mysql-5 bin]# masterha_check_repl --conf=/etc/mha/mysql_mha.cnf
Thu Jul 26 22:19:27 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu Jul 26 22:19:27 2018 - [info] Reading application default configuration from /etc/mha/mysql_mha.cnf..
Thu Jul 26 22:19:27 2018 - [info] Reading server configuration from /etc/mha/mysql_mha.cnf..
Thu Jul 26 22:19:27 2018 - [info] MHA::MasterMonitor version 0.57.
Thu Jul 26 22:19:28 2018 - [info] GTID failover mode = 1
Thu Jul 26 22:19:28 2018 - [info] Dead Servers:
Thu Jul 26 22:19:28 2018 - [info] 192.168.40.11(192.168.40.11:3306)
Thu Jul 26 22:19:28 2018 - [info] Alive Servers:
Thu Jul 26 22:19:28 2018 - [info] 192.168.40.10(192.168.40.10:3306)
Thu Jul 26 22:19:28 2018 - [info] 192.168.40.12(192.168.40.12:3306)
Thu Jul 26 22:19:28 2018 - [info] Alive Slaves:
Thu Jul 26 22:19:28 2018 - [info] 192.168.40.12(192.168.40.12:3306) Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Thu Jul 26 22:19:28 2018 - [info] GTID ON
Thu Jul 26 22:19:28 2018 - [info] Replicating from 192.168.40.10(192.168.40.10:3306)
Thu Jul 26 22:19:28 2018 - [info] Not candidate for the new Master (no_master is set)
Thu Jul 26 22:19:28 2018 - [info] Current Alive Master: 192.168.40.10(192.168.40.10:3306)
Thu Jul 26 22:19:28 2018 - [info] Checking slave configurations..
Thu Jul 26 22:19:28 2018 - [info] read_only=1 is not set on slave 192.168.40.12(192.168.40.12:3306).
Thu Jul 26 22:19:28 2018 - [info] Checking replication filtering settings..
Thu Jul 26 22:19:28 2018 - [info] binlog_do_db= , binlog_ignore_db=
Thu Jul 26 22:19:28 2018 - [info] Replication filtering check ok.
Thu Jul 26 22:19:28 2018 - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln364] None of slaves can be master. Check failover configuration file or log-bin settings in my.cnf
Thu Jul 26 22:19:28 2018 - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln427] Error happened on checking configurations. at /usr/bin/masterha_check_repl line 48.
Thu Jul 26 22:19:28 2018 - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln525] Error happened on monitoring servers.
Thu Jul 26 22:19:28 2018 - [info] Got exit code 1 (Not master dead).
MySQL Replication Health is NOT OK!