Mysql主主高可用方案

master配置

[root@master ~]# yum -y install keepalived

[root@master ~]# 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

    }

}

}

[root@master ~]# vim /opt/mysql.sh

#!/bin/bash

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

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

        then

        systemctl stop keepalived

fi

~     

[root@master ~]# chmod +x /opt/mysql.sh

[root@master ~]# 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

 

[root@master ~]# 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从

[root@master1 ~]# yum -y install keepalived

[root@master1 ~]# 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转移

[root@master1 ~]# vim /opt/mysql.sh

#!/bin/bash

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

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

        then

                systemctl stop keepalived

fi

[root@master1 ~]# chmod +x /opt/mysql.sh

[root@master1 ~]# systemctl start keepalived

[root@master1 ~]# tail -f /var/log/messages

[root@master ~]# systemctl stop mariadb

[root@master ~]# ip a |grep ens33

[root@localhost ~]# 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 服务器授权

[root@localhost ~]# mysql -uroot

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

MariaDB [(none)]> flush privileges;

 

通过vip 登陆测试

[root@localhost ~]# mysql -uroot -p123456 -h 192.168.30.210;

MariaDB [(none)]> show databases;

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

| Database           |

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

| information_schema |

| mysql              |

| performance_schema |

| sampdb             |

| test               |

| test01             |

| test02             |

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

 

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

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

    MySQL双主复制,即互为Master-Slave(只有一个Master提供写操作),可以实现数据库服务器的热备,但是一个Master宕机后不能实现动态切换.而Keepalived通过虚拟IP,实现了 ...

  2. MySQL MGR+ Consul之数据库高可用方案

    背景说明:     基于目前存在很多MySQL数据库单点故障,传统的MHA,PXC等方案用VIP或者DNS切换的方式可以实现.基于数据库的数据强一致性考虑,采用MGR集群,采用consul服务注册发现 ...

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

    前言 http://blog.chinaunix.net/uid-20639775-id-3337432.htmlLvs+Keepalived+Mysql单点写入主主同步高可用方案 http://bl ...

  4. Linux下"负载均衡+高可用"集群的考虑点 以及 高可用方案说明(Keepalive/Heartbeat)

    当下Linux运维技术越来越受到企业的关注和追捧, 在某些企业, 尤其是牵涉到电子商务和电子广告类的网站,通常会要求作负载均衡和高可用的Linux集群方案.那么如何实施Llinux集群架构,才能既有效 ...

  5. 利用LVS+Keepalived搭建Mysql双主复制高可用负载均衡环境

    应用背景: MySQL复制(主主,主从...)能在保证数据的备份的同时也能够做读写分离分摊系统压力,但是发生单点故障时,需要手动 切换到另外一台主机.LVS和Keppalived可以设定一个VIP来实 ...

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

    环境说明:操作系统:CentOS6.7 x86_64Nginx版本:nginx-1.9.7Keepalived版本:keepalived-1.2.24 主nginx + Keepalived :10. ...

  7. MySQL高可用方案

    高可用架构对于互联网服务基本是标配,无论是应用服务还是数据库服务都需要做到高可用.虽然互联网服务号称7*24小时不间断服务,但多多少少有一些时候服务不可用,比如某些时候网页打不开,百度不能搜索或者无法 ...

  8. mysql高可用方案总结性说明

    MySQL的各种高可用方案,大多是基于以下几种基础来部署的(也可参考:Mysql优化系列(0)--总结性梳理   该文后面有提到)1)基于主从复制:2)基于Galera协议(PXC):3)基于NDB引 ...

  9. [转载] MySQL高可用方案选型参考

    原文: http://imysql.com/2015/09/14/solutions-of-mysql-ha.shtml?hmsr=toutiao.io&utm_medium=toutiao. ...

随机推荐

  1. 子序列 NYOJ (尺取法+队列+hash) (尺取法+离散化)

    子序列 时间限制:3000 ms  |  内存限制:65535 KB 难度:5   描述 给定一个序列,请你求出该序列的一个连续的子序列,使原串中出现的所有元素皆在该子序列中出现过至少1次. 如2 8 ...

  2. Android平台Airplay的实现方法

    Airplay属于局域网内异构设备之间分享多媒体数据的一种通信协议.Airplay设备有客户端和服务器之分,一般将小屏IOS设备实现为Airplay客户端,大屏幕设备实现为Airplay服务器.即iP ...

  3. Android - Error: &quot;java.io.IOException: setDataSource failed.: status=0x80000000&quot;

    Error: "java.io.IOException: setDataSource failed.: status=0x80000000" 本文地址: http://blog.c ...

  4. Linux(redhat 5.8)下 安装jetty 部署 使用

    首先须要安装JDK,自行解决 下载jetty安装包http://dist.codehaus.org/jetty/ 我下载的是8.1.15 tar -xzvf *.tar.gz 解压完之后,基本就能够用 ...

  5. luogu4218 [JSOI2008] 最小生成树计数

    题目大意 求一个加权无向图的最小生成树的个数.1<=n<=100; 1<=m<=1000,具有相同权值的边不会超过10条. 题解 命题1 由构成最小生成树的边的边权从小到大排序 ...

  6. inux内核模块编程入门

    linux内核模块编程入门 2013-07-06 23:59:54 分类: LINUX 原文地址:linux内核模块编程入门 作者:s270768095 模块编程属于内核编程,因此,除了对内核相关知识 ...

  7. 初识Java,Java语言概述

    Java语言是SUN(斯坦福大学网络公司)公司1995年推出的一门高级编程语言,由此James Gosling被公认为Java语言之父.Java语言起初运用在小型的家用电子产品上,后来随着互联网的发展 ...

  8. C语言程序创建文件夹

    #include <stdio.h> #include <process.h> #include <dir.h> int main(void) { int stat ...

  9. netty之ByteBuf详解

    [ChannelPromise作用:可以设置success或failure 是为了通知ChannelFutureListener]Netty的数据处理API通过两个组件暴露——abstract cla ...

  10. Windows:Word,PPT,EXCEL com+组件配置

    本文所涉及到配置前提: 服务器必须安装Office套件(Word,PPT,Excel) 第一部分 Word Com+组件权限配置 1.cmd模式输入dcomcnfg 2.找到Microsoft Wor ...