码迷,mamicode.com
首页 > 数据库 > 详细

[转帖]【MySQL+keepalived】用keepalived实现MySQL主主模式的高可用

时间:2019-11-01 10:00:05      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:ddr   关闭   firewalld   div   mct   mod   tar   fir   配置   

【MySQL+keepalived】用keepalived实现MySQL主主模式的高可用

https://www.jianshu.com/p/8694d07595bc

 

一、实验说明

MySQL主主模式,是两台MySQL数据库互为主从。

此实验是用keepalived实现MySQL主主模式的高可用,基于已经安装好了主主架构的MySQL,然后配置keepalived,验证高可用性!

 

 
技术图片

二、实验环境

操作系统:CentOS 7.5 

serverA:192.168.1.104

serverB: 192.168.1.105

VIP: 192.168.1.110

三、关闭selinux

# setenforce 0

# sed -i ‘s/^SELINUX=.*/SELINUX=permissive/g‘  /etc/selinux/config

四、防火墙设置

firewalld和iptables二选一

 
技术图片

五、软件安装

在serverA和serverB

#  yum  -y install epel-release

# yum -y install keepalived

 

六、在serverA配置keepalived

# vim  /etc/keepalived/keepalived.conf

###########################################

! Configuration File for keepalived

global_defs {

  router_id LVS_DEVEL

}

vrrp_instance VI_1 {

    state BACKUP

    interface ens33

    virtual_router_id 150

    priority 100

    advert_int 1

    nopreempt

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

        192.168.1.110/24

    }

}

virtual_server 192.168.1.110 3306 {

    delay_loop 2

    lb_algo rr

    lb_kind DR

    persistence_timeout 50

    protocol TCP

    real_server 192.168.1.104 3306 {

        weight 3

        notify_down /etc/keepalived/restartKeepalived.sh

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

        }

    }

}

###################################################

 
技术图片

 

# vim /etc/keepalived/restartKeepalived.sh

#################################

#!/bin/bash

systemctl restart keepalived

##################################

 

 
技术图片

# chmod 700 /etc/keepalived/restartKeepalived.sh

 

七、在serverB配置keepalived

在serveB

# vim  /etc/keepalived/keepalived.conf

###########################################

! Configuration File for keepalived

global_defs {

  router_id LVS_DEVEL

}

vrrp_instance VI_1 {

    state BACKUP

    interface ens33

    virtual_router_id 150

    priority 90

    advert_int 1

    nopreempt

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

        192.168.1.110/24

    }

}

virtual_server 192.168.1.110 3306 {

    delay_loop 2

    lb_algo rr

    lb_kind DR

    persistence_timeout 50

    protocol TCP

real_server 192.168.1.105 3306 {

        weight 3

 notify_down /etc/keepalived/restartKeepalived.sh

        TCP_CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

        }

    }

}

###################################################

 

 
技术图片

# vim /etc/keepalived/restartKeepalived.sh

#################################

#!/bin/bash

systemctl restart keepalived

##################################

 

 
技术图片

# chmod 700 /etc/keepalived/restartKeepalived.sh

八、验证MySQL的高可用性

在serverA 

# ip addr list 

 

 
技术图片

# systemctl stop mysqld

在serverB

# ip addr list 

 
技术图片

从上可以看出,关闭serverA上的MySQL,vip成功漂移到了severB,数据库的连接不受影响,实现了一定程度的高可用。

两个注意点:

1. 具体通过vip连接到serverA或者severB 时,服务器上的vip才监听3306端口,无连接时,不监听

 

 
技术图片

2. vip在serverA时,在severB上无法通过vip连接上数据库,反之亦然

 

 
技术图片
 
技术图片

 

九、参考

keepalived + mysql 实现单向备份、故障转移

https://www.jianshu.com/p/35030921dab5

Centos7+Keepalived实现Mariadb(MYSQL)的高可用(HA)

http://blog.51cto.com/gaowenlong/1888036

[转帖]【MySQL+keepalived】用keepalived实现MySQL主主模式的高可用

标签:ddr   关闭   firewalld   div   mct   mod   tar   fir   配置   

原文地址:https://www.cnblogs.com/jinanxiaolaohu/p/11757890.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!