Rumah >pangkalan data >tutorial mysql > Mysql-MHA高可用实验测试

Mysql-MHA高可用实验测试

WBOY
WBOYasal
2016-06-07 16:42:231494semak imbas

说明:centos6.5mysql5.5.37mha4mysql-manager-0.55mha4mysql-node-0.54manager192.168.1.1db1192.168.1.2db2192.168.1.3db3192.168.1.4配置mysql主从db1:server

说明:

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 mharep@'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 mharep@'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 rsa for i in db1 db2 db3;do ssh-copy-id -i ~/.ssh/id_rsa.pub root@$i;done

db1主

ssh-keygen -t rsa  for i in manager db2 db3;do ssh-copy-id -i ~/.ssh/id_rsa.pub root@$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.rpm wget 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 cpan yum install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager

#这两个yum没有安装上 perl-Log-Dispatch perl-Parallel-ForkManager

wget  wget ftp://rpmfind.net/linux/dag/redhat/el6/en/x86_64/dag/RPMS/perl-Parallel-ForkManager-0.7.5-2.2.el6.rf.noarch.rpm wget ftp://rpmfind.net/linux/dag/redhat/el6/en/x86_64/dag/RPMS/perl-Mail-Sender-0.8.16-1.el6.rf.noarch.rpm wget 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
[root@manager ~]# masterha_
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

[root@manager ~]# vim /usr/local/mha/mha.conf  [server default] user=mha_manager password=123456 manager_workdir=/usr/local/mha manager_log=/usr/local/mha/manager.log remote_workdir=/usr/local/mha ssh_user=root repl_user=mharep repl_password=passwd ping_interval=1 secondary_check_script= masterha_secondary_check -s 192.168.1.2 -s 192.168.1.3 -s 192.168.1.4 master_ip_failover_script=/usr/local/mha/scripts/master_ip_failover #shutdown_script= /usr/local/mha/scripts/power_manager report_script= /usr/local/mha/scripts/send_report master_ip_online_change_script= /usr/local/mha/scripts/master_ip_online_change [server1] hostname=192.168.1.2 ssh_port=22 master_binlog_dir=/var/mysql/log candidate_master=1 [server2] hostname=192.168.1.3 ssh_port=22 master_binlog_dir=/var/mysql/log candidate_master=1 [server3] hostname=192.168.1.4 ssh_port=22 master_binlog_dir=/var/mysql/log no_master=1


#验证ssh通讯
masterha_check_ssh  --conf=/usr/local/mha/mha.conf

wKioL1SueDOSfVm9AAZR6Nm0jAQ282.jpg

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn