[Posts] [MySQL] + keepalived keepalived implemented with MySQL master master mode availability

MySQL keepalived] + [HA keepalived implemented with MySQL master master mode

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

 

First, the experiments show

MySQL master main mode, is mainly from two mutually MySQL database.

This experiment is to achieve the main MySQL master mode with keepalived high availability, based on already installed MySQL master host architecture, and then configure keepalived, verify high availability!

 

 

Second, the experimental environment

Operating System: CentOS 7.5 

Server: 192.168.1.104

serverB: 192.168.1.105

VIP: 192.168.1.110

Third, turn off selinux

# setenforce 0

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

Fourth, the firewall settings

and a second election firewalld iptables

 

Fifth, software installation

In serverA and serverB

#  yum  -y install epel-release

# yum -y install keepalived

 

Sixth, in serverA configuration 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

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/11757890.html
Recommended