MySQL+Keepalived实现主主高可用方案

Mysql主主高可用方案

master配置

[[email protected] ~]# yum -y install keepalived

[[email protected] ~]# vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived

 

global_defs {

        router_id LVS_MASTER-A

 

}

vrry_script mysql {

        script "/opt/mysql.sh"

        interval 2

        weight -5

        fall 2

        rise 1

}

 

vrrp_instance VI_1 {

    state MASTER

    interface ens33

    virtual_router_id 51

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

        track_script {

                mysql

        }

    virtual_ipaddress {

        192.168.200.210

    }

}

}

[[email protected] ~]# vim /opt/mysql.sh

#!/bin/bash

counter=$(netstat -na |grep "LISTEN" |grep "3306" |wc -l)

if [ "${counter}" -eq 0 ]

        then

        systemctl stop keepalived

fi

~     

[[email protected] ~]# chmod +x /opt/mysql.sh

[[email protected] ~]# systemctl start keepalived

2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

    inet 192.168.30.25/24 brd 192.168.30.255 scope global noprefixroute ens33

    inet 192.168.200.210/32 scope global ens33

 

[[email protected] ~]# tail -f /var/log/messages

 

Apr  9 15:36:43 master ntpd_intres[3721]: host name not found: 0.centos.pool.ntp.org

Apr  9 15:36:43 master ntpd_intres[3721]: host name not found: 1.centos.pool.ntp.org

Apr  9 15:36:43 master ntpd_intres[3721]: host name not found: 2.centos.pool.ntp.org

Apr  9 15:36:43 master ntpd_intres[3721]: host name not found: 3.centos.pool.ntp.org

Apr  9 15:36:45 master Keepalived_vrrp[9706]: Sending gratuitous ARP on ens33 for 192.168.200.210

Apr  9 15:36:45 master Keepalived_vrrp[9706]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on ens33 for 192.168.200.210

Apr  9 15:36:45 master Keepalived_vrrp[9706]: Sending gratuitous ARP on ens33 for 192.168.200.210

Apr  9 15:36:45 master Keepalived_vrrp[9706]: Sending gratuitous ARP on ens33 for 192.168.200.210

Apr  9 15:36:45 master Keepalived_vrrp[9706]: Sending gratuitous ARP on ens33 for 192.168.200.210

Apr  9 15:36:45 master Keepalived_vrrp[9706]: Sending gratuitous ARP on ens33 for 192.168.200.210

Apr  9 15:40:01 master systemd: Started Session 40 of user root.

Apr  9 15:40:01 master systemd: Starting Session 40 of user root.

 

 

 

 

第二台master2从

[[email protected] ~]# yum -y install keepalived

[[email protected] ~]# vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived

 

global_defs {

        router_id LVS_MASTER-B

 

}

vrry_script mysql {

        script "/opt/mysql.sh"

        interval 2

        weight -5

        fall 2

        rise 1

}

 

vrrp_instance VI_1 {

    state BACKUP

    interface ens33

    virtual_router_id 51

    priority 90

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

        track_script {

                mysql

        }

    virtual_ipaddress {

        192.168.200.210

    }

}

}

 

测试VIP转移

[[email protected] ~]# vim /opt/mysql.sh

#!/bin/bash

counter=$(netstat -na |grep "LISTEN"|grep "3306" |wc -l)

if [ "${counter}" -eq 0 ]

        then

                systemctl stop keepalived

fi

[[email protected] ~]# chmod +x /opt/mysql.sh

[[email protected] ~]# systemctl start keepalived

[[email protected] ~]# tail -f /var/log/messages

[[email protected] ~]# systemctl stop mariadb

[[email protected] ~]# ip a |grep ens33

[[email protected] ~]# ip a |grep ens33

2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

    inet 192.168.30.25/24 brd 192.168.30.255 scope global noprefixroute ens33

2,在远程客户端 测试

Mysql 服务器授权

[[email protected] ~]# mysql -uroot

MariaDB [(none)]> grant all on *.* to ‘root‘@‘192.168.30.%‘identified by ‘123456‘;

MariaDB [(none)]> flush privileges;

 

通过vip 登陆测试

[[email protected] ~]# mysql -uroot -p123456 -h 192.168.30.210;

MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sampdb             |

| test               |

| test01             |

| test02             |

+--------------------+

 

原文地址:https://www.cnblogs.com/zc1741845455/p/10921254.html

时间: 2024-11-01 19:44:50

MySQL+Keepalived实现主主高可用方案的相关文章

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高可用探究(二)Lvs+Keepalived+Mysql单点写入主主同步高可用方案

global_defs {   notification_email {        [email protected] } notification_email_from [email protected] smtp_server smtp.mail.sina.com smtp_connect_timeout 30 router_id LVS1 }   vrrp_sync_group test { group { loadbalance } }   vrrp_instance loadbal

MySQL高可用方案——双主

MySQL的高可用方案有很多种,双主.MHA.MMM等等,这里只是写下最简单的双主这种高可用方案. 一.配置MySQL互为主从 1.环境准备 系统 IP 主机名 服务 Centos 7.5 192.168.20.2 mysql01 MySQL+keepalived Centos 7.5 192.168.20.3 mysql02 MySQL+keepalived 注:MySQL已部署完成,可参考博文Centos部署MySQL 5.7进行部署. 2.开启二进制日志及中继日志 #主机mysql01配置

MySQL高可用方案探究

来自 http://bbs.chinaunix.net/thread-3769165-1-1.html 最近花了点时间研究了一下mysql的高可用,总结成文档,希望对初学这有帮助. Lvs+Keepalived+Mysql单点写入主主同步高可用方案 http://blog.chinaunix.net/uid-20639775-id-3337448.html Lvs+Keepalived+Mysql单点写入读负载均衡主主同步高可用方案 http://blog.chinaunix.net/uid-2

[转]MYSQL高可用方案探究(总结)

前言 http://blog.chinaunix.net/uid-20639775-id-3337432.htmlLvs+Keepalived+Mysql单点写入主主同步高可用方案 http://blog.chinaunix.net/uid-20639775-id-3337448.htmlLvs+Keepalived+Mysql单点写入读负载均衡主主同步高可用方案http://blog.chinaunix.net/uid-20639775-id-3337471.htmlHeartbeat高可用M

Keepalived配置实现HaProxy高可用

这次,小编就先写一篇对Keepalived的配置,那么在学习之前,我们首先要了解Keepalived是什么,以及为什么要用Keepalived. 实际上,Keepalived不仅仅是实现HaProxy的高可用,小编这里只是拿HaProxy来做一个示例而已,根据这个示例,进行稍微的改动基本就可以实现其他服务的高可用. 在此之前,小编就先来说说为什么要用Keepalived来实现负载均衡器高可用,小编这里只拿HaProxy负载均衡器来进行说明: 对于所有懂运维的小伙伴来说,都应该知道,无论后端的服务

企业级应用,持久层架构方案二(双主同步高可用二)

这是企业级应用,持久层架构方案的第二篇.在上一篇:企业级应用,持久层架构方案一(双主同步高可用)中.已经准备好了两台mysql数据库节点:hadoop001.hadoop002.两个节点互为主备,实现舒双主同步高可用,如何叫做双主同步高可用呢?其实要分为两个问题:一个是双主同步,互为主备:另一个是高可用.那么在上一篇中已经实现了双主互为主备,本篇通过keepalived虚拟ip实现高可用: 1.安装keepalived 1.1.hadoop001节点 #安装keepalived yum inst

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