keepalived+MySQL主主高可用

keepalived+MySQL主主高可用

一、环境介绍:

10.1.1.174:23316 M1
10.1.1.237:23316 M2

二、配置双主:略。

三、keepalive安装

[[email protected] ~]# cd /usr/local/src/

[[email protected] src]# wget https://www.keepalived.org/software/keepalived-2.0.17.tar.gz

[[email protected] src]# tar -xf keepalived-2.0.17.tar.gz

[[email protected] src]# cd keepalived-2.0.17

[[email protected] keepalived-2.0.17]# yum install openssl* libnl‐dev* gcc-c++

[[email protected] keepalived-2.0.17]# ./configure --prefix=/usr/local/keepalived

[[email protected] keepalived-2.0.17]# make

[[email protected] keepalived-2.0.17]# make install
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
echo "/etc/init.d/keepalived start" >> /etc/rc.local
mkdir -p  /etc/keepalived/
mv /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
M1:keepalive配置文件:
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived

vrrp_script chk_mysql_port {     #检测mysql服务是否在运行。有很多方式,比如进程,用脚本检测等等
    script "/etc/keepalived/chk_mysql.sh"   #这里通过脚本监测
    interval 2                   #脚本执行间隔,每2s检测一次
    weight -5                    #脚本结果导致的优先级变更,检测失败(脚本返回非0)则优先级 -5
    fall 2                    #检测连续2次失败才算确定是真失败。会用weight减少优先级(1-255之间)
    rise 1                    #检测1次成功就算成功。但不修改优先级
}

vrrp_instance VI_1 {
    state MASTER
    interface ens192      #指定虚拟ip的网卡接口,改成你自己的 eth0或者其它什么的
   # mcast_src_ip 10.1.1.174
    virtual_router_id 51    #路由器标识,MASTER和BACKUP必须是一致的
    priority 101            #定义优先级,数字越大,优先级越高,在同一个vrrp_instance下,MASTER的优先级必须大于BACKUP的优先级。这样MASTER故障恢复后,就可以将VIP资源再次抢回来
    unicast_src_ip  10.1.1.174 ##(本地IP地址)
    unicast_peer {
                  10.1.1.237 ##(对端IP地址)此地址一定不能忘记
                       }
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.1.1.111
    }

track_script {
   chk_mysql_port
}
}
[[email protected] ~]# cat /etc/keepalived/chk_mysql.sh         #####注意可执行权限
#!/bin/bash
counter=$(netstat -na|grep "LISTEN"|grep "23316"|wc -l)
if [ "${counter}" -eq 0 ]; then
    /etc/init.d/keepalived stop
fi
M2:keepalived配置文件:
[[email protected]#localhost keepalived]# cat keepalived.conf
! Configuration File for keepalived

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

vrrp_instance VI_1 {
    state BACKUP
    interface ens192             #指定虚拟ip的网卡接口,改成你自己的 eth0或者其它什么的
    #mcast_src_ip 10.1.1.237
    virtual_router_id 51
    priority 90
    unicast_src_ip  10.1.1.237 ##(本地IP地址)
    unicast_peer {
                  10.1.1.174       ##(对端IP地址)此地址一定不能忘记
                       }
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.1.1.111
    }

track_script {
   chk_mysql_port
}
}

