MHA+mysql5.7高可用部署

MHA+mysql5.7高可用部署

/ 0 评 / 0

软件:
mysql5.7
mha4mysql-manager-0.58

存放 /data/software/

部署:
一、 mysql5.7 一主二从
mysql安装略
1、 三 个 mysql 节点做主从复制授权
mysql> grant replication slave on . to ‘mysql’@’192.168.X.%’ identified by ‘passwd’;
mysql> grant all on . to ‘root’@’192.168.X.%’ identified by ‘passwd’;

2、 在两个salve节点上执行,只读限制

3、 主master

4、 两个slave节点执行

mysql> start slave;

二、 MHA环境和安装
1、 配置三台机器的ssh互信
ssh-keygen -t rsa
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.2.50
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.2.51
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.2.52

2、 MHA安装

三节点安装依赖

wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

rpm -ivh epel-release-latest-7.noarch.rpm

三节点部署node

rpm -ivh mha4mysql-node-0.58-0.el7.centos.noarch.rpm

master节点部署manager

rpm -ivh mha4mysql-manager-0.58-0.el7.centos.noarch.rpm

全局配置文件

/etc/masterha_default.cnf

scp 192.168.8.59:/data/software/masterha_default.cnf /etc/

修改账号密码ip

主配置文件

/etc/mha/app1.cnf

修改账号密码ip

配置VIP

/etc/mha/master_ip_failover

scp 192.168.8.59:/data/software/master_ip_failover /etc/mha/

定义VIP变量

my $vip = ‘192.168.2.49/24’;
my $key = ‘1’;

my $ssh_stop_vip = “/sbin/ifconfig em1:$key down”;

配置编写VIP脚本

/etc/mha/master_ip_online_change

服务的网卡识别名一样

stop_vip=echo "ssh root@$orig_master_host /usr/sbin/ifconfig em1:$key down" ##em1 网卡名

start_vip=echo "ssh root@$new_master_host /usr/sbin/ifconfig em1:$key $vip"

chmod +x /etc/mha/master_ip_failover chmod +x /etc/mha/master_ip_online_change

配置报警邮件(非必须)

yum install mailx

/etc/mha/mail.rc ## 8.59:/data/software/

/etc/mha/send_report

chmod +x /etc/mha/send_report

验证 mysql 主从复制是否成功

masterha_check_repl —conf=/etc/mha/app1.cnf (成功:MySQL Replication Health is OK.)

三、 启动MHA(注意:MHA监控脚本切换一次就会退出,需要再次启动)

ifconfig em1:1 192.168.2.49/24

nohup masterha_manager —conf=/etc/mha/app1.cnf —remove_dead_master_conf —ignore_last_failover < /dev/null > /opt/log/mha/app1/manager.log 2>&1 &

tail -f /opt/log/mha/app1/manager.log

启动成功 [info] Ping(SELECT) succeeded, waiting until MySQL doesn’t respond..

检查集群状态

masterha_check_status —conf=/etc/mha/app1.cnf

四、 切换测试

停MHA脚本

masterha_stop —conf=/etc/mha/app1.cnf

切换 master

masterha_master_switch —conf=/etc/mha/app1.cnf —master_state=alive —new_master_host=192.168.2.51 —orig_master_is_new_slave —running_updates_limit=10000 —interactive=0

故障master重新加入集群

修复故障老的 master,设置为 slave (新master 2.51)

mysql> change master to master_host=’192.168.2.51’,master_user=’mysql’,master_password=’passwd’,master_log_file=’mysql-bin.0000X’,master_log_pos=XXX;

mysql> start slave;

在新manger 节点上重新启动监控进程

nohup masterha_manager —conf=/etc/mha/app1.cnf —remove_dead_master_conf —ignore_last_failover < /dev/null > /opt/log/mha/app1/manager.log 2>&1 &

五、 从1和从2之间的切换

192.168.2.50 主
192.168.2.51 从1 (自用读库)

六、从1和从2之间,使用keepalive+vip, 如从2业务读库宕机后,vip 自动漂移 从1 自用读库

安装keepalived

wget http://www.keepalived.org/software/keepalived-1.2.13.tar.gz
yum -y install popt-*
./configure —prefix=/usr/local/keepalived —enable-snmp
make && make install
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
chmod +x /etc/rc.d/init.d/keepalived
chkconfig keepalived on
mkdir /etc/keepalived

编辑 /etc/keepalived/keepalived.conf

创建check_mysql.sh ,master_sh

模拟关闭(vip)上mysql,vip会进行飘移

发表评论

电子邮件地址不会被公开。 必填项已用*标注