简单粗暴的MHA部署

Download mha4mysql-manager/node
Download for MHA

IP规划
192.168.1.10/24 MHA-manager
192.168.1.20/24 MHA-node1(主)
192.168.1.30/24 MHA-node2(从1)
192.168.1.40/24 MHA-node3(从2)

MHA部署前准备工作
3.1配置EPEL以及RPMForge
EPEL
RPMForge

3.2上述中各节点SSH无密钥认证打通
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.10
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.20
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.30
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.40

注:因MHA是通过SSH连接各节点机器管理,故本机也需要执行ssh-copy-di

安装MHA的manager和node软件包
yum localinstall -y mha4mysql-node-0.56-0.el6.noarch.rpm #各节点都要安装,含manager节点
yum localinstall -y mha4mysql-manager-0.56-0.el6.noarch.rpm #只在manager节点安装

在node节点安装配置MySQL一主两从,半同步复制
参考:半同步复制部署配置

配置MHA

[root@db-one bin]# mkdir -p /usr/local/mha
[root@db-one bin]# mkdir -p /etc/mha

[root@db-one bin]# cat >/etc/mha/mha.conf  <<EOF

>[server default]
> user=root         #MySQL用户,其host字段需设置如"root@'192.168.1.%'"
> password=123@Coral
> ssh_user=root
> manager_workdir=/usr/local/mha
> remote_workdir=/usr/local/mha
> manager_log=/usr/local/mha/manager.log
> repl_user=slave
> repl_password=123@Coral
>
> [server1]
> hostname=192.168.1.20
>
> [server2]
> hostname=192.168.1.30
>
> [server3]
> hostname=192.168.1.40
>
> EOF

MHA各节点的SSH以及复制健康检测

[root@db-one bin]# masterha_check_ssh  --conf=/etc/mha/mha.conf
Wed Jun 22 03:07:37 2016 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Wed Jun 22 03:07:37 2016 - [info] Reading application default configuration from /etc/mha/mha.conf..
Wed Jun 22 03:07:37 2016 - [info] Reading server configuration from /etc/mha/mha.conf..
Wed Jun 22 03:07:37 2016 - [info] Starting SSH connection tests..
Wed Jun 22 03:07:38 2016 - [debug]
Wed Jun 22 03:07:37 2016 - [debug]  Connecting via SSH from root@192.168.1.20(192.168.1.20:22) to root@192.168.1.30(192.168.1.30:22)..
Wed Jun 22 03:07:37 2016 - [debug]   ok.
Wed Jun 22 03:07:37 2016 - [debug]  Connecting via SSH from root@192.168.1.20(192.168.1.20:22) to root@192.168.1.40(192.168.1.40:22)..
Wed Jun 22 03:07:38 2016 - [debug]   ok.
Wed Jun 22 03:07:38 2016 - [debug]
Wed Jun 22 03:07:38 2016 - [debug]  Connecting via SSH from root@192.168.1.30(192.168.1.30:22) to root@192.168.1.20(192.168.1.20:22)..
Wed Jun 22 03:07:38 2016 - [debug]   ok.
Wed Jun 22 03:07:38 2016 - [debug]  Connecting via SSH from root@192.168.1.30(192.168.1.30:22) to root@192.168.1.40(192.168.1.40:22)..
Wed Jun 22 03:07:38 2016 - [debug]   ok.
Wed Jun 22 03:07:39 2016 - [debug]
Wed Jun 22 03:07:38 2016 - [debug]  Connecting via SSH from root@192.168.1.40(192.168.1.40:22) to root@192.168.1.20(192.168.1.20:22)..
Wed Jun 22 03:07:38 2016 - [debug]   ok.
Wed Jun 22 03:07:38 2016 - [debug]  Connecting via SSH from root@192.168.1.40(192.168.1.40:22) to root@192.168.1.30(192.168.1.30:22)..
Wed Jun 22 03:07:39 2016 - [debug]   ok.
Wed Jun 22 03:07:39 2016 - [info] All SSH connection tests passed successfully.

