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

Centos7.5安装mysql5.7.24二进制包方式部署(keepalived+主从复制)

时间:2018-11-26 00:02:43      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:5.7   counter   vim   zabbix   zab   脚本   virt   .com   add   

一、环境准备:

操作系统:CentOS Linux release 7.5.1804 (Core)
mysql版本:mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
主库:172.16.8.247
从库:172.16.8.249
主机名:
172.16.8.247 qas-zabbix-node01
172.16.8.249 qas-zabbix-node02
172.16.8.248 vip

二、mysql5.7安装及主从复制配置

主库:172.16.8.247
从库:172.16.8.249
数据安装参考:
一、Centos7.5安装mysql5.7.24二进制包方式部署
二、Centos7.5安装mysql5.7.24二进制包方式部署(主从复制)

三、Keepalived概述

Keepalived 是一个可以快速构建高用服务的解决方案。设计之初针对 LVS 负载均衡提供高可用 的,它集成对 LVS 集群管理,包括健康检查、故障剔除等功能。
Keepalived 使用 VRRP

四 、Keepalived安装及配置

1、安装keepalived

主库、从库都需要安装
yum -y install keepalived

2、 配置keeepalived配置文件(主库)

#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
    }
}
检查脚本
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、 配置keeepalived配置文件(从库)

# 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
    }
}

检查脚本
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

Centos7.5安装mysql5.7.24二进制包方式部署(keepalived+主从复制)

标签:5.7   counter   vim   zabbix   zab   脚本   virt   .com   add   

原文地址:http://blog.51cto.com/10880347/2321855

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