实验环境准备:

master:192.168.200.111

slave1:192.168.200.112

slave2:192.168.200.113

Altas:192.168.200.114

client:192.168.200.115

第一步:关闭防火墙(master,slave1,slave2,Altas)

[root@localhost ~]# systemctl stop firewalld && setenforce 0 && iptables -F

第二步:在master,slave1,slave2上实现主从复制

步骤省略,详情请参考以下网址:

https://www.cnblogs.com/lyqlyqlyq/p/11677034.html

master:

mysql> grant all on *.* to 'admin'@'192.168.200.%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

slave1:

mysql> grant all on *.* to 'admin'@'192.168.200.%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

slave2:

mysql> grant all on *.* to 'admin'@'192.168.200.%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

第三步:配置Altas服务器

[root@localhost ~]# wget  https://github.com/Qihoo360/Atlas/releases/download/2.2.1/Atlas-2.2.1.el6.x86_64.rpm

[root@localhost ~]# rpm -ivh Atlas-2.2.1.el6.x86_64.rpm

[root@localhost ~]# cd /usr/local/mysql-proxy/bin/

[root@localhost bin]# ./encrypt 123456

/iZxz+0GRoA=

[root@localhost bin]# cp /usr/local/mysql-proxy/conf/test.cnf /usr/local/mysql-proxy/conf/test.cnf.bak

[root@localhost bin]# vim /usr/local/mysql-proxy/conf/test.conf

[mysql-proxy]
admin-username = user
admin-password = pwd
proxy-backend-addresses = 192.168.200.111:3306
proxy-read-only-backend-addresses = 192.168.200.112:3306,192.168.200.113:3306
pwds = admin:/iZxz+0GRoA=
daemon = true
keepalive = true
event-threads = 8
log-level = message
log-path = /usr/local/mysql-proxy/log
sql-log = REALTIME
proxy-address = 0.0.0.0:1234
admin-address = 0.0.0.0:2345

[root@localhost bin]# /usr/local/mysql-proxy/bin/mysql-proxyd test start

OK: MySQL-Proxy of test is started   //出现即成功

[root@localhost ~]# netstat -lnpt | grep mysql-proxy
tcp 0 0 0.0.0.0: 0.0.0.0:* LISTEN 28754/mysql-proxy
tcp 0 0 0.0.0.0: 0.0.0.0:* LISTEN 28754/mysql-proxy

第四步:测试

此时的三台MySQL服务器是主从备份

在mysql-master 创建db_test 库及该库下的test表

mysql> create database AB_ab;

mysql> create table ab(id char(1));

可以在112和113上查看该库及表

mysql> show  databases;

在112和113 服务器上停止主从备份

mysql> stop slave;

在111上添加表内容

mysql> insert into AB_ab.ab values('9');

此前在服务器上同步了表,所以在从服务器上可以直接手动插入其他内容

在slave1 上:

mysql> insert into AB_ab.ab values('1');

在slave2上:

mysql> insert into AB_ab.ab values('2'');

在115上测试

[root@localhost ~]# yum -y install mariadb 或者mysql

mysql -uadmin -p123456 -h 192.168.200.114 -P1234

(1) 读测试

2)写测试:

