• 官方网站(需要×××):

  https://code.google.com/p/mysql-master-ha/


  • 参考网站:

  http://mysqlstepbystep.com/2015/06/01/mysql-high-available-with-mha-2/

  • rpm及tar包下载

    本例安装是使用rpm安装,所以需要下载rpm安装文件

    下载tar包的目的是为了里面的配置文件及可执行文件,具体位置在manager的samples\scripts下

  • 环境

  操作系统:centos6.6

  mha版本:0.56

  mysql版本:5.6.27

  • ip分配:

  master  192.168.31.64

  slave   192.168.31.65

  vip    192.168.31.100

  • mysql主从

    主从复制搭建步骤略

    创建账号(每个节点):grant all privileges on *.* to mha@'%' identified by 'mhapass';

    创建复制账号(每个节点):grant replication slave on *.* to repl@'%' identified by 'slavepass';

  • mha安装

    说明:生产环境mha4mysql-manager如果在管理多套主从情况下最好单独安装到独立主机,并作ha,本次实验是虚拟机,因此mha4mysql-manager安装到192.168.31.64,mha4mysql-node每个节点都安装。

    • 192.168.31.64

      #安装manager和node

      yum install libdbd-mysql-perl libconfig-tiny-perl liblog-dispatch-perl libparallel-forkmanager-perl

    yum localinstall mha4mysql-node-0.56-0.el6.noarch.rpm mha4mysql-manager-0.56-0.el6.noarch.rpm

    #创建配置文件目录和日志目录

    mkdir -p /etc/masterha /var/log/masterha/app1

    #拷贝mha配置文件和可执行文件到配置文件目录下

    tar -zxf mha4mysql-manager-0.56.tar.gz

    cp ./mha4mysql-manager-0.56/samples/scripts/* /etc/masterha

    #设置节点间互信

    ssh-keygen -t rsa

    ssh-copy-id -i /root/.ssh/id_rsa [email protected]

    ssh-copy-id -i /root/.ssh/id_rsa [email protected]

    #查看vip有没有被绑定

    ip addr

        inet 192.168.31.64/24 brd 192.168.31.255 scope global eth0

        inet 192.168.31.100/32 scope global eth0

    • 192.168.31.65

  yum install libdbd-mysql-perl libconfig-tiny-perl liblog-dispatch-perl libparallel-forkmanager-perl

    yum localinstall mha4mysql-node-0.56-0.el6.noarch.rpm

    • 配置文件及可执行文件放置在/etc/masterha/下,可从附件下

  • mha检查及启动

    • ssh检查


[root@centos-zabbix-64 masterha]# masterha_check_ssh --global_conf=/etc/masterha/masterha_default.conf --conf=/etc/masterha/app1.cnf 

Thu Jan 21 09:29:41 2016 - [info] Reading default configuration from /etc/masterha/masterha_default.conf..

Thu Jan 21 09:29:41 2016 - [info] Reading application default configuration from /etc/masterha/app1.cnf..

Thu Jan 21 09:29:41 2016 - [info] Reading server configuration from /etc/masterha/app1.cnf..

Thu Jan 21 09:29:41 2016 - [info] Starting SSH connection tests..

Thu Jan 21 09:29:42 2016 - [debug] 

Thu Jan 21 09:29:41 2016 - [debug]  Connecting via SSH from [email protected](192.168.31.65:22) to [email protected](192.168.31.64:22)..

Thu Jan 21 09:29:42 2016 - [debug]   ok.

Thu Jan 21 09:29:42 2016 - [debug] 

Thu Jan 21 09:29:41 2016 - [debug]  Connecting via SSH from [email protected](192.168.31.64:22) to [email protected](192.168.31.65:22)..

Thu Jan 21 09:29:42 2016 - [debug]   ok.

Thu Jan 21 09:29:42 2016 - [info] All SSH connection tests passed successfully.

  • 复制检查

.....

MySQL Replication Health is OK.

  • 启动mha manager

    masterha_manager --global_conf=/etc/masterha/masterha_default.conf --conf=/etc/masterha/app1.cnf &   

  • 绑定vip到主64

    ip addr add 192.168.31.64/24 dev eth0

  • 查看vip有没有被绑定

    ip addr

        inet 192.168.31.64/24 brd 192.168.31.255 scope global eth0

        inet 192.168.31.100/32 scope global eth0

    • 查看mha日志


masterha_manager --global_conf=/etc/masterha/masterha_default.conf --conf=/etc/masterha/app1.cnf &