MySQL+Keepalived实现主主高可用方案
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实现主主高可用方案的更多相关文章
- keepalived+mysql双主复制高可用方案
MySQL双主复制,即互为Master-Slave(只有一个Master提供写操作),可以实现数据库服务器的热备,但是一个Master宕机后不能实现动态切换.而Keepalived通过虚拟IP,实现了 ...
- MySQL MGR+ Consul之数据库高可用方案
背景说明: 基于目前存在很多MySQL数据库单点故障,传统的MHA,PXC等方案用VIP或者DNS切换的方式可以实现.基于数据库的数据强一致性考虑,采用MGR集群,采用consul服务注册发现 ...
- [转]MYSQL高可用方案探究(总结)
前言 http://blog.chinaunix.net/uid-20639775-id-3337432.htmlLvs+Keepalived+Mysql单点写入主主同步高可用方案 http://bl ...
- Linux下"负载均衡+高可用"集群的考虑点 以及 高可用方案说明(Keepalive/Heartbeat)
当下Linux运维技术越来越受到企业的关注和追捧, 在某些企业, 尤其是牵涉到电子商务和电子广告类的网站,通常会要求作负载均衡和高可用的Linux集群方案.那么如何实施Llinux集群架构,才能既有效 ...
- 利用LVS+Keepalived搭建Mysql双主复制高可用负载均衡环境
应用背景: MySQL复制(主主,主从...)能在保证数据的备份的同时也能够做读写分离分摊系统压力,但是发生单点故障时,需要手动 切换到另外一台主机.LVS和Keppalived可以设定一个VIP来实 ...
- Nginx+Keepalived 主备高可用 安装与配置
环境说明:操作系统:CentOS6.7 x86_64Nginx版本:nginx-1.9.7Keepalived版本:keepalived-1.2.24 主nginx + Keepalived :10. ...
- MySQL高可用方案
高可用架构对于互联网服务基本是标配,无论是应用服务还是数据库服务都需要做到高可用.虽然互联网服务号称7*24小时不间断服务,但多多少少有一些时候服务不可用,比如某些时候网页打不开,百度不能搜索或者无法 ...
- mysql高可用方案总结性说明
MySQL的各种高可用方案,大多是基于以下几种基础来部署的(也可参考:Mysql优化系列(0)--总结性梳理 该文后面有提到)1)基于主从复制:2)基于Galera协议(PXC):3)基于NDB引 ...
- [转载] MySQL高可用方案选型参考
原文: http://imysql.com/2015/09/14/solutions-of-mysql-ha.shtml?hmsr=toutiao.io&utm_medium=toutiao. ...
随机推荐
- A. Treasure Hunt Codeforces 线性代数
A. Treasure Hunt time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- [bzoj3061][Usaco13Feb]Partitioning the Farm_动态规划_状压dp
Partitioning the Farm bzoj-3061 Usaco13Feb 题目大意:给定一个n*n的方格图,用k条贯穿方格图的直线将整个方格图分割,使得每一块的权值和的最大值最小. 注释: ...
- percona-toolkit使用教程
1:慢日志查询 [root@test_dx modify]# wget percona.com/get/pt-query-digest [root@test_dx modify]# file pt-q ...
- systemtap dtrace与 oracle
https://fritshoogland.wordpress.com/page/3/ http://externaltable.blogspot.com/2013/06/dtrace-explora ...
- Machine_learning--score
辛苦了2个半月,终须学完了machine-learning watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2hyaXN0cHJpbmNlMDA3/font ...
- iphone照片查看器
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- HDU 5501
这题的01背包的特点很容易看出来,但其实发现,这个题讲究加入时候的顺序. 于是,用贪心排序,如代码中所示,如果A在B前面造成的分数损失更小,则排在前面...其实这个我也是猜的.. #include & ...
- linux下apache+openssl配置记录
软件环境 Apache Httpd 2.2.29 (http://httpd.apache.org ) OpenSSL 1.0.1h (http://www.openssl.org/source ) ...
- Photon + Unity3D 线上游戏开发 学习笔记(四)
这一节 我们建立 photon Server 端的框架 一个最简单的Photon框架 就包括一个 Applocation 类 和 一个 peer 类,作用例如以下: * Application 类是 ...
- Linux Framebuffer 驱动框架之一概念介绍及LCD硬件原理【转】
本文转载自:http://blog.csdn.net/liuxd3000/article/details/17464779 一.基本概念 帧缓冲(Framebuffer)是Linux系统为显示设备提供 ...