189 8069 5689

怎么搭建MHA+MySQL

这篇文章主要介绍“怎么搭建MHA+MySQL”,在日常操作中,相信很多人在怎么搭建MHA+MySQL问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”怎么搭建MHA+MySQL”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

创新互联建站长期为千余家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为格尔木企业提供专业的网站建设、网站设计格尔木网站改版等技术服务。拥有十载丰富建站经验和众多成功案例,为您定制开发。

一主两从,manager节点为vm3
master:10.0.0.2 vm1   node
slave1: 10.0.0.3 vm2     node
slave2: 10.0.0.4 vm3     manager

OS verision均为:CentOS release 6.5

1,从https://code.google.com/p/mysql-master-ha/wiki/Downloads?tm=2下载MHA安装包
   mha4mysql-node-0.56-0.el6.noarch.rpm
   mha4mysql-manager-0.56-0.el6.noarch.rpm
   
   node需要安装mha4mysql-node-0.56-0.el6.noarch.rpm包,
   manager节点需要安装mha4mysql-manager-0.56-0.el6.noarch.rpm和mha4mysql-node-0.56-0.el6.noarch.rpm
   或者从https://github.com/yoshinorim下载源码包
2 给所有节点配置EPEL yum源。
   rpm -ivh http://mirrors.opencas.cn/epel/6/i386/epel-release-6-8.noarch.rpm
   
   yum clean all; yum makecache

3 为所有节点安装mha4mysql-node-0.56-0.el6.noarch.rpm
   yum -y install perl-DBD-MySQL  ncftp  
   rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm
   
4 为manager节点安装mha4mysql-manager-0.56-0.el6.noarch.rpm
   yum -y install perl-Config-Tiny perl-Params-Validate perl-Log-Dispatch perl-Parallel-ForkManager  
   rpm -ivh mha4mysql-manager-0.56-0.el6.noarch.rpm

5 配置各节点间的ssh公钥信任,实现免密钥登录。(manager to node, node to node)
  vm1:
    ssh-keygen -t rsa
    ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.0.0.3
    ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.0.0.4   
  vm2:
    ssh-keygen -t rsa
    ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.0.0.2
    ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.0.0.4   
  vm3:
    ssh-keygen -t rsa
    ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.0.0.2
    ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.0.0.3   
   
  分别从各个节点ssh登陆其他节点。(必须做,头一次需要输入yes确认)

6 在各mysql节点创建MHA的监控用户
   grant all privileges on *.* to 'mha_monitor'@'10.0.0.%' identified by '123456';
   mysql> select user,host from user;
   +-------------+-----------+
   | user        | host      |
   +-------------+-----------+
   | mha_monitor | 10.0.0.%  |
   | repl        | 10.0.0.%  |

7 配置mha conf文件
   mkdir /etc/masterha  
   mkdir -p /masterha/app1
   
   配置文件app1.cnf内容如下
   cat /etc/masterha/app1.cnf
    [server default]
    manager_workdir=/masterha/app1  
    manager_log=/masterha/app1/manager.log  
    ssh_user=root            ##OS ssh登陆用户
   
    user=mha_monitor         ##mha登陆mysql主从的用户
    password=123456          ##mha登陆mysql主从的用户密码
     
    repl_user=repl           ##主从复制用户
    repl_password=p4ssw0rd   ##主从复制用户的密码
   
    ping_interval=1
    shutdown_script=""
    #master_ip_failover_script="/usr/local/bin/master_ip_failover"
    master_ip_online_change_script=""
    report_script=""
   
    [server1]  
    hostname=10.0.0.2  
    master_binlog_dir="/data/mysql3306"
    port=3306
    candidate_master=1
   
    [server2]  
    hostname=10.0.0.3  
    master_binlog_dir="/data/mysql3306"
    port=3306
    candidate_master=1
   
    [server3]
    hostname=10.0.0.4
    master_binlog_dir="/data/mysql3306"
    port=3306
    no_master=1