mysql> insert into AB_ab.ab values('5'');

在master服务器上查看是否写入:

高可用:

192.168.200.113 Atlas备

[root@localhost ~]# wget  https://github.com/Qihoo360/Atlas/releases/download/2.2.1/Atlas-2.2.1.el6.x86_64.rpm

[root@localhost ~]# rpm -ivh Atlas-2.2.1.el6.x86_64.rpm

[root@localhost ~]# cd /usr/local/mysql-proxy/bin/

[root@localhost bin]# ./encrypt 123456

/iZxz+0GRoA=

[root@localhost bin]# cp /usr/local/mysql-proxy/conf/test.cnf /usr/local/mysql-proxy/conf/test.cnf.bak

[root@localhost bin]# vim /usr/local/mysql-proxy/conf/test.conf

[mysql-proxy]
admin-username = user
admin-password = pwd
proxy-backend-addresses = 192.168.200.111:3306
proxy-read-only-backend-addresses = 192.168.200.112:3306,192.168.200.113:3306
pwds = admin:/iZxz+0GRoA=
daemon = true
keepalive = true
event-threads = 8
log-level = message
log-path = /usr/local/mysql-proxy/log
sql-log = REALTIME
proxy-address = 0.0.0.0:1234
admin-address = 0.0.0.0:2345

[root@localhost bin]# /usr/local/mysql-proxy/bin/mysql-proxyd test start

OK: MySQL-Proxy of test is started   //出现即成功

[root@localhost ~]# netstat -lnpt | grep mysql-proxy
tcp 0 0 0.0.0.0:2345 0.0.0.0:* LISTEN 28754/mysql-proxy 
tcp 0 0 0.0.0.0:1234 0.0.0.0:* LISTEN 28754/mysql-proxy

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

[root@localhost ~]# cp /etc/keepalived/keepalived.conf  /etc/keepalived/keepalived.conf.bak

[root@localhost ~]# vim  /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
router_id LVS_ATLAS
}

vrrp_script chk_atlas_port {
script "/opt/check_atlas.sh"
weight 5
}

vrrp_instance VI_1 {
state BACKUP
interface ens32
virtual_router_id 51
priority 99
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}

track_script {
chk_atlas_port
}
virtual_ipaddress {
192.168.200.254
}
}

[root@localhost ~]# vim  cat /opt/chk_atlas.sh

#!/bin/bash
counter=$(ps -C mysql-proxy --no-heading | wc -l)
if [ "${counter}" = "0" ];then
/usr/local/mysql-proxy/bin/mysql-proxyd test start
sleep 3
counter=$(ps -C mysql-proxy --no-heading | wc -l)
if [ "{counter}" = "0" ];then
systemctl stop keepalived
fi
fi

[root@localhost ~]# chmod +x /opt/chk_atlas.sh

[root@localhost ~]#  systemctl start keepalived

192.168.200.114 Atlas主

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

[root@localhost ~]# cp /etc/keepalived/keepalived.conf  /etc/keepalived/keepalived.conf.bak

[root@localhost ~]# vim  /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
router_id LVS_ATLAS
}

vrrp_script chk_atlas_port {
script "/opt/check_atlas.sh"
weight 5
}

vrrp_instance VI_1 {
state MASTER
interface ens32
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}

track_script {
chk_atlas_port
}
virtual_ipaddress {
192.168.200.254
}
}

[root@localhost ~]# vim  cat /opt/chk_atlas.sh

#!/bin/bash
counter=$(ps -C mysql-proxy --no-heading | wc -l)
if [ "${counter}" = "0" ];then
/usr/local/mysql-proxy/bin/mysql-proxyd test start 
sleep 3
counter=$(ps -C mysql-proxy --no-heading | wc -l)
if [ "{counter}" = "0" ];then
systemctl stop keepalived
fi
fi

[root@localhost ~]# chmod +x /opt/chk_atlas.sh

[root@localhost ~]#  systemctl start keepalived

高可用搭建完成!

 

