it运维开发教程,运维管理,因为微不足道,所以值得关注!域名来源:sos 救援 idc 数据中心 所以sos+idc=sosidc.com

mysql高可用mha解决方案03-去哪网采用的

发布:admin2016-3-4 16:25分类: 解决方案

2.安装部署MHA

2.1安装MHA node(在所有Mysql服务器上安装)

1)安装依赖包

  rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

yum -y install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-Config-IniFiles perl-Time-HiRes  perl-Time-HiRes  perl-CPAN

 

2)在所有的节点上安装mha node:

tar  zxvf  mha4mysql-node-0.56.tar.gz

cd  mha4mysql-node-0.56

perl  Makefile.PL

make

make install

 

2.2.安装MHA Manager

MHA Manager中主要包括了几个管理员的命令行工具,例如masterha_managermasterha_master_switch等。

(1)       安装依赖包

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

yum -y install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-Config-IniFiles perl-Time-HiRes  perl-Time-HiRes  perl-CPAN

(2)       安装MHA node软件包。注意,在MHA Manger的主机上也要安装MHA node.

tar  zxvf  mha4mysql-node-0.56.tar.gz

cd  mha4mysql-node-0.56

perl  Makefile.PL

make

make install

(3)       安装MHA Manager软件包。

tar zxvf mha4mysql-manager-0.56.tar.gz

cd mha4mysql-manager-0.56

perl Makefile.PL

make

make install

 

2.3. 配置SSH 登录无密码验证

(1)       manager 192.168.127.100上配置到所有节点的无密码验证

ssh-keygen -t rsa

ssh-copy-id -i ~/.ssh/id_rsa.pub root@MHA

ssh-copy-id -i ~/.ssh/id_rsa.pub root@master

ssh-copy-id -i ~/.ssh/id_rsa.pub root@slave01

ssh-copy-id -i ~/.ssh/id_rsa.pub root@slave02

(2)       MHA Node master(192.168.127.101)上:

 ssh-keygen -t rsa

 ssh-copy-id -i ~/.ssh/id_rsa.pub root@MHA

ssh-copy-id -i ~/.ssh/id_rsa.pub root@master

ssh-copy-id -i ~/.ssh/id_rsa.pub root@slave01

     ssh-copy-id -i ~/.ssh/id_rsa.pub root@slave02

(3)       MHA Node slave01(192.168.127.102)上:

 ssh-keygen -t rsa

ssh-copy-id -i ~/.ssh/id_rsa.pub root@MHA

 ssh-copy-id -i ~/.ssh/id_rsa.pub root@master

ssh-copy-id -i ~/.ssh/id_rsa.pub root@slave01

     ssh-copy-id -i ~/.ssh/id_rsa.pub root@slave02

(4)       MHA Node slave02(192.168.127.103)上:

 ssh-keygen -t rsa

ssh-copy-id -i ~/.ssh/id_rsa.pub root@MHA

 ssh-copy-id -i ~/.ssh/id_rsa.pub root@master

     ssh-copy-id -i ~/.ssh/id_rsa.pub root@slave01

ssh-copy-id -i ~/.ssh/id_rsa.pub root@slave02

 

   在每台做以下步骤

