Mysql-MHA高可用實驗測試

來源:互聯網
上載者:User

標籤:centos mysql mha 高可用 實驗

說明:

centos 6.5  mysql 5.5.37  mha4mysql-manager-0.55  mha4mysql-node-0.54

manager 192.168.1.1
db1 192.168.1.2
db2 192.168.1.3
db3 192.168.1.4


配置mysql主從
db1:

server-id = 1
read_only = 1
relay_log_purge=0
binlog_format=mixed

db2,db3忽略

db1主

grant replication slave on *.* to [email protected]‘192.168.1.%‘ identified by ‘passwd‘;flush privileges;stop slave;#設定複製許可權帳號GRANT ALL PRIVILEGES ON *.* TO ‘mha_manager‘@‘192.168.1.%‘ IDENTIFIED BY ‘123456‘;reset master;show master status\G

db2備

grant replication slave on *.* to [email protected]‘192.168.1.%‘ identified by ‘passwd‘;GRANT ALL PRIVILEGES ON *.* TO ‘mha_manager‘@‘192.168.1.%‘ IDENTIFIED BY ‘123456‘;flush privileges;reset master;slave stop;change master to MASTER_HOST=‘192.168.1.2‘, MASTER_PORT=3306,MASTER_USER=‘mharep‘, MASTER_PASSWORD=‘passwd‘,master_log_file=‘mysql-bin.000001‘, master_log_pos=107;slave start;show slave status\G;

db3從

reset master;slave stop;GRANT ALL PRIVILEGES ON *.* TO ‘mha_manager‘@‘192.168.1.%‘ IDENTIFIED BY ‘123456‘;flush privileges;change master to MASTER_HOST=‘192.168.1.2‘, MASTER_PORT=3306,MASTER_USER=‘mharep‘, MASTER_PASSWORD=‘passwd‘,master_log_file=‘mysql-bin.000001‘, master_log_pos=107;slave start;show slave status\G;


配置雙機互信
manager

ssh-keygen -t rsafor i in db1 db2 db3;do ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]$i;done

db1主

ssh-keygen -t rsa for i in manager db2 db3;do ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]$i;done

db2備 和 db3從 配置略


安裝mysql-MHA
https://downloads.mariadb.com/files/MHA

wget https://downloads.mariadb.com/files/MHA/mha4mysql-manager-0.55-0.el6.noarch.rpmwget https://downloads.mariadb.com/files/MHA/mha4mysql-node-0.54-0.el6.noarch.rpm

db1主 db2備 db3從
yum install perl-DBD-MySQL
yum localinstall mha4mysql-node-0.54-0.el6.noarch.rpm

manager

yum install perl cpanyum install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager

#這兩個yum沒有安裝上 perl-Log-Dispatch perl-Parallel-ForkManager

wget http://downloads.naulinux.ru/pub/NauLinux/6x/x86_64/sites/School/RPMS/perl-Log-Dispatch-2.27-1.el6.noarch.rpmwget ftp://rpmfind.net/linux/dag/redhat/el6/en/x86_64/dag/RPMS/perl-Parallel-ForkManager-0.7.5-2.2.el6.rf.noarch.rpmwget ftp://rpmfind.net/linux/dag/redhat/el6/en/x86_64/dag/RPMS/perl-Mail-Sender-0.8.16-1.el6.rf.noarch.rpmwget ftp://rpmfind.net/linux/dag/redhat/el6/en/x86_64/dag/RPMS/perl-Mail-Sendmail-0.79-1.2.el6.rf.noarch.rpm

rpm -ivh perl-Mail-Sender-0.8.16-1.el6.rf.noarch.rpm
rpm -ivh perl-Mail-Sendmail-0.79-1.2.el6.rf.noarch.rpm
yum localinstall perl-Log-Dispatch-2.27-1.el6.noarch.rpm
yum localinstall perl-Parallel-ForkManager-0.7.5-2.2.el6.rf.noarch.rpm
yum localinstall mha4mysql-node-0.54-0.el6.noarch.rpm
yum localinstall mha4mysql-manager-0.55-0.el6.noarch.rpm


配置mysql-MHA
[[email protected] ~]# masterha_<Tab>
masterha_check_repl       masterha_conf_host        masterha_master_switch
masterha_check_ssh        masterha_manager          masterha_secondary_check
masterha_check_status     masterha_master_monitor   masterha_stop

tar -xzf mha4mysql-manager-0.55.tar.gz
ls mha4mysql-manager-0.55/samples/conf
masterha_default.cnf    app1.cnf

