CentOS 7.5 installs mysql5.7.24 binary package deployment (maintained + master-slave replication)

Keywords: Linux vim MySQL CentOS

I. environmental preparation:

Operating system: CentOS Linux release 7.5.1804 (Core)
MySQL version: mysql-5.7.24-linux-glibc2.12-x86_.tar.gz
Main warehouse: 172.16.8.247
Slave Library: 172.16.8.249
Host name:
172.16.8.247 qas-zabbix-node01
172.16.8.249 qas-zabbix-node02
172.16.8.248 vip

2. mysql5.7 installation and master-slave replication configuration

Main warehouse: 172.16.8.247
Slave Library: 172.16.8.249
Data installation reference:
I. CentOS 7.5 installs mysql5.7.24 in binary package mode
II. CentOS 7.5 installs mysql5.7.24 binary package deployment (master-slave replication)

III. overview of preserved

Keepalived is a solution that can quickly build high-use services. At the beginning of design, it provides high availability for LVS load balancing. It integrates LVS cluster management, including health check, fault elimination and other functions.
Keepalived using VRRP

IV. installation and configuration of preserved

1. Install keepalived

Both master and slave libraries need to be installed
yum -y install keepalived

2. Configure keeepalive configuration file (main database)

#vim /etc/keepalived/keepalived.conf 

global_defs {
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id mysql-247
}
vrrp_script chk_mysql {
   script "/etc/keepalived/scripts/mysql_check.sh"
   interval 2
   weight -5
   fall 2
   rise 1
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 61
    priority 100
    advert_int 1
    nopreempt
    authentication {
        auth_type PASS
        auth_pass 2222
    }
       track_script {
       chk_mysql
    }
    virtual_ipaddress {
        172.16.8.248
    }
}
//Check script
vim /etc/keepalived/scripts/mysql_check.sh
#!/bin/bash
counter=$(netstat -na|grep "LISTEN"|grep "3306"|wc -l)
if [ "${counter}" -eq 0 ]; then
    service keepalived stop
fi

3. Configure keeepalive configuration file (slave)

# vim /etc/keepalived/keepalived.conf 

global_defs {
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id mysql-249
}

vrrp_script chk_mysql {
   script "/etc/keepalived/scripts/mysql_check.sh"
   interval 2
   weight -5
   fall 2
   rise 1
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 61
    priority 99
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 2222
    }
    track_script {
    chk_mysql
    }
    virtual_ipaddress {
        172.16.8.248
    }
}

//Check script
vim /etc/keepalived/scripts/mysql_check.sh
#!/bin/bash
counter=$(netstat -na|grep "LISTEN"|grep "3306"|wc -l)
if [ "${counter}" -eq 0 ]; then
    service keepalived stop
fi

Posted by Xurion on Sat, 07 Dec 2019 21:09:55 -0800