keepalived+双主架构部署

keepalived+双主架构部署,第1张

概述在高可用集群环境中,keepalived使用的是VIP,利用keepalived自带的服务监控功能和自定义脚本来实现MYSQL故障时自带切换。 Keepalived基于VRRP协议,虚拟冗余路由协议,

在高可用集群环境中,keepalived使用的是VIP,利用keepalived自带的服务监控功能和自定义脚本来实现MysqL故障时自带切换。

Keepalived基于VRRP协议,虚拟冗余路由协议,所谓vrrp的优先级就是它会根据优先级来确定其他在集群中的地位,用0-255来表示,数字越小则表示优先级越低,数值越大表示优先级越高。当值为0,代表着master放弃持有VIP;该值为255时,表示当前master的优先级最高并蚩尤VIP。

1、      搭建GTID+row模式双主环境此处参照以前论坛内容:

http://www.cnblogs.com/hmwh/p/9011377.HTML

https://www.cnblogs.com/hmwh/p/9011377.HTML

1.2.     分别再主备库上创建同步账号

创建主从复制账号

create user 'rep'@'172.16.20.%' IDentifIEd by 'MysqL';

grant replication slave on *.* to 'rep'@'172.16.20.%';

show grants for 'rep'@'172.16.20.%';

flush privileges;

所有主机创建管理账号:

create user 'zs'@'172.16.20.%' IDentifIEd by '123456';

grant all privileges on *.* to 'zs'@'172.16.20.%';

flush privileges;

配置主从复制:

change master to master_host='172.16.20.32',master_port=3307,master_user='rep',master_password='MysqL',master_auto_position=1;

star slave;

show slave status\G;

无问题后再在主库配置复制关系:

change master to master_host='172.16.20.34',master_auto_position=1;

start salve;

show slave status\G;

1.3分别安装keepalived软件包

由于我的没有keepalived包

yum install keepalived

 下载地址:

href="http://rpmfind.net/linux/rpm2HTML/search.PHP?query=keepalived&submit=%E6%90%9C%E7%B4%A2...+&system=&arch">http://rpmfind.net/linux/rpm2HTML/search.PHP?query=keepalived&submit=%E6%90%9C%E7%B4%A2...+&system=&arch=

rpm -ivh keepalived-1.2.13-5.el6_6.x86_64.rpm

 

1.4配置MysqL数据库检测脚本

两台服务器都配置检测脚本:内容根据情况自行修改

cd /etc/keepalived/

vim checkMysqL.sh

内容如下:

#!/bin/bash

MysqLstr=/usr/local/MysqL5.7/bin/MysqL

host=172.16.2.32

user=zs

password=123456

port=3307

#####MysqL service machine status health is 1,others 0

MysqL_status=1

#####check MysqL status#########

$MysqLstr -h $host -u $user -p$password -P $port -e "show status;" > /dev/null 2>&1

    if [ $? = 0 ];then

         echo "MysqL_status=1"

        exit 0

    else

/etc/init.d/keepalived stop

fi

chmod 775 checkMysqL.sh

1.5两台机器上修改keepalived配置文件

主库的:

vim keepalived.conf

vrrp_script vs_MysqL_100 {

     script "/etc/keepalived/checkMysqL.sh"

     interval 10

}

vrrp_instance VI_100 {

    state BACKUP

    nopreempt

    interface eth0

    virtual_router_ID 100

    priority 100     --注意,30的为100,34的为90。

    advert_int 5

    authentication {

        auth_type PASS

        auth_pass 1314

    }

track_script {

    vs_MysqL_100

   

}

 virtual_ipaddress {

        172.16.20.30

    }

}

备库的:

vim keepalived.conf

vrrp_script vs_MysqL_101 {

     script "/etc/keepalived/checkMysqL.sh"

     interval 10

}

vrrp_instance VI_101 {

    state BACKUP

    nopreempt

    interface eth0

    virtual_router_ID 100

    priority 90

    advert_int 5

    authentication {

        auth_type PASS

        auth_pass 1314

    }

track_script {

    vs_MysqL_101

   

}

 virtual_ipaddress {

        172.16.20.30

    }

}

1.6 启动keepalived

32服务器先启动。

/etc/init.d/keepalived start

/etc/init.d/keepalived status

ps -ef |grep keep

 

tail -100f /var/log/messages

 

172.16.20.32优先级高,keepalived的状态已经由backup升级为master。

ip addr

 

34服务器启动keepalived进程:

/etc/init.d/keepalived start

/etc/init.d/keepalived status

ps -ef |grep keep

tail -100f /var/log/messages

 

查看日志为backup 模式

管理用户测试登陆:

 

 

查看的UUID为主库32的。

 

备库keepalived 启动了,并没有VIP。

 1.7故障演练

关闭32。

可以看到VIP飘到34服务器上。

 

且keepalived状态由backup升级为master。

 

总结

以上是内存溢出为你收集整理的keepalived+双主架构部署全部内容,希望文章能够帮你解决keepalived+双主架构部署所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1169352.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)