一:環境配置
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