一:环境配置
192.168.78.128(备库,只读), 192.168.78.129(主库),192.168.78.130(从库,master为128)
三台数据库可以SSH无密码登录
二:配置配置主从半同步
# 所有mysql数据库服务器,安装半同步插件(semisync_master.so,semisync_slave.so)
mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';
mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so'; mysql> show variables like '%sync%';
# 查看半同步状态:
mysql> show status like '%sync%';
# 有几个状态参数值得关注的:
rpl_semi_sync_master_status:显示主服务是异步复制模式还是半同步复制模式
rpl_semi_sync_master_clients:显示有多少个从服务器配置为半同步复制模式
rpl_semi_sync_master_yes_tx:显示从服务器确认成功提交的数量
rpl_semi_sync_master_no_tx:显示从服务器确认不成功提交的数量
rpl_semi_sync_master_tx_avg_wait_time:事务因开启semi_sync,平均需要额外等待的时间
rpl_semi_sync_master_net_avg_wait_time:事务进入等待队列后,到网络平均等待时间
一般主从半同步需要修改配置文件,然后重启。最初安装如果用的是标配配置文件,通过set开启就可以了。
三:安装MHA
三台机器上都要做配置epel源
[root@M128 ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
安装所需要的包
[root@M128 ~]# yum -y install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-Config-IniFiles ncftp perl-Params-Validate perl-CPAN perl-Test-Mock-LWP.noarch perl-LWP-Authen-Negotiate.noarch perl-devel
[root@M128 ~]# yum -y install perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker 这个百度文档没有但是显然是要装的(***)
以下操作管理节点需要两个都安装,在3台数据库节点只要安装MHA的node节点:
1 # 如果安装下面包,报依赖关系错,请先安装mysql-share-compat包
2 # 先安装下面的 perl-dbd-mysql包
3 # 在下面执行perl时,如果出现报错,需要安装如下这几个perl包: perl-devel perl-CPAN
tar -zxf mha4mysql-node-0.53.tar.gz
cd mha4mysql-node-0.53
perl Makefile.PL
make && make install
管理节点还需要安装manger
tar -zxf mha4mysql-manager-0.53.tar.gz
cd mha4mysql-manager-0.53
perl Makefile.PL
make && make install
修改MHA的配置文件
mkdir /etc/masterha
mkdir -p /master/app1
mkdir -p /scripts
cp samples/conf/* /etc/masterha/
cp samples/scripts/* /scripts
cp samples/conf/* /etc/masterha/
vi /etc/masterha/app1.cnf
[server default]
manager_workdir=/var/log/masterha/app1
manager_log=/var/log/masterha/app1/manager.log
[server default]
manager_workdir=/masterha/app1
manager_log=/masterha/app1/manager.log
user=root
#mha管理用的账号(及时换行,不要有空格,否则会抱ssh的错误)
password=123456
ssh_user=root
#ssh的账号
repl_user=repl
#主从同步复制的账号
repl_password=repl
ping_interval=1
shutdown_script=""
master_ip_online_change_script=""
report_script=""
[server1]
hostname=192.168.78.128
master_binlog_dir=/usr/local/mysql/data
candidate_master=1
[server2]
hostname=192.168.78.129
master_binlog_dir=/usr/local/mysql/data
#candidate_master=1
[server3]
hostname=192.168.78.130
master_binlog_dir=/usr/local/mysql/data
no_master=1
masterha_default.cnf 文件置空
echo > masterha_default.cnf
四:测试配置
测试SSH可以无密码登录
~
[root@M128 masterha]# masterha_check_ssh --global_conf=/etc/masterha/masterha_default.cnf --conf=/etc/masterha/app1.cnf
Tue Oct 27 20:47:50 2015 - [info] Reading default configuratoins from /etc/masterha/masterha_default.cnf..
Tue Oct 27 20:47:50 2015 - [info] Reading application default configurations from /etc/masterha/app1.cnf..
Tue Oct 27 20:47:50 2015 - [info] Reading server configurations from /etc/masterha/app1.cnf..
Tue Oct 27 20:47:50 2015 - [info] Starting SSH connection tests..
Tue Oct 27 20:47:50 2015 - [debug]
Tue Oct 27 20:47:50 2015 - [debug] Connecting via SSH from [email protected](192.168.78.128:22) to [email protected](192.168.78.129:22)..
Tue Oct 27 20:47:50 2015 - [debug] ok.
Tue Oct 27 20:47:50 2015 - [debug] Connecting via SSH from [email protected](192.168.78.128:22) to [email protected](192.168.78.130:22)..
Tue Oct 27 20:47:50 2015 - [debug] ok.
Tue Oct 27 20:47:51 2015 - [debug]
Tue Oct 27 20:47:50 2015 - [debug] Connecting via SSH from [email protected](192.168.78.129:22) to [email protected](192.168.78.128:22)..
Tue Oct 27 20:47:50 2015 - [debug] ok.
Tue Oct 27 20:47:50 2015 - [debug] Connecting via SSH from [email protected](192.168.78.129:22) to [email protected](192.168.78.130:22)..
Tue Oct 27 20:47:51 2015 - [debug] ok.
Tue Oct 27 20:47:51 2015 - [debug]
Tue Oct 27 20:47:51 2015 - [debug] Connecting via SSH from [email protected](192.168.78.130:22) to [email protected](192.168.78.128:22)..
Tue Oct 27 20:47:51 2015 - [debug] ok.
Tue Oct 27 20:47:51 2015 - [debug] Connecting via SSH from [email protected](192.168.78.130:22) to [email protected](192.168.78.129:22)..
Tue Oct 27 20:47:51 2015 - [debug] ok.
Tue Oct 27 20:47:51 2015 - [info] All SSH connection tests passed successfully.
如果报错,清空 ~/.ssh内的文件,重新配置无密码登录
测试MHA
[root@M128 masterha]# masterha_check_repl --conf=/etc/masterha/app1.cnf
Tue Oct 27 20:50:24 2015 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Tue Oct 27 20:50:24 2015 - [info] Reading application default configurations from /etc/masterha/app1.cnf..
Tue Oct 27 20:50:24 2015 - [info] Reading server configurations from /etc/masterha/app1.cnf..
Tue Oct 27 20:50:24 2015 - [info] MHA::MasterMonitor version 0.53.
Tue Oct 27 20:50:25 2015 - [info] Multi-master configuration is detected. Current primary(writable) master is 192.168.78.128(192.168.78.128:3306)
Tue Oct 27 20:50:25 2015 - [info] Master configurations are as below:
Master 192.168.78.128(192.168.78.128:3306), replicating from 192.168.78.129(192.168.78.129:3306)
Master 192.168.78.129(192.168.78.129:3306), replicating from 192.168.78.128(192.168.78.128:3306), read-only
Tue Oct 27 20:50:25 2015 - [info] Dead Servers:
Tue Oct 27 20:50:25 2015 - [info] Alive Servers:
Tue Oct 27 20:50:25 2015 - [info] 192.168.78.128(192.168.78.128:3306)
Tue Oct 27 20:50:25 2015 - [info] 192.168.78.129(192.168.78.129:3306)
Tue Oct 27 20:50:25 2015 - [info] 192.168.78.130(192.168.78.130:3306)
Tue Oct 27 20:50:25 2015 - [info] Alive Slaves:
Tue Oct 27 20:50:25 2015 - [info] 192.168.78.129(192.168.78.129:3306) Version=5.6.25-log (oldest major version between slaves) log-bin:enabled
Tue Oct 27 20:50:25 2015 - [info] Replicating from 192.168.78.128(192.168.78.128:3306)
Tue Oct 27 20:50:25 2015 - [info] 192.168.78.130(192.168.78.130:3306) Version=5.6.25-log (oldest major version between slaves) log-bin:enabled
Tue Oct 27 20:50:25 2015 - [info] Replicating from 192.168.78.128(192.168.78.128:3306)
Tue Oct 27 20:50:25 2015 - [info] Not candidate for the new Master (no_master is set)
Tue Oct 27 20:50:25 2015 - [info] Current Alive Master: 192.168.78.128(192.168.78.128:3306)
Tue Oct 27 20:50:25 2015 - [info] Checking slave configurations..
Tue Oct 27 20:50:25 2015 - [info] read_only=1 is not set on slave 192.168.78.130(192.168.78.130:3306).
Tue Oct 27 20:50:25 2015 - [info] Checking replication filtering settings..
Tue Oct 27 20:50:25 2015 - [info] binlog_do_db= , binlog_ignore_db=
Tue Oct 27 20:50:25 2015 - [info] Replication filtering check ok.
Tue Oct 27 20:50:25 2015 - [info] Starting SSH connection tests..
Tue Oct 27 20:50:26 2015 - [info] All SSH connection tests passed successfully.
Tue Oct 27 20:50:26 2015 - [info] Checking MHA Node version..
Tue Oct 27 20:50:26 2015 - [info] Version check ok.
Tue Oct 27 20:50:26 2015 - [info] Checking SSH publickey authentication settings on the current master..
Tue Oct 27 20:50:27 2015 - [info] HealthCheck: SSH to 192.168.78.128 is reachable.
Tue Oct 27 20:50:27 2015 - [info] Master MHA Node version is 0.53.
Tue Oct 27 20:50:27 2015 - [info] Checking recovery script configurations on the current master..
Tue Oct 27 20:50:27 2015 - [info] Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/usr/local/mysql/data --output_file=/var/tmp/save_binary_logs_test --manager_version=0.53 --start_file=mysql-bin.000008
Tue Oct 27 20:50:27 2015 - [info] Connecting to [email protected](192.168.78.128)..
Creating /var/tmp if not exists.. ok.
Checking output directory is accessible or not..
ok.
Binlog found at /usr/local/mysql/data, up to mysql-bin.000008
Tue Oct 27 20:50:27 2015 - [info] Master setting check done.
Tue Oct 27 20:50:27 2015 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
Tue Oct 27 20:50:27 2015 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user=root --slave_host=192.168.78.129 --slave_ip=192.168.78.129 --slave_port=3306 --workdir=/var/tmp --target_version=5.6.25-log --manager_version=0.53 --relay_log_info=/usr/local/mysql/data/relay-log.info --relay_dir=/usr/local/mysql/data/ --slave_pass=xxx
Tue Oct 27 20:50:27 2015 - [info] Connecting to [email protected](192.168.78.129:22)..
Checking slave recovery environment settings..
Opening /usr/local/mysql/data/relay-log.info ... ok.
Relay log found at /usr/local/mysql/data, up to M129-relay-bin.000002
Temporary relay log file is /usr/local/mysql/data/M129-relay-bin.000002
Testing mysql connection and privileges..Warning: Using a password on the command line interface can be insecure.
done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s).. done.
Tue Oct 27 20:50:27 2015 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user=root --slave_host=192.168.78.130 --slave_ip=192.168.78.130 --slave_port=3306 --workdir=/var/tmp --target_version=5.6.25-log --manager_version=0.53 --relay_log_info=/usr/local/mysql/data/relay-log.info --relay_dir=/usr/local/mysql/data/ --slave_pass=xxx
Tue Oct 27 20:50:27 2015 - [info] Connecting to [email protected](192.168.78.130:22)..
Checking slave recovery environment settings..
Opening /usr/local/mysql/data/relay-log.info ... ok.
Relay log found at /usr/local/mysql/data, up to M130-relay-bin.000003
Temporary relay log file is /usr/local/mysql/data/M130-relay-bin.000003
Testing mysql connection and privileges..Warning: Using a password on the command line interface can be insecure.
done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s).. done.
Tue Oct 27 20:50:28 2015 - [info] Slaves settings check done.
Tue Oct 27 20:50:28 2015 - [info]
192.168.78.128 (current master)
+--192.168.78.129
+--192.168.78.130
Tue Oct 27 20:50:28 2015 - [info] Checking replication health on 192.168.78.129..
Tue Oct 27 20:50:28 2015 - [info] ok.
Tue Oct 27 20:50:28 2015 - [info] Checking replication health on 192.168.78.130..
Tue Oct 27 20:50:28 2015 - [info] ok.
Tue Oct 27 20:50:28 2015 - [warning] master_ip_failover_script is not defined.
Tue Oct 27 20:50:28 2015 - [warning] shutdown_script is not defined.
Tue Oct 27 20:50:28 2015 - [info] Got exit code 0 (Not master dead).
MySQL Replication Health is OK.
如果报错,按照报错信息修改用户权限,主从同步等。
至此说明你的MHA 已经配置好了
四:启动MHA