mkdir -p /usr/local/mha/scripts
cp mha4mysql-manager-0.55/samples/scripts/* /usr/local/mha/scripts

[[email protected] ~]# vim /usr/local/mha/mha.conf [server default]user=mha_managerpassword=123456manager_workdir=/usr/local/mhamanager_log=/usr/local/mha/manager.logremote_workdir=/usr/local/mhassh_user=rootrepl_user=mhareprepl_password=passwdping_interval=1secondary_check_script= masterha_secondary_check -s 192.168.1.2 -s 192.168.1.3 -s 192.168.1.4master_ip_failover_script=/usr/local/mha/scripts/master_ip_failover#shutdown_script= /usr/local/mha/scripts/power_managerreport_script= /usr/local/mha/scripts/send_reportmaster_ip_online_change_script= /usr/local/mha/scripts/master_ip_online_change[server1]hostname=192.168.1.2ssh_port=22master_binlog_dir=/var/mysql/logcandidate_master=1[server2]hostname=192.168.1.3ssh_port=22master_binlog_dir=/var/mysql/logcandidate_master=1[server3]hostname=192.168.1.4ssh_port=22master_binlog_dir=/var/mysql/logno_master=1


#驗證ssh通訊
masterha_check_ssh  --conf=/usr/local/mha/mha.conf

650) this.width=650;" title="QQ20150108165603.jpg" alt="wKioL1SueDOSfVm9AAZR6Nm0jAQ282.jpg" src="http://s3.51cto.com/wyfs02/M00/58/52/wKioL1SueDOSfVm9AAZR6Nm0jAQ282.jpg" />

#驗證mysql複製
wget ftp://rpmfind.net/linux/dag/redhat/el6/en/x86_64/extras/RPMS/perl-Net-Telnet-3.03-2.el6.rfx.noarch.rpm
yum localinstall perl-Net-Telnet-3.03-2.el6.rfx.noarch.rpm
[[email protected] ~]# masterha_check_repl --conf=/usr/local/mha/mha.conf
Thu Jan  8 18:05:40 2015 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu Jan  8 18:05:40 2015 - [info] Reading application default configurations from /usr/local/mha/mha.conf..
Thu Jan  8 18:05:40 2015 - [info] Reading server configurations from /usr/local/mha/mha.conf..
Thu Jan  8 18:05:40 2015 - [info] MHA::MasterMonitor version 0.55.
Thu Jan  8 18:05:40 2015 - [info] Dead Servers:
Thu Jan  8 18:05:40 2015 - [info] Alive Servers:
Thu Jan  8 18:05:40 2015 - [info]   192.168.1.2(192.168.1.2:3306)
Thu Jan  8 18:05:40 2015 - [info]   192.168.1.3(192.168.1.3:3306)
Thu Jan  8 18:05:40 2015 - [info]   192.168.1.4(192.168.1.4:3306)
Thu Jan  8 18:05:40 2015 - [info] Alive Slaves:
Thu Jan  8 18:05:40 2015 - [info]   192.168.1.3(192.168.1.3:3306)  Version=5.5.37-log (oldest major version between slaves) log-bin:enabled
Thu Jan  8 18:05:40 2015 - [info]     Replicating from 192.168.1.2(192.168.1.2:3306)
Thu Jan  8 18:05:40 2015 - [info]     Primary candidate for the new Master (candidate_master is set)
Thu Jan  8 18:05:40 2015 - [info]   192.168.1.4(192.168.1.4:3306)  Version=5.5.37-log (oldest major version between slaves) log-bin:enabled
Thu Jan  8 18:05:40 2015 - [info]     Replicating from 192.168.1.2(192.168.1.2:3306)
Thu Jan  8 18:05:40 2015 - [info]     Not candidate for the new Master (no_master is set)
Thu Jan  8 18:05:40 2015 - [info] Current Alive Master: 192.168.1.2(192.168.1.2:3306)
Thu Jan  8 18:05:40 2015 - [info] Checking slave configurations..
Thu Jan  8 18:05:40 2015 - [info] Checking replication filtering settings..
Thu Jan  8 18:05:40 2015 - [info]  binlog_do_db= , binlog_ignore_db=
Thu Jan  8 18:05:40 2015 - [info]  Replication filtering check ok.
Thu Jan  8 18:05:40 2015 - [info] Starting SSH connection tests..
Thu Jan  8 18:05:41 2015 - [info] All SSH connection tests passed successfully.
Thu Jan  8 18:05:41 2015 - [info] Checking MHA Node version..
Thu Jan  8 18:05:42 2015 - [info]  Version check ok.
Thu Jan  8 18:05:42 2015 - [info] Checking SSH publickey authentication settings on the current master..
Thu Jan  8 18:05:42 2015 - [info] HealthCheck: SSH to 192.168.1.2 is reachable.
Thu Jan  8 18:05:42 2015 - [info] Master MHA Node version is 0.54.
Thu Jan  8 18:05:42 2015 - [info] Checking recovery script configurations on the current master..
Thu Jan  8 18:05:42 2015 - [info]   Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/var/mysql/log --output_file=/usr/local/mha/save_binary_logs_test --manager_version=0.55 --start_file=mysql-bin.000002
Thu Jan  8 18:05:42 2015 - [info]   Connecting to [email protected](192.168.1.2)..
  Creating /usr/local/mha if not exists..    ok.
  Checking output directory is accessible or not..
   ok.
  Binlog found at /var/mysql/log, up to mysql-bin.000002
Thu Jan  8 18:05:42 2015 - [info] Master setting check done.
Thu Jan  8 18:05:42 2015 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
Thu Jan  8 18:05:42 2015 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user=‘mha_manager‘ --slave_host=192.168.1.3 --slave_ip=192.168.1.3 --slave_port=3306 --workdir=/usr/local/mha --target_version=5.5.37-log --manager_version=0.55 --relay_log_info=/var/mysql/data/relay-log.info  --relay_dir=/var/mysql/data/  --slave_pass=xxx
Thu Jan  8 18:05:42 2015 - [info]   Connecting to [email protected](192.168.1.3:22)..
  Checking slave recovery environment settings..
    Opening /var/mysql/data/relay-log.info ... ok.
    Relay log found at /var/mysql/data, up to mysql-relay-bin.000007
    Temporary relay log file is /var/mysql/data/mysql-relay-bin.000007
    Testing mysql connection and privileges.. done.
    Testing mysqlbinlog output.. done.
    Cleaning up test file(s).. done.
Thu Jan  8 18:05:42 2015 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user=‘mha_manager‘ --slave_host=192.168.1.4 --slave_ip=192.168.1.4 --slave_port=3306 --workdir=/usr/local/mha --target_version=5.5.37-log --manager_version=0.55 --relay_log_info=/var/mysql/data/relay-log.info  --relay_dir=/var/mysql/data/  --slave_pass=xxx
Thu Jan  8 18:05:42 2015 - [info]   Connecting to [email protected](192.168.1.4:22)..
  Checking slave recovery environment settings..
    Opening /var/mysql/data/relay-log.info ... ok.
    Relay log found at /var/mysql/data, up to mysql-relay-bin.000006
    Temporary relay log file is /var/mysql/data/mysql-relay-bin.000006
    Testing mysql connection and privileges.. done.
    Testing mysqlbinlog output.. done.
    Cleaning up test file(s).. done.
Thu Jan  8 18:05:43 2015 - [info] Slaves settings check done.
Thu Jan  8 18:05:43 2015 - [info]
192.168.1.2 (current master)
 +--192.168.1.3
 +--192.168.1.4

Thu Jan  8 18:05:43 2015 - [info] Checking replication health on 192.168.1.3..
Thu Jan  8 18:05:43 2015 - [info]  ok.
Thu Jan  8 18:05:43 2015 - [info] Checking replication health on 192.168.1.4..
Thu Jan  8 18:05:43 2015 - [info]  ok.
Thu Jan  8 18:05:43 2015 - [info] Checking master_ip_failover_script status:
Thu Jan  8 18:05:43 2015 - [info]   /usr/local/mha/scripts/master_ip_failover --command=status --ssh_user=root --orig_master_host=192.168.1.2 --orig_master_ip=192.168.1.2 --orig_master_port=3306


IN SCRIPT TEST====/sbin/ifconfig eth0:1 down==/sbin/ifconfig eth0:1 192.168.1.100;/sbin/arping -I eth0 -c 3 -s 192.168.1.100 192.168.1.1 >/dev/null 2>&1===

Checking the Status of the script.. OK
Thu Jan  8 18:05:46 2015 - [info]  OK.
Thu Jan  8 18:05:46 2015 - [warning] shutdown_script is not defined.
Thu Jan  8 18:05:46 2015 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.


啟動MHA
[[email protected] ~]# masterha_manager --conf=/usr/local/mha/mha.conf &
查看MHA
[[email protected] ~]# masterha_check_status --conf=/usr/local/mha/mha.conf
mha (pid:2686) is running(0:PING_OK), master:192.168.1.2

650) this.width=650;" title="QQ20150108183928.jpg" alt="wKioL1SueHGwWiK5AAPP_YskCTE055.jpg" src="http://s3.51cto.com/wyfs02/M01/58/52/wKioL1SueHGwWiK5AAPP_YskCTE055.jpg" />

停止MHA
[[email protected] ~]# masterha_stop --conf=/usr/local/mha/mha.conf

驗證MHA:

[[email protected] ~]# ip a #現在有VIP
[[email protected] ~]# service mysqld stop #mysql停止,在這時候VIP會做轉移
Shutting down MySQL... SUCCESS!
[[email protected] ~]# ip a #已經沒有VIP

IP已經轉移到db2,並且在db3上 mysql> show slave status\G 查看 Master_Server_Id: 2

650) this.width=650;" title="QQ20150108201913.jpg" alt="wKiom1Sud8PxYxZ0AAOV3qG1V5A991.jpg" src="http://s3.51cto.com/wyfs02/M01/58/55/wKiom1Sud8PxYxZ0AAOV3qG1V5A991.jpg" />


本文出自 “金戈鐵馬行飛燕” 部落格,請務必保留此出處http://bbotte.blog.51cto.com/6205307/1600894

Mysql-MHA高可用實驗測試

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.