mysql MHA搭建和切換測試
一、mysql MHA介紹和測試環境
參考
伺服器環境:
192.168.133.108/109/241/242
192.168.133.242 計劃安裝MHA manager mysql 5.1
192.168.133.108/109/241 MHA Node mysql 5.5
二、安裝MHA Node
需要在所有伺服器上安裝NODE:192.168.133.108/109/241/242
1)在個Node上安裝perl-DBI以及相容性libmysqlclient.so共享物件庫以及perl-DBD依賴包
[root@cs-ora perl-rpm]# rpm -ivh perl-DBD-MySQL-4.014-1.el5.rfx.x86_64.rpm
warning: perl-DBD-MySQL-4.014-1.el5.rfx.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
error: Failed dependencies:
libmysqlclient.so.15()(64bit) is needed by perl-DBD-MySQL-4.014-1.el5.rfx.x86_64
libmysqlclient.so.15(libmysqlclient_15)(64bit) is needed by perl-DBD-MySQL-4.014-1.el5.rfx.x86_64
perl(DBI) is needed by perl-DBD-MySQL-4.014-1.el5.rfx.x86_64
perl(DBI) >= 1.08 is needed by perl-DBD-MySQL-4.014-1.el5.rfx.x86_64
perl(DBI::Const::GetInfoType) is needed by perl-DBD-MySQL-4.014-1.el5.rfx.x86_64
從 網站下載相應的
MySQL-shared-compat-5.5.24-1.rhel5.x86_64.rpm
perl-DBI-1.620-1.el5.rfx.x86_64.rpm
並安裝:
[root@cs-ora perl-rpm]# rpm -ivh MySQL-shared-compat-5.5.24-1.rhel5.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-shared-compat ########################################### [100%]
[root@cs-ora perl-rpm]# rpm -ivh perl-DBI-1.620-1.el5.rfx.x86_64.rpm
warning: perl-DBI-1.620-1.el5.rfx.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
Preparing... ########################################### [100%]
1:perl-DBI ########################################### [100%]
[root@cs-ora perl-rpm]# rpm -ivh perl-DBD-MySQL-4.014-1.el5.rfx.x86_64.rpm
warning: perl-DBD-MySQL-4.014-1.el5.rfx.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
Preparing... ########################################### [100%]
1:perl-DBD-MySQL ########################################### [100%]
如果沒有安裝mysql則報如下錯誤:
warning: perl-DBD-MySQL-4.014-1.el5.rfx.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
error: Failed dependencies:
mysql is needed by perl-DBD-MySQL-4.014-1.el5.rfx.x86_64
解決:
A:確定主機上沒有安裝mysql,則安裝mysql server
B:如果已經安裝mysql 並正在運營,報改錯誤,則只要在/root/.bash_profile中增加訪問路徑:
sed -i '/^PATH/s#$#:/usr/local/mysql/bin#' /root/.bash_profile
2)MHA node安裝
[root@cs-ora perl-rpm]# tar -xzvf mha4mysql-node-0.53.tar.gz
mha4mysql-node-0.53/
[root@cs-ora perl-rpm]# cd mha4mysql-node-0.53
[root@cs-ora mha4mysql-node-0.53]# perl Makefile.PL
*** Module::AutoInstall version 1.03
*** Checking for Perl dependencies...
......
commit: wrote /usr/lib/perl5/5.8.8/CPAN/Config.pm
[Core Features]
- DBI ...loaded. (1.620)
- DBD::mysql ...loaded. (4.014)
*** Module::AutoInstall configuration finished.
Checking if your kit is complete...
Looks good
Warning: prerequisite ExtUtils::MakeMaker 6.42 not found. We have 6.30.
Writing Makefile for mha4mysql::node
[root@cs-ora mha4mysql-node-0.53]# make
cp lib/MHA/BinlogPosFinderElp.pm blib/lib/MHA/BinlogPosFinderElp.pm
cp lib/MHA/NodeUtil.pm blib/lib/MHA/NodeUtil.pm
cp lib/MHA/BinlogManager.pm blib/lib/MHA/BinlogManager.pm
cp lib/MHA/SlaveUtil.pm blib/lib/MHA/SlaveUtil.pm
cp lib/MHA/NodeConst.pm blib/lib/MHA/NodeConst.pm
cp lib/MHA/BinlogPosFindManager.pm blib/lib/MHA/BinlogPosFindManager.pm
cp lib/MHA/BinlogPosFinderXid.pm blib/lib/MHA/BinlogPosFinderXid.pm
cp lib/MHA/BinlogHeaderParser.pm blib/lib/MHA/BinlogHeaderParser.pm
cp lib/MHA/BinlogPosFinder.pm blib/lib/MHA/BinlogPosFinder.pm
cp bin/filter_mysqlbinlog blib/script/filter_mysqlbinlog
/usr/bin/perl "-Iinc" "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/filter_mysqlbinlog
cp bin/apply_diff_relay_logs blib/script/apply_diff_relay_logs
/usr/bin/perl "-Iinc" "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/apply_diff_relay_logs
cp bin/purge_relay_logs blib/script/purge_relay_logs
/usr/bin/perl "-Iinc" "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/purge_relay_logs
cp bin/save_binary_logs blib/script/save_binary_logs
/usr/bin/perl "-Iinc" "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/save_binary_logs
Manifying blib/man1/filter_mysqlbinlog.1
Manifying blib/man1/apply_diff_relay_logs.1
Manifying blib/man1/purge_relay_logs.1
Manifying blib/man1/save_binary_logs.1
[root@cs-ora mha4mysql-node-0.53]# make install
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/BinlogPosFinderXid.pm
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/BinlogHeaderParser.pm
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/NodeUtil.pm
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/NodeConst.pm
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/BinlogPosFindManager.pm
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/SlaveUtil.pm
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/BinlogManager.pm
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/BinlogPosFinder.pm
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/BinlogPosFinderElp.pm
Installing /usr/share/man/man1/save_binary_logs.1
Installing /usr/share/man/man1/filter_mysqlbinlog.1
Installing /usr/share/man/man1/apply_diff_relay_logs.1
Installing /usr/share/man/man1/purge_relay_logs.1
Installing /usr/bin/purge_relay_logs
Installing /usr/bin/filter_mysqlbinlog
Installing /usr/bin/save_binary_logs
Installing /usr/bin/apply_diff_relay_logs
Writing /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/mha4mysql/node/.packlist
Appending installation info to /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/perllocal.pod
三、MHA manager安裝
在Manager server上安裝:192.168.133.242
1)安裝依賴包
[root@racdb perl-rpm]# rpm -ivh perl-Config-Tiny-2.12-1.el5.rf.noarch.rpm
warning: perl-Config-Tiny-2.12-1.el5.rf.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
Preparing... ########################################### [100%]
1:perl-Config-Tiny ########################################### [100%]
[root@racdb perl-rpm]# rpm -ivh perl-Log-Dispatch-2.28-1.el5.pp.noarch.rpm
warning: perl-Log-Dispatch-2.28-1.el5.pp.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 6971f6ac
error: Failed dependencies:
perl(MIME::Lite) is needed by perl-Log-Dispatch-2.28-1.el5.pp.noarch
perl(Mail::Send) is needed by perl-Log-Dispatch-2.28-1.el5.pp.noarch
perl(Mail::Sender) is needed by perl-Log-Dispatch-2.28-1.el5.pp.noarch
perl(Mail::Sendmail) is needed by perl-Log-Dispatch-2.28-1.el5.pp.noarch
perl(Params::Validate) is needed by perl-Log-Dispatch-2.28-1.el5.pp.noarch
perl(Sys::Syslog) >= 0.16 is needed by perl-Log-Dispatch-2.28-1.el5.pp.noarch
perl(Sys::Syslog) >= 0.25 is needed by perl-Log-Dispatch-2.28-1.el5.pp.noarch
解決下載相關的rpm包或相容包:
[root@racdb perl-rpm]# rpm -ivh perl-Mail-Sendmail-0.79-9.el5.1.noarch.rpm
warning: perl-Mail-Sendmail-0.79-9.el5.1.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 217521f6
Preparing... ########################################### [100%]
1:perl-Mail-Sendmail ########################################### [100%]
[root@racdb perl-rpm]# rpm -ivh perl-Mail-Sender-0.8.16-1.el5.rf.noarch.rpm
warning: perl-Mail-Sender-0.8.16-1.el5.rf.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
Preparing... ########################################### [100%]
1:perl-Mail-Sender ########################################### [100%]
[root@racdb perl-rpm]# rpm -ivh perl-Sys-Syslog-0.29-1.el5.pp.x86_64.rpm
warning: perl-Sys-Syslog-0.29-1.el5.pp.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 6971f6ac
Preparing... ########################################### [100%]
1:perl-Sys-Syslog ########################################### [100%]
[root@racdb perl-rpm]# rpm -ivh perl-Params-Validate-1.00-1.el5.pp.x86_64.rpm
warning: perl-Params-Validate-1.00-1.el5.pp.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 6971f6ac
Preparing... ########################################### [100%]
1:perl-Params-Validate ########################################### [100%]
[root@racdb perl-rpm]# rpm -ivh perl-Pod-Escapes-1.04-5.el5.noarch.rpm
warning: perl-Pod-Escapes-1.04-5.el5.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 217521f6
Preparing... ########################################### [100%]
1:perl-Pod-Escapes ########################################### [100%]
[root@racdb perl-rpm]# rpm -ivh perl-Pod-Simple-3.19-1.el5.pp.noarch.rpm
warning: perl-Pod-Simple-3.19-1.el5.pp.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 6971f6ac
Preparing... ########################################### [100%]
1:perl-Pod-Simple ########################################### [100%]
[root@racdb perl-rpm]# rpm -ivh perl-Test-Pod-1.45-1.el5.rf.noarch.rpm
warning: perl-Test-Pod-1.45-1.el5.rf.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
Preparing... ########################################### [100%]
1:perl-Test-Pod ########################################### [100%]
[root@racdb perl-rpm]# rpm -ivh perl-TimeDate-1.20-1.el5.rfx.noarch.rpm
warning: perl-TimeDate-1.20-1.el5.rfx.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
Preparing... ########################################### [100%]
1:perl-TimeDate ########################################### [100%]
[root@racdb perl-rpm]# rpm -ivh perl-Email-Date-Format-1.002-4.el5.noarch.rpm
warning: perl-Email-Date-Format-1.002-4.el5.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 217521f6
Preparing... ########################################### [100%]
1:perl-Email-Date-Format ########################################### [100%]
[root@racdb perl-rpm]# rpm -ivh perl-Parallel-ForkManager-0.7.5-4.el5.noarch.rpm
warning: perl-Parallel-ForkManager-0.7.5-4.el5.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 217521f6
Preparing... ########################################### [100%]
1:perl-Parallel-ForkManag########################################### [100%]
[root@racdb perl-rpm]# rpm -ivh perl-MIME-Lite-3.028-1.el5.rf.noarch.rpm
warning: perl-MIME-Lite-3.028-1.el5.rf.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
Preparing... ########################################### [100%]
1:perl-MIME-Lite ########################################### [100%]
[root@racdb perl-rpm]# rpm -ivh perl-MailTools-2.09-1.el5.rf.noarch.rpm
warning: perl-MailTools-2.09-1.el5.rf.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
Preparing... ########################################### [100%]
1:perl-MailTools ########################################### [100%]
[root@racdb perl-rpm]# rpm -ivh perl-Log-Dispatch-2.28-1.el5.pp.noarch.rpm
warning: perl-Log-Dispatch-2.28-1.el5.pp.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 6971f6ac
Preparing... ########################################### [100%]
1:perl-Log-Dispatch ########################################### [100%]
perl-Config-IniFiles
2)安裝MHA manager
[root@racdb perl-rpm]# tar -xzvf mha4mysql-manager-0.53.tar.gz
[root@racdb perl-rpm]# cd mha4mysql-manager-0.53
[root@racdb mha4mysql-manager-0.53]# perl Makefile.PL
*** Module::AutoInstall version 1.03
*** Checking for Perl dependencies...
[Core Features]
- DBI ...loaded. (1.620)
- DBD::mysql ...loaded. (4.014)
- Time::HiRes ...loaded. (1.9717)
- Config::Tiny ...loaded. (2.12)
- Log::Dispatch ...loaded. (2.28)
- Parallel::ForkManager ...loaded. (0.7.5)
- MHA::NodeConst ...loaded. (0.53)
*** Module::AutoInstall configuration finished.
Checking if your kit is complete...
Looks good
Warning: prerequisite ExtUtils::MakeMaker 6.42 not found. We have 6.30.
Writing Makefile for mha4mysql::manager
[root@racdb mha4mysql-manager-0.53]# make
cp lib/MHA/ManagerUtil.pm blib/lib/MHA/ManagerUtil.pm
cp lib/MHA/Config.pm blib/lib/MHA/Config.pm
cp lib/MHA/HealthCheck.pm blib/lib/MHA/HealthCheck.pm
cp lib/MHA/ManagerConst.pm blib/lib/MHA/ManagerConst.pm
cp lib/MHA/ServerManager.pm blib/lib/MHA/ServerManager.pm
cp lib/MHA/FileStatus.pm blib/lib/MHA/FileStatus.pm
cp lib/MHA/ManagerAdmin.pm blib/lib/MHA/ManagerAdmin.pm
cp lib/MHA/ManagerAdminWrapper.pm blib/lib/MHA/ManagerAdminWrapper.pm
cp lib/MHA/MasterFailover.pm blib/lib/MHA/MasterFailover.pm
cp lib/MHA/MasterRotate.pm blib/lib/MHA/MasterRotate.pm
cp lib/MHA/MasterMonitor.pm blib/lib/MHA/MasterMonitor.pm
cp lib/MHA/Server.pm blib/lib/MHA/Server.pm
cp lib/MHA/SSHCheck.pm blib/lib/MHA/SSHCheck.pm
cp lib/MHA/DBHelper.pm blib/lib/MHA/DBHelper.pm
cp bin/masterha_stop blib/script/masterha_stop
/usr/bin/perl "-Iinc" "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/masterha_stop
cp bin/masterha_conf_host blib/script/masterha_conf_host
/usr/bin/perl "-Iinc" "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/masterha_conf_host
cp bin/masterha_check_repl blib/script/masterha_check_repl
/usr/bin/perl "-Iinc" "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/masterha_check_repl
cp bin/masterha_check_status blib/script/masterha_check_status
/usr/bin/perl "-Iinc" "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/masterha_check_status
cp bin/masterha_master_monitor blib/script/masterha_master_monitor
/usr/bin/perl "-Iinc" "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/masterha_master_monitor
cp bin/masterha_check_ssh blib/script/masterha_check_ssh
/usr/bin/perl "-Iinc" "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/masterha_check_ssh
cp bin/masterha_master_switch blib/script/masterha_master_switch
/usr/bin/perl "-Iinc" "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/masterha_master_switch
cp bin/masterha_secondary_check blib/script/masterha_secondary_check
/usr/bin/perl "-Iinc" "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/masterha_secondary_check
cp bin/masterha_manager blib/script/masterha_manager
/usr/bin/perl "-Iinc" "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/masterha_manager
Manifying blib/man1/masterha_stop.1
Manifying blib/man1/masterha_conf_host.1
Manifying blib/man1/masterha_check_repl.1
Manifying blib/man1/masterha_check_status.1
Manifying blib/man1/masterha_master_monitor.1
Manifying blib/man1/masterha_check_ssh.1
Manifying blib/man1/masterha_master_switch.1
Manifying blib/man1/masterha_secondary_check.1
Manifying blib/man1/masterha_manager.1
[root@racdb mha4mysql-manager-0.53]# make install
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/Config.pm
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/FileStatus.pm
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/HealthCheck.pm
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/ManagerAdmin.pm
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/SSHCheck.pm
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/MasterFailover.pm
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/Server.pm
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/ManagerConst.pm
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/ServerManager.pm
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/DBHelper.pm
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/ManagerAdminWrapper.pm
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/MasterRotate.pm
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/ManagerUtil.pm
Installing /usr/lib/perl5/site_perl/5.8.8/MHA/MasterMonitor.pm
Installing /usr/share/man/man1/masterha_secondary_check.1
Installing /usr/share/man/man1/masterha_manager.1
Installing /usr/share/man/man1/masterha_master_switch.1
Installing /usr/share/man/man1/masterha_check_repl.1
Installing /usr/share/man/man1/masterha_stop.1
Installing /usr/share/man/man1/masterha_check_status.1
Installing /usr/share/man/man1/masterha_conf_host.1
Installing /usr/share/man/man1/masterha_check_ssh.1
Installing /usr/share/man/man1/masterha_master_monitor.1
Installing /usr/bin/masterha_check_ssh
Installing /usr/bin/masterha_manager
Installing /usr/bin/masterha_check_repl
Installing /usr/bin/masterha_master_switch
Installing /usr/bin/masterha_secondary_check
Installing /usr/bin/masterha_check_status
Installing /usr/bin/masterha_stop
Installing /usr/bin/masterha_conf_host
Installing /usr/bin/masterha_master_monitor
Writing /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/mha4mysql/manager/.packlist
Appending installation info to /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/perllocal.pod
四、MHA 配置
1)、幾個概念:
Application:是指master-slave對,一個manager可以管理多個Applications
appxx.cnf和預設masterha_default.cnf:全域性範圍引數配置和應用引數配置,全域性引數配置是對該MHA manager管理下的所有Applications生效,並從預設的全域性
配置檔案/etc/masterha_default.cnf讀取;Application範圍引數配置只對一個Applicattion生效,配置檔案需要獨立建立,如/etc/app1.cnf。manager管理
的多個application可以分別設定,如:/etc/app2.cnf /etc/app3.cnf等;
Application範圍的引數配置,必須包含在[server default]定義塊中,而Node本地的配置必須包含在[server 1...N]塊中。多個Application的相關名稱必須唯一;
如果同時配置了全域性範圍引數和Application範圍引數,最終以Application範圍引數生效,因此引數分Local/App/Global 三種範圍。
2)、配置MHA cnf
manager_host$ cat /etc/app1.cnf
[server default]
# mysql user and password
user=root
password=12345678
ssh_user=root
# working directory on the manager
manager_workdir=/var/log/masterha/app1 #不存在Node會自動建立
manager_log=/var/log/masterha/app1/app1.log
# working directory on MySQL servers
remote_workdir=/var/log/masterha/app1
master_binlog_dir=/var/lib/mysql/
check_repl_delay=0
[server1]
hostname=192.168.133.109
candidate_master=1
[server2]
hostname=192.168.133.108
candidate_master=1
[server3]
hostname=192.168.133.241
no_master=1
3)檢查和配置SSH無密碼驗證設定
在manager上192.168.133.242配置到個Node的無密碼驗證:
[root@racdb ~]# ssh-keygen -t rsa
[root@racdb ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.133.108
[root@racdb ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.133.109
[root@racdb ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.133.241
在Node:192.168.133.108上:
[root@racdb ~]# ssh-keygen -t rsa
[root@racdb ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.133.109
[root@racdb ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.133.241
在Node:192.168.133.109上:
[root@racdb ~]# ssh-keygen -t rsa
[root@racdb ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.133.108
[root@racdb ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.133.241
在Node:192.168.133.241上:
[root@racdb ~]# ssh-keygen -t rsa
[root@racdb ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.133.108
[root@racdb ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.133.109
檢查SSH:
[root@racdb mha4mysql-manager-0.53]# masterha_check_ssh --conf=/etc/app1.cnf
Thu May 17 15:15:24 2012 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu May 17 15:15:24 2012 - [info] Reading application default configurations from /etc/app1.cnf..
Thu May 17 15:15:24 2012 - [info] Reading server configurations from /etc/app1.cnf..
Thu May 17 15:15:24 2012 - [info] Starting SSH connection tests..
Thu May 17 15:15:25 2012 - [debug]
Thu May 17 15:15:24 2012 - [debug] Connecting via SSH from root@192.168.133.109(192.168.133.109:22) to root@192.168.133.108(192.168.133.108:22)..
Thu May 17 15:15:25 2012 - [debug] ok.
Thu May 17 15:15:25 2012 - [debug] Connecting via SSH from root@192.168.133.109(192.168.133.109:22) to root@192.168.133.241(192.168.133.241:22)..
Thu May 17 15:15:25 2012 - [debug] ok.
Thu May 17 15:15:25 2012 - [debug]
Thu May 17 15:15:25 2012 - [debug] Connecting via SSH from root@192.168.133.108(192.168.133.108:22) to root@192.168.133.109(192.168.133.109:22)..
Thu May 17 15:15:25 2012 - [debug] ok.
Thu May 17 15:15:25 2012 - [debug] Connecting via SSH from root@192.168.133.108(192.168.133.108:22) to root@192.168.133.241(192.168.133.241:22)..
Thu May 17 15:15:25 2012 - [debug] ok.
Thu May 17 15:15:26 2012 - [debug]
Thu May 17 15:15:25 2012 - [debug] Connecting via SSH from root@192.168.133.241(192.168.133.241:22) to root@192.168.133.109(192.168.133.109:22)..
Thu May 17 15:15:26 2012 - [debug] ok.
Thu May 17 15:15:26 2012 - [debug] Connecting via SSH from root@192.168.133.241(192.168.133.241:22) to root@192.168.133.108(192.168.133.108:22)..
Thu May 17 15:15:26 2012 - [debug] ok.
Thu May 17 15:15:26 2012 - [info] All SSH connection tests passed successfully.
4)檢查複製狀態
[root@racdb mha4mysql-manager-0.53]# masterha_check_repl --conf=/etc/app1.cnf
如果報錯,則做相應的授權處理:
Thu May 17 15:17:06 2012 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu May 17 15:17:06 2012 - [info] Reading application default configurations from /etc/app1.cnf..
Thu May 17 15:17:06 2012 - [info] Reading server configurations from /etc/app1.cnf..
Thu May 17 15:17:06 2012 - [info] MHA::MasterMonitor version 0.53.
Creating directory /var/log/masterha/app1 #...Node....... done.
Thu May 17 15:17:06 2012 - [error][/usr/lib/perl5/site_perl/5.8.8/MHA/ServerManager.pm, ln255] Got MySQL error when connecting 192.168.133.109(192.168.133.109:3306) :1130:Host '192.168.133.242' is not allowed to connect to this MySQL server, but this is not mysql crash. Check MySQL server settings.
在192.168.133.109/108上:
mysql> grant all privileges on *.* to root@192.168.133.242 identified by '12345678';
Query OK, 0 rows affected (0.01 sec)
後繼續檢查:
[root@racdb mha4mysql-manager-0.53]# masterha_check_repl --conf=/etc/app1.cnf
Thu May 17 15:29:29 2012 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu May 17 15:29:29 2012 - [info] Reading application default configurations from /etc/app1.cnf..
Thu May 17 15:29:29 2012 - [info] Reading server configurations from /etc/app1.cnf..
Thu May 17 15:29:29 2012 - [info] MHA::MasterMonitor version 0.53.
Thu May 17 15:29:29 2012 - [error][/usr/lib/perl5/site_perl/5.8.8/MHA/ServerManager.pm, ln732] Multi-master configuration is detected, but two or more masters are either writable (read-only is not set) or dead! Check configurations for details. Master configurations are as below:
Master 192.168.133.109(192.168.133.109:3306), replicating from 192.168.133.108(192.168.133.108:3306)
Master 192.168.133.108(192.168.133.108:3306), replicating from 192.168.133.109(192.168.133.109:3306)
注:根據檢查的錯誤提示,進行相應的修改設定。
1、告警:
當前是主主互備構架,設定一個candicate主機108以及其他從機均為read_only。
mysql> set global read_only=1;
Query OK, 0 rows affected (0.03 sec)
mysql> show variables like 'read_only';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| read_only | ON |
+---------------+-------+
1 row in set (0.00 sec)
設定主機和其他從機位relay_log_purge:
mysql> set global relay_log_purge=0;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'relay_log_purge';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| relay_log_purge | OFF |
+-----------------+-------+
1 row in set (0.00 sec)
設定relay_log_purge=0 後必須對relay log檔案進行有效的管理:
vi /etc/cron.d/purge_relay_logs
# purge relay logs at 5am
0 5 * * * app /usr/bin/purge_relay_logs --user=root --password=12345678 --disable_relay_log_purge >> /var/log/masterha/purge_relay_logs.log 2>&1
/etc/init.d/crond restart
自此,MHA配置完畢
五、運營管理和測試
1)啟動MHA manager:
[root@racdb mha4mysql-manager-0.53]# masterha_manager --conf=/etc/app1.cnf --remove_dead_master_conf
推薦使用後臺程式模式運營:
[root@racdb mha4mysql-manager-0.53]# nohup masterha_manager --conf=/etc/app1.cnf --remove_dead_master_conf < /dev/null > /var/log/masterha/app1/app1.log 2>&1 &
2)檢查manager運營狀態:
[root@racdb scripts]# masterha_check_status --conf=/etc/app1.cnf
app1 (pid:26447) is running(0:PING_OK), master:192.168.133.109
[root@racdb scripts]# masterha_check_repl --conf=/etc/app1.cnf
3)手工切換測試
方式一:手工對dead master進行切換
[root@racdb scripts]# masterha_master_switch --master_state=dead --conf=/etc/app1.cnf --dead_master_host=192.168.133.109 --new_master_host=192.168.133.108
如果,MHA manager檢測到沒有dead的server,將報錯,並結束failover:
Thu May 17 17:53:33 2012 - [info] Dead Servers:
Thu May 17 17:53:33 2012 - [error][/usr/lib/perl5/site_perl/5.8.8/MHA/MasterFailover.pm, ln181] None of server is dead. Stop failover.
方式二:當前master在正常執行情況的切換:
masterha_master_switch --conf=/etc/app1.cnf --master_state=alive --new_master_host=192.168.133.108
Thu May 17 18:01:33 2012 - [info] Checking MHA is not monitoring or doing failover..
Thu May 17 18:01:33 2012 - [error][/usr/lib/perl5/site_perl/5.8.8/MHA/MasterRotate.pm, ln142] Getting advisory lock failed on the current master.
MHA Monitor runs on the current master. Stop MHA Manager/Monitor and try again.
[root@racdb app1]# vi /etc/app1.cnf
修改App1.cnf如下:
[server1]
hostname=192.168.133.109
[server2]
hostname=192.168.133.108
candidate_master=1
[server3]
hostname=192.168.133.241
[root@racdb app1]# masterha_stop --conf=/etc/app1.cnf
[root@racdb app1]# masterha_master_switch --conf=/etc/app1.cnf --master_state=alive --new_master_host=192.168.133.108
執行成功。
masterha_master_switch --master_state=dead --conf=/etc/app1.cnf --dead_master_host=192.168.133.108 --new_master_host=192.168.133.109
4)停止manager,不停止mysql server
[root@racdb scripts]# masterha_stop --conf=/etc/app1.cnf
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/14710393/viewspace-1650040/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL MHA部署 Part 7 MHA手動切換測試MySql
- MySQL高可用之MHA切換測試(switchover & failover)MySqlAI
- MHA安裝搭建和測試
- MysqlMaster切換方案MHA的探索與測試結果MySqlAST
- Mysql MHA部署-06手動切換MySql
- mysql mha 主從自動切換 高可用MySql
- mysql MGR搭建和模擬切換演練MySql
- MySQL MHA部署與測試-下篇MySql
- MySQL MHA部署 Part 6 MHA故障轉移測試MySql
- MySQL高可用方案MHA線上切換的步驟及原理MySql
- MHA高可用配置及故障切換
- RAC的VIP切換測試
- 【DB寶19】MySQL高可用之MHA功能測試MySql
- MySQL——MHA高可用群集部署及故障測試MySql
- MySQL高可用群集MHA部署及故障測試分析MySql
- MHA實現mysql主從資料庫手動切換的方法MySql資料庫
- MySQL InnoDB Cluster環境搭建和簡單測試MySql
- app 測試環境切換問題APP
- redis哨兵模式搭建和測試Redis模式
- 【MySQL】【高可用】從masterha_master_switch工具簡單分析MHA的切換邏輯MySqlAST
- 關於歸檔日誌的切換測試
- ORACLE 11g dataguard系列,手工切換測試Oracle
- Pytest 如何使用切換被測試環境
- 【MHA】mysql高可用之MHAMySql
- ORACLE 12C DATAGUARD環境搭建和主從切換Oracle
- Oracle9i重建和切換臨時表空間Oracle
- MySQL主從切換MySql
- Mysql MHA部署-04MHA配置MySql
- mysql之MHAMySql
- MySQL MHA配置MySql
- 手工切換MySQL主從MySql
- mysql主從搭建切換MySql
- Mysql Slave群切換MasterMySqlAST
- Mysql Slave群切換Master (=)MySqlAST
- MySQL MHA部署 Part 5 MHA部署指南MySql
- WebSphere MQ傳輸環境搭建和測試WebMQ
- MySQL Orchestrator自動導換+VIP切換MySql
- 【Mysql】MHA的原理MySql