[root@db-one bin]# masterha_check_repl  --conf=/etc/mha/mha.conf
Wed Jun 22 03:20:44 2016 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Wed Jun 22 03:20:44 2016 - [info] Reading application default configuration from /etc/mha/mha.conf..
Wed Jun 22 03:20:44 2016 - [info] Reading server configuration from /etc/mha/mha.conf..
Wed Jun 22 03:20:44 2016 - [info] MHA::MasterMonitor version 0.56.
Wed Jun 22 03:20:51 2016 - [info] GTID failover mode = 1
Wed Jun 22 03:20:51 2016 - [info] Dead Servers:
Wed Jun 22 03:20:51 2016 - [info] Alive Servers:
Wed Jun 22 03:20:51 2016 - [info]   192.168.1.20(192.168.1.20:3306)
Wed Jun 22 03:20:51 2016 - [info]   192.168.1.30(192.168.1.30:3306)
Wed Jun 22 03:20:51 2016 - [info]   192.168.1.40(192.168.1.40:3306)
Wed Jun 22 03:20:51 2016 - [info] Alive Slaves:
Wed Jun 22 03:20:51 2016 - [info]   192.168.1.30(192.168.1.30:3306)  Version=5.7.13-log (oldest major version between slaves) log-bin:enabled
Wed Jun 22 03:20:51 2016 - [info]     GTID ON
Wed Jun 22 03:20:51 2016 - [info]     Replicating from 192.168.1.20(192.168.1.20:3306)
Wed Jun 22 03:20:51 2016 - [info]   192.168.1.40(192.168.1.40:3306)  Version=5.7.13-log (oldest major version between slaves) log-bin:enabled
Wed Jun 22 03:20:51 2016 - [info]     GTID ON
Wed Jun 22 03:20:51 2016 - [info]     Replicating from 192.168.1.20(192.168.1.20:3306)
Wed Jun 22 03:20:51 2016 - [info] Current Alive Master: 192.168.1.20(192.168.1.20:3306)
Wed Jun 22 03:20:51 2016 - [info] Checking slave configurations..
Wed Jun 22 03:20:51 2016 - [info]  read_only=1 is not set on slave 192.168.1.30(192.168.1.30:3306).
Wed Jun 22 03:20:51 2016 - [info]  read_only=1 is not set on slave 192.168.1.40(192.168.1.40:3306).
Wed Jun 22 03:20:51 2016 - [info] Checking replication filtering settings..
Wed Jun 22 03:20:51 2016 - [info]  binlog_do_db= , binlog_ignore_db=
Wed Jun 22 03:20:51 2016 - [info]  Replication filtering check ok.
Wed Jun 22 03:20:51 2016 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Wed Jun 22 03:20:51 2016 - [info] Checking SSH publickey authentication settings on the current master..
Wed Jun 22 03:20:51 2016 - [info] HealthCheck: SSH to 192.168.1.20 is reachable.
Wed Jun 22 03:20:51 2016 - [info]
192.168.1.20(192.168.1.20:3306) (current master)
 +--192.168.1.30(192.168.1.30:3306)
 +--192.168.1.40(192.168.1.40:3306)

Wed Jun 22 03:20:51 2016 - [info] Checking replication health on 192.168.1.30..
Wed Jun 22 03:20:51 2016 - [info]  ok.
Wed Jun 22 03:20:51 2016 - [info] Checking replication health on 192.168.1.40..
Wed Jun 22 03:20:51 2016 - [info]  ok.
Wed Jun 22 03:20:51 2016 - [warning] master_ip_failover_script is not defined.
Wed Jun 22 03:20:51 2016 - [warning] shutdown_script is not defined.
Wed Jun 22 03:20:51 2016 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.

启动MHA以及停止MHA等操作
启动:
[root@db-one bin]# nohup masterha_manager –conf=/etc/mha/mha.conf &
[1] 7206
[root@db-one bin]# nohup: ignoring input and appending output to `nohup.out’

[root@db-one MHA]# nohup masterha_manager –conf=/etc/mha/mha.conf –ignore_last_failover –remove_dead_master_conf & #mha默认8h内连续检测到宕机,则不会自动Failover

关闭:
[root@db-one mha]# masterha_stop –conf=/etc/mha/mha.conf
Stopped mha successfully.

STATUS:
[root@db-one mha]# masterha_check_status –conf=/etc/mha/mha.conf
mha (pid:4720) is running(0:PING_OK), master:192.168.1.20

模拟MHA的Failover
停止现master节点服务
[root@db-two ~]#/etc/init.d/mysqld stop
MHA的manager节点日志信息如下
—– Failover Report —–

mha: MySQL Master failover 192.168.1.20(192.168.1.20:3306) to 192.168.1.30(192.168.1.30:3306) succeeded

Master 192.168.1.20(192.168.1.20:3306) is down!

Check MHA Manager logs at db-one for details.

Started automated(non-interactive) failover.
Selected 192.168.1.30(192.168.1.30:3306) as a new master.
192.168.1.30(192.168.1.30:3306): OK: Applying all logs succeeded.
192.168.1.40(192.168.1.40:3306): OK: Slave started, replicating from 192.168.1.30(192.168.1.30:3306)
192.168.1.30(192.168.1.30:3306): Resetting slave info succeeded.
Master failover to 192.168.1.30(192.168.1.30:3306) completed successfully.

(over)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值