mysql基于Altas读写分离并实现高可用的更多相关文章

  1. mysql主主、mysql-proxy读写分离、keepalived高可用完美组合

    配置mysql主主复制 服务器A:172.16.100.9 服务器B:172.16.100.10 首先在服务器A和服务器B上各安装好单机版mysql5.7,安装好后,再继续下面的操作. 在服务器A和服 ...

  2. mysql主从复制以及读写分离

    之前我们已经对LNMP平台的Nginx做过了负载均衡以及高可用的部署,今天我们就通过一些技术来提升数据的高可用以及数据库性能的提升. 一.mysql主从复制 首先我们先来看一下主从复制能够解决什么问题 ...

  3. 聊聊Mysql主从同步读写分离配置实现

    Hi,各位热爱技术的小伙伴您们好,好久没有写点东西了,今天写点关于mysql主从同步配置的操作日志同大家一起分享.最近自己在全新搭建一个mysql主从同步读写分离数据库简单集群,我讲实际操作步骤整理分 ...

  4. Linux下MySQL主从复制(GTID)+读写分离(ProxySQL)-实施笔记

    GTID概念: GTID( Global Transaction Identifier)全局事务标识.GTID 是 5.6 版本引入的一个有关于主从复制的重大改进,相对于之前版本基于 Binlog 文 ...

  5. MySQL 主从复制与读写分离 (超详细图文并茂小白闭着眼睛都会做)

    MySQL 主从复制与读写分离 1.什么是读写分离 2.为什么要读写分离 3.什么时候要读写分离 4.主从复制与读写分离 5.mysql支持的复制类型 6.主从复制的工作过程 7.MySQL主从复制延 ...

  6. 30.Mysql主从复制、读写分离

    Mysql主从复制.读写分离 目录 Mysql主从复制.读写分离 读写分离 读写分离概述 为什么要读写分离 什么时候要读写分离 主从复制与读写分离 mysql支持的复制类型 主从复制的工作过程 初始环 ...

  7. MySQL + Atlas --- 部署读写分离

    阅读目录 1. 数据库用户配置 2. 主从数据库连接 3. Atlas配置 4. 读写分离测试 序章 Atlas是360团队弄出来的一套基于MySQL-Proxy基础之上的代理,修改了MySQL-Pr ...

  8. Amoeba+Mysql实现数据库读写分离

    一.Amoeba 是什么 Amoeba(变形虫)项目,专注 分布式数据库 proxy 开发.座落与Client.DB Server(s)之间.对客户端透明.具有负载均衡.高可用性.sql过滤.读写分离 ...

  9. Mysql主从配置+读写分离

    Mysql主从配置+读写分离     MySQL从5.5版本开始,通过./configure进行编译配置方式已经被取消,取而代之的是cmake工具.因此,我们首先要在系统中源码编译安装cmake工具. ...

随机推荐

  1. 洛谷4843 BZOJ2502 清理雪道

    有源汇有上下界的最小可行流. YY一下建图应该很好搞吧(? 就是对于每个雪道都是[1,inf]然后源点到所有点都是[0,inf]所有点到汇点都是[0,inf] 这样的话跑一个有源汇上下界最小可行流就可 ...

  2. Pycharm的debug单步调试

    首先设置断点,点击行号显示的一侧,在指定行设置断点.比如这里,我们设断点在创建对象时: .如果这时我们直接右键run这个代码.他还是会直接运行,不会理会断点 结果 所以要右键选择run下面的debug ...

  3. Python3解leetcode Binary Tree Paths

    问题描述: Given a binary tree, return all root-to-leaf paths. Note: A leaf is a node with no children. E ...

  4. yii2和laravel比较

    yii2和laravel比较 一.总结 一句话总结: 开发速度两者相当:laravel的artisan工具和yii的gii有异曲同工的效果,借助于artisan工具,可以快速创建控制器.模型和路由等. ...

  5. CentOS 7在VMware 12中共享文件看不见的问题?

    前言 由于rhel 7.2因为没有注册导致yum无法使用,包括自己配置本地源,这个命令在你没有注册都不能使用,每次使用rpm去装软件,自己去找缺少的依赖包,实在是麻烦.于是不如就换一个系统,CentO ...

  6. mysql oracle sqlserver三种数据库count函数返回值不一样

    SQLQuery countSqlQuery = userDAO.createSQLQuery("select count(id) from fhcb_08_tbl_user"); ...

  7. 建议66,67 注意Arrays.asList()的使用

    代码 public static void main(String[] args) { int[]data = {1,2,3,4,5}; List list = Arrays.asList(data) ...

  8. python 访问 网页 获得源码

    >>> from urllib.request import urlopen >>> for line in urlopen('http://tycho.usno. ...

  9. Linux 通配符和特殊符号

  10. 搜索的应用--计算最优解:Aizu - ALDS1_4_D Allocation

    搜索的应用-计算最优解 题目: You are given nn packages of wiwi kg from a belt conveyor in order (i=0,1,...n−1i=0, ...