这里以在Linux上个演示。
这里在SSH免密码登录的前提上个进行设置的。
如何设置免密登录,请看前一篇博文,或者搜索下,在此不再给出链接。
同样的3台主机
名称 | ip |
Centos 7 MySQL Master | 192.168.79.134 |
Centos 7 MySQL Slave | 192.168.79.136 |
Centos 7 MySQL Manager | 192.168.79.137 |
三台主机全部安装依赖:
yum install perl-DBD-MySQL
yum install perl-DBI
yum install mysql-libs
get http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -ivh epel-release-latest-7.noarch.rpm
yum install -y perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager
然后在Manager上个,也就是192.168.79.137的机器上个安装控制端:
wget https://qiniu.wsfnk.com/mha4mysql-manager-0.58-0.el7.centos.noarch.rpm
rpm -ivh mha4mysql-manager-0.58-0.el7.centos.noarch.rpm
随后在Manager机器上个添加如下文件/etc/app1.cnf
[server default]
manager_workdir=/var/log/mha/app1
manager_log=/var/log/mha/app1/manager.log
user=root
password=root
ssh_user=root
repl_user=rep1
repl_password=rep1
ping_interval=1
[server1]
hostname=192.168.79.134
port=3306
master_binlog_dir=/u01/mysql3306/log/binlog
candidate_master=1
check_repl_delay=0
[server2]
hostname=192.168.79.136
port=3306
master_binlog_dir=/u01/mysql3306/log/binlog
candidate_master=1
check_repl_delay=0
这里改创建新路径要创建,master_binlog_dir需要改的就要改。
扫描二维码关注公众号,回复:
11348626 查看本文章
下面是一些常用命令:
masterha_check_ssh --conf=/etc/app1.cnf
masterha_check_repl --conf=/etc/app1.cnf
masterha_manager --conf=/etc/app1.cnf
masterha_check_status --conf=/etc/app1.cnf
masterha_stop --conf=/etc/app1.cnf
如下测试条命令:
[root@localhost ~]# masterha_check_ssh --conf=/etc/app1.cnf
Sat Jun 6 14:03:39 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Sat Jun 6 14:03:39 2020 - [info] Reading application default configuration from /etc/app1.cnf..
Sat Jun 6 14:03:39 2020 - [info] Reading server configuration from /etc/app1.cnf..
Sat Jun 6 14:03:39 2020 - [info] Starting SSH connection tests..
Sat Jun 6 14:03:39 2020 - [debug]
Sat Jun 6 14:03:39 2020 - [debug] Connecting via SSH from [email protected](192.168.79.134:22) to [email protected](192.168.79.136:22)..
Sat Jun 6 14:03:39 2020 - [debug] ok.
Sat Jun 6 14:03:40 2020 - [debug]
Sat Jun 6 14:03:39 2020 - [debug] Connecting via SSH from [email protected](192.168.79.136:22) to [email protected](192.168.79.134:22)..
Sat Jun 6 14:03:39 2020 - [debug] ok.
Sat Jun 6 14:03:40 2020 - [info] All SSH connection tests passed successfully.
第二个:
[root@localhost ~]# masterha_check_repl --conf=/etc/app1.cnf
Sat Jun 6 16:36:33 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Sat Jun 6 16:36:33 2020 - [info] Reading application default configuration from /etc/app1.cnf..
Sat Jun 6 16:36:33 2020 - [info] Reading server configuration from /etc/app1.cnf..
Sat Jun 6 16:36:33 2020 - [info] MHA::MasterMonitor version 0.58.
Sat Jun 6 16:36:34 2020 - [info] GTID failover mode = 0
Sat Jun 6 16:36:34 2020 - [info] Dead Servers:
Sat Jun 6 16:36:34 2020 - [info] Alive Servers:
Sat Jun 6 16:36:34 2020 - [info] mydb1(192.168.79.134:3306)
Sat Jun 6 16:36:34 2020 - [info] mydb2(192.168.79.136:3306)
Sat Jun 6 16:36:34 2020 - [info] Alive Slaves:
Sat Jun 6 16:36:34 2020 - [info] mydb2(192.168.79.136:3306) Version=5.7.25-log (oldest major version between slaves) log-bin:enabled
Sat Jun 6 16:36:34 2020 - [info] Replicating from 192.168.79.134(192.168.79.134:3306)
Sat Jun 6 16:36:34 2020 - [info] Primary candidate for the new Master (candidate_master is set)
Sat Jun 6 16:36:34 2020 - [info] Current Alive Master: mydb1(192.168.79.134:3306)
Sat Jun 6 16:36:34 2020 - [info] Checking slave configurations..
Sat Jun 6 16:36:34 2020 - [info] read_only=1 is not set on slave mydb2(192.168.79.136:3306).
Sat Jun 6 16:36:34 2020 - [warning] relay_log_purge=0 is not set on slave mydb2(192.168.79.136:3306).
Sat Jun 6 16:36:34 2020 - [info] Checking replication filtering settings..
Sat Jun 6 16:36:34 2020 - [info] binlog_do_db= , binlog_ignore_db=
Sat Jun 6 16:36:34 2020 - [info] Replication filtering check ok.
Sat Jun 6 16:36:34 2020 - [info] GTID (with auto-pos) is not supported
Sat Jun 6 16:36:34 2020 - [info] Starting SSH connection tests..
Sat Jun 6 16:36:35 2020 - [info] All SSH connection tests passed successfully.
Sat Jun 6 16:36:35 2020 - [info] Checking MHA Node version..
Sat Jun 6 16:36:35 2020 - [info] Version check ok.
Sat Jun 6 16:36:35 2020 - [info] Checking SSH publickey authentication settings on the current master..
Sat Jun 6 16:36:35 2020 - [info] HealthCheck: SSH to mydb1 is reachable.
Sat Jun 6 16:36:36 2020 - [info] Master MHA Node version is 0.58.
Sat Jun 6 16:36:36 2020 - [info] Checking recovery script configurations on mydb1(192.168.79.134:3306)..
Sat Jun 6 16:36:36 2020 - [info] Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/u01/mysql3306/log/binlog --output_file=/var/tmp/save_binary_logs_test --manager_version=0.58 --start_file=binlog.000054
Sat Jun 6 16:36:36 2020 - [info] Connecting to [email protected](mydb1:22)..
Creating /var/tmp if not exists.. ok.
Checking output directory is accessible or not..
ok.
Binlog found at /u01/mysql3306/log/binlog, up to binlog.000054
Sat Jun 6 16:36:36 2020 - [info] Binlog setting check done.
Sat Jun 6 16:36:36 2020 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
Sat Jun 6 16:36:36 2020 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=mydb2 --slave_ip=192.168.79.136 --slave_port=3306 --workdir=/var/tmp --target_version=5.7.25-log --manager_version=0.58 --relay_log_info=/u01/mysql3306/log/relay-log.info --relay_dir=/u01/mysql3306/data/ --slave_pass=xxx
Sat Jun 6 16:36:36 2020 - [info] Connecting to [email protected](mydb2:22)..
Checking slave recovery environment settings..
Opening /u01/mysql3306/log/relay-log.info ... ok.
Relay log found at /u01/mysql3306/log, up to relaylog.000002
Temporary relay log file is /u01/mysql3306/log/relaylog.000002
Checking if super_read_only is defined and turned on.. not present or turned off, ignoring.
Testing mysql connection and privileges..
mysql: [Warning] Using a password on the command line interface can be insecure.
done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s).. done.
Sat Jun 6 16:36:36 2020 - [info] Slaves settings check done.
Sat Jun 6 16:36:36 2020 - [info]
mydb1(192.168.79.134:3306) (current master)
+--mydb2(192.168.79.136:3306)
Sat Jun 6 16:36:36 2020 - [info] Checking replication health on mydb2..
Sat Jun 6 16:36:36 2020 - [info] ok.
Sat Jun 6 16:36:36 2020 - [warning] master_ip_failover_script is not defined.
Sat Jun 6 16:36:36 2020 - [warning] shutdown_script is not defined.
Sat Jun 6 16:36:36 2020 - [info] Got exit code 0 (Not master dead).
MySQL Replication Health is OK.
[root@localhost ~]#