[[email protected]#localhost keepalived]# cat chk_mysql.sh           #####注意可执行权限
#!/bin/bash
counter=$(netstat -na|grep "LISTEN"|grep "23316"|wc -l)
if [ "${counter}" -eq 0 ]; then
    /etc/init.d/keepalived stop
fi
启动keepalived服务
[[email protected] ~]# /etc/init.d/keepalived start
常用命令:
/etc/init.d/keepalived restart|start|stop
/etc/init.d/mysqld restart|start|stop
查看keepalive状态:
systemctl status keepalived.service
查看日志:
tail -f /var/log/messages

四、可能出现的问题:

1.启动两个keepalived ,两边都有VIP。
我这个配置文件已经修改过,应该不会出现这个情况。
2.VIP起来后,无法通过VIP访问MySQL数据库。
关闭防火墙或者开放相关端口。
查看你的MySQL配置文件,看看有没有这个参数#bind-address = 10.1.1.237,有的话注释掉,重启数据库。

原文地址:https://blog.51cto.com/woniu123/2465006

时间: 2024-10-12 06:07:52

keepalived+MySQL主主高可用的相关文章

Keepalived+Mysql互为主从高可用安装配置

Keepalived+Mysql互为主从高可用安装配置环境介绍:keepalived_vip=192.168.1.210    (写虚拟ip)mysql_master01      eth0:192.168.1.211  eth1:172.20.27.211 (1核1G)mysql_master02      eth0:192.168.1.212  eth1:172.20.27.212 (1核1G) 1.安装mysql数据库(所有节点安装)  //此处省略安装mysql服务2.编辑my.cnf配

Lvs+Keepalived+MySQL Cluster架设高可用负载均衡Mysql集群

------------------------------------- 一.前言 二.MySQL Cluster基本概念 三.环境 四.配置 1.LB-Master及LB-Backup配置 2.MGM配置 3.SQL节点(SQL1和SQL2)配置 4.数据节点(NDB1和NDB2)配置 五.查看状态 六.测试 ------------------------------------- 一.前言 MySQL Cluster 是MySQL适合于分布式计算环境的高实用.高冗余版本.它采用了NDB

Keepalived MySQL master-master配置高可用

环境说明 OS:CentOS 6.5 X64 keepalived: keepalived-1.2.7.tar.gz 系统包

keepalived+mysql双主复制高可用方案

MySQL双主复制,即互为Master-Slave(只有一个Master提供写操作),可以实现数据库服务器的热备,但是一个Master宕机后不能实现动态切换.而Keepalived通过虚拟IP,实现了双主对外的统一接口以及自动检查.失败切换机制.联合使用,可以实现MySQL数据库的高可用方案. 实验环境:OS:centos 6.x x86_64系统MySQL版本: :mysql 5.6.22   64 位A: master :192.168.79.3 3306B: slave :192.168.

MySQL 高可用之 keepalived+Mysql 双主双活。

环境描述:[[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) [[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) IP 规划:MySQL-M 192.168.10.10 MySQL-S 192.168.10.20 配置两服务服务器双主: MySQL 安装: [[ema

MM(主主数据库)+keepalived主备高可用集群

博客分享的第一篇技术文章: 项目主要搭建:主主数据库高可用集群搭建. 数据库互为主备,应用技术:MM+keepalived 使用的是虚拟机搭建的实验向大家展示: 数据库1:192.168.4.7 数据库2:192.168.4.77 VIP:192.168.4.68 web1:192.168.4.69 web2:192.168.4.70 一.安装mysql,部署主主同步结构. 直接yum安装 配置主主同步: 由于主数据库192.168.4.7里面存放着数据,所以需要先导出数据,方法很多,我们采取m

Nginx+Keepalived 主备高可用 安装与配置

环境说明:操作系统:CentOS6.7 x86_64Nginx版本:nginx-1.9.7Keepalived版本:keepalived-1.2.24 主nginx + Keepalived :10.219.24.26备nginx + Keepalived :10.219.24.23虚拟IP:10.219.24.100后端tomcat_1:10.219.24.21:8080后端tomcat_2:10.219.24.21:8081 架构与原理: 前端双 Nginx + Keepalived ,Ng

keepalived+mysql双主

       mysql高可用keepalived+mysql双主 MySQL的高可用方案一般有如下几种: keepalived+双主,MHA,PXC,MMM,Heartbeat+DRBD等,比较常用的是keepalived+双主,MHA和PXC. 本节主要介绍了利用 keepalived 实现 MySQL 数据库的高可用. Keepalived+mysql双主来实现MySQL-HA,我们必须保证两台MySQL数据库的数据完全一样,基本思路是两台MySQL互为主从关系,通过Keepalived配

MySQL 高可用性之keepalived+mysql双主

生产环境中一台mysql主机存在单点故障,所以我们要确保mysql的高可用性,即两台MySQL服务器如果其中有一台MySQL服务器挂掉后,另外一台能立马接替其进行工作. MySQL的高可用方案一般有如下几种: keepalived+双主,MHA,PXC,MMM,Heartbeat+DRBD等,比较常用的是keepalived+双主,MHA和PXC. 这里将主要介绍了利用 keepalived 实现 MySQL数据库的高可用. Keepalived+mysql双主来实现MySQL-HA,我们必须保

MySQL 高可用性——keepalived+mysql双主(有详细步骤和全部配置项解释)

博主QQ:819594300 博客地址:http://zpf666.blog.51cto.com/ 有什么疑问的朋友可以联系博主,博主会帮你们解答,谢谢支持! 前言:生产环境中一台mysql主机存在单点故障,所以我们要确保mysql的高可用性,即两台MySQL服务器如果其中有一台MySQL服务器挂掉后,另外一台能立马接替其进行工作. MySQL的高可用方案一般有如下几种: keepalived+双主,MHA,PXC,MMM,Heartbeat+DRBD等,比较常用的是keepalived+双主,