ln -s /app/mysql5.6/bin/* /usr/local/bin/

把脚本拷贝相关目录

[root@MHA ~]# cp /root/mha4mysql-manager-0.56/samples/scripts/master_ip_failover /usr/local/bin/

 

[root@MHA ~]# cp /root/mha4mysql-manager-0.56/samples/scripts/master_ip_online_change /usr/local/bin/

 

[root@MHA~]#cp /root/mha4mysql-manager-0.56/samples/scripts/send_report  /usr/local/bin/

 

[root@MHA ~]# cp /root/mha4mysql-manager-0.56/bin/masterha_secondary_check /usr/bin/

3.配置MHA

配置MHA的步骤如下。

(1)       创建MHA工作目录,并且创建相关配置文件:

mkdir -p /etc/masterha

mkdir -p /masterha/app1

      配置如下

vi /etc/masterha/app1.cnf

[server default]

manager_workdir=/masterha/app1

manager_log=/masterha/app1/app1.log

master_ip_failover_script=/usr/local/bin/master_ip_failover

master_ip_online_change_script=/usr/local/bin/master_ip_online_change

 

user=root

password=123456

ssh_user=root

repl_user=repl

repl_password=repl

ping_interval=1

remote_workdir=/tmp

report_script=/usr/local/bin/send_report

secondary_check_script=/usr/bin/masterha_secondary_check  -s MHA -s slave02  --user=root --master_host=master --master_ip=192.168.127.101 --master_port=3306 --password=123456

shutdown_script=""

report_script=""

 

 

[server1]

hostname=192.168.127.101

master_binlog_dir=/data/mysql3306

candidate_master=1

[server2]

hostname=192.168.127.102

master_binlog_dir=/data/mysql3306

candidate_master=1

check_repl_delay=0

 

[server3]

hostname=192.168.127.103

master_binlog_dir=/data/mysql3306

no_master=1

 

4.检查SSH的配置

检查MHA Manager到所有MHA nodeSSH连接状态:

[root@MHA ~]# masterha_check_ssh --conf=/etc/masterha/app1.cnf

Wed Mar  2 19:03:30 2016 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.

Wed Mar  2 19:03:30 2016 - [info] Reading application default configuration from /etc/masterha/app1.cnf..

Wed Mar  2 19:03:30 2016 - [info] Reading server configuration from /etc/masterha/app1.cnf..

Wed Mar  2 19:03:30 2016 - [info] Starting SSH connection tests..

Wed Mar  2 19:03:31 2016 - [debug]

Wed Mar  2 19:03:30 2016 - [debug]  Connecting via SSH from root@192.168.127.101(192.168.127.101:22) to root@192.168.127.102(192.168.127.102:22)..

Wed Mar  2 19:03:30 2016 - [debug]   ok.

Wed Mar  2 19:03:30 2016 - [debug]  Connecting via SSH from root@192.168.127.101(192.168.127.101:22) to root@192.168.127.103(192.168.127.103:22)..

Wed Mar  2 19:03:30 2016 - [debug]   ok.

Wed Mar  2 19:03:31 2016 - [debug]

Wed Mar  2 19:03:30 2016 - [debug]  Connecting via SSH from root@192.168.127.102(192.168.127.102:22) to root@192.168.127.101(192.168.127.101:22)..

Wed Mar  2 19:03:31 2016 - [debug]   ok.

Wed Mar  2 19:03:31 2016 - [debug]  Connecting via SSH from root@192.168.127.102(192.168.127.102:22) to root@192.168.127.103(192.168.127.103:22)..

Wed Mar  2 19:03:31 2016 - [debug]   ok.

Wed Mar  2 19:03:32 2016 - [debug]

Wed Mar  2 19:03:31 2016 - [debug]  Connecting via SSH from root@192.168.127.103(192.168.127.103:22) to root@192.168.127.101(192.168.127.101:22)..

Wed Mar  2 19:03:31 2016 - [debug]   ok.

Wed Mar  2 19:03:31 2016 - [debug]  Connecting via SSH from root@192.168.127.103(192.168.127.103:22) to root@192.168.127.102(192.168.127.102:22)..

Wed Mar  2 19:03:32 2016 - [debug]   ok.

Wed Mar  2 19:03:32 2016 - [info] All SSH connection tests passed successfully.

5.检查整个复制环境

[root@MHA ~]# masterha_check_ssh --conf=/etc/masterha/app1.cnf

Wed Mar  2 19:03:30 2016 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.

Wed Mar  2 19:03:30 2016 - [info] Reading application default configuration from /etc/masterha/app1.cnf..

Wed Mar  2 19:03:30 2016 - [info] Reading server configuration from /etc/masterha/app1.cnf..

Wed Mar  2 19:03:30 2016 - [info] Starting SSH connection tests..