• keepalived+双主架构部署


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

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

    1、      搭建GTID+row模式双主环境

    IP

    主机名

    作用

    数据库版本

    操作系统版本

    172.16.20.32

    mastera

    master

    Mysql5.7.20

    Redhat6.7

    172.16.20.34

    masterb

    master

    Mysql5.7.20

    Redhat6.7

    172.16.20.30

     

    VIP

     

     

    1.1.     MySQL GTID环境安装

    此处参照以前论坛内容:

    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;

    start slave;

    show slave statusG;

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

    change master to master_host='172.16.20.34',master_port=3307,master_user='rep',master_password='mysql',master_auto_position=1;

    start salve;

    show slave statusG;

    1.3分别安装keepalived软件包

    由于我的没有keepalived包

    yum install keepalived

     下载地址:

    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。

     

  • 相关阅读:
    Java实现判断单联通(强连通缩点+拓扑排序)Going from u to v or from v to u
    Java实现判断单联通(强连通缩点+拓扑排序)Going from u to v or from v to u
    Java实现判断单联通(强连通缩点+拓扑排序)Going from u to v or from v to u
    Java实现判断单联通(强连通缩点+拓扑排序)Going from u to v or from v to u
    判断一个窗体是否被完全遮挡(比较有意思,但这招有什么用呢?)
    Delphi中用MessageBox()API函数做倒计时对话框(使用Hook安装CBTHookCallback,计时器更改文字,SetWindowText API真正修改文字,引用未知函数)good
    Delphi&C#代码模拟“显示桌面”的功能(使用CreateOleObject('Shell.Application'))
    LLVM和GCC的区别(LLVM提供了模块化的编译模块,非常有利于重用,以前的编译器都没有做到这一点)
    Delphi产生任务栏图标【TNotifyIconData】
    国内外10大项目外包平台
  • 原文地址:https://www.cnblogs.com/hmwh/p/9285106.html
Copyright © 2020-2023  润新知