8 启动
nohup masterha_manager --conf=/etc/masterha/app1.cnf > /tmp/mha_manager.log  < /dev/null 2>&1 &  
shutdown 掉master后,可以顺利切换。
   
但是masterha_check_ssh会报错,只是不影响功能:
[root@vm3 ~]# masterha_check_ssh --conf=/etc/masterha/app1.cnf
Wed Apr  6 15:56:05 2016 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Wed Apr  6 15:56:05 2016 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Wed Apr  6 15:56:05 2016 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Wed Apr  6 15:56:05 2016 - [info] Starting SSH connection tests..
Wed Apr  6 15:56:05 2016 - [debug]
Wed Apr  6 15:56:05 2016 - [debug]  Connecting via SSH from root@vm1(10.0.0.2:22) to root@vm2(10.0.0.3:22)..
Wed Apr  6 15:56:05 2016 - [debug]   ok.
Wed Apr  6 15:56:05 2016 - [debug]  Connecting via SSH from root@vm1(10.0.0.2:22) to root@10.0.0.4(10.0.0.4:22)..
Wed Apr  6 15:56:05 2016 - [debug]   ok.
Wed Apr  6 15:56:06 2016 - [debug]
Wed Apr  6 15:56:05 2016 - [debug]  Connecting via SSH from root@vm2(10.0.0.3:22) to root@vm1(10.0.0.2:22)..
Wed Apr  6 15:56:06 2016 - [debug]   ok.
Wed Apr  6 15:56:06 2016 - [debug]  Connecting via SSH from root@vm2(10.0.0.3:22) to root@10.0.0.4(10.0.0.4:22)..
Wed Apr  6 15:56:06 2016 - [debug]   ok.
Wed Apr  6 15:56:06 2016 - [error][/usr/share/perl5/vendor_perl/MHA/SSHCheck.pm, ln63]
Wed Apr  6 15:56:06 2016 - [debug]  Connecting via SSH from root@10.0.0.4(10.0.0.4:22) to root@vm1(10.0.0.2:22)..
Warning: Permanently added '10.0.0.4' (RSA) to the list of known hosts.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
Wed Apr  6 15:56:06 2016 - [error][/usr/share/perl5/vendor_perl/MHA/SSHCheck.pm, ln111] SSH connection from root@10.0.0.4(10.0.0.4:22) to root@vm1(10.0.0.2:22) failed!
SSH Configuration Check Failed!
at /usr/bin/masterha_check_ssh line 44中间

9 最后shutdown掉master,模拟failover:

----- Failover Report -----

app1: MySQL Master failover vm1(10.0.0.2:3306) to vm2(10.0.0.3:3306) succeeded

Master vm1(10.0.0.2:3306) is down!

Check MHA Manager logs at vm3:/masterha/app1/manager.log for details.

Started automated(non-interactive) failover.
Selected vm2(10.0.0.3:3306) as a new master.
vm2(10.0.0.3:3306): OK: Applying all logs succeeded.
10.0.0.4(10.0.0.4:3306): OK: Slave started, replicating from vm2(10.0.0.3:3306)
vm2(10.0.0.3:3306): Resetting slave info succeeded.

主从切换成功。

##########################################
##########################################
关于masterha_check_ssh报错的问题,MHA官网上发现类似问题的帖子有人给的解释如下:
#3 dba.abde...@gmail.com As mentioned here in the tutorial:
https://code.google.com/p/mysql-master-ha/wiki/Tutorial
You shouldn't add an entry for the manager host. If you have 4 hosts, 1, 2, 3 and 4 (manager), you should add host entries for the first 3 ones only (1, 2 & 3) then it should work without any problems.

他的结构是:
master:10.10.105.9
slave1:10.10.105.10
slave2:10.10.105.11
slave3+mha_manage:10.10.105.12
和我的结构类似。

到此,关于“怎么搭建MHA+MySQL”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!


网页标题:怎么搭建MHA+MySQL
标题URL:http://jkwzsj.com/article/psgipo.html

其他资讯