首页
学习
活动
专区
工具
TVP
发布

MySQL读写分离工具Atlas

大家好,我是anyux。本文介绍MySQL读写分离工具Atlas。

Atlas介绍

原来mha构架下有三台服务器,利用率只有30%,可以使用Atlas数据库中间件提高服务器利用率。即利用从库读,主库写

atlas架构

atlas安装在应用程序和数据库服务之间,使用时,应用程序直接连接atlas

注意:

atlas只能安装在64位系统上

后端mysql版本须大于等于5.6

安装过程

在新链接复制的虚拟机db116上安装atlas

wget https://github.com/Qihoo360/Atlas/releases/download/2.2.1/Atlas-2.2.1.el6.x86_64.rpm

rpm -ivh Atlas-2.2.1.el6.x86_64.rpm

cd /usr/local/mysql-proxy/conf

mv test.cnf test.cnf.bak

echo "export PATH=$PATH:/usr/local/mysql-proxy/bin/" >> /etc/profile

source /etc/profile配置文件

配置文件项可以参考test.cnf.bak,因为atlas是国人基于MySQL-proxy二次开发的软件产品,注释也是汉字,很是方便

cat >test.cnf

[mysql-proxy]

admin-username = atlas

admin-password = atlas

proxy-backend-addresses = 192.168.255.200:3306

proxy-read-only-backend-addresses = 192.168.255.113:3306,192.168.255.115:3306

pwds = repl:3yb5jEku5h4=,mha:O2jBXONX098=

daemon = true

keepalive = true

event-threads = 8

log-level = message

log-path = /usr/local/mysql-proxy/log

sql-log=ON

proxy-address = 0.0.0.0:33060

admin-address = 0.0.0.0:2345

charset=utf8

EOF

启动atlas

test对应上面的test.cnf文件,可以管理多个mha节点

mysql-proxyd test start

ps -ef |grep [p]roxy

ss -lnatup | grep proxy

连接atlas生产端口

cat >/etc/yum.repos.d/mysql-community.repo

[mysql57-community]

name=MySQL 5.7 Community Server

baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7/

enabled=1

gpgcheck=0

EOF

yum install -y mysql

mysql -uatlas -patlas -h 192.168.255.116 -P 33060

服务器版本Server version:5.0.81

测试读写分离

模拟读操作

select @@server_id;

模拟写操作

begin;

select @@server_id;

commit;

添加生产用户

主库创建用户

grant all on *.* to 'app'@'%' identified by 'app';

flush privileges;

制作密码

encrypt app

追加到配置文件

vim /usr/local/mysql-proxy/conf/test.cnf

pwds = repl:3yb5jEku5h4=,mha:O2jBXONX098=,app:CsTF0xptdHU=

重启atlas

mysql-proxyd test restart

测试连接

mysql -uapp -papp -h 192.168.255.116 -P 33060

测试新用户读写分离

select @@server_id;

begin;

select @@server_id;

commit;

集群管理

连接管理端口

mysql -uatlas -patlas -h 127.0.0.1 -P 2345

连接截图如下

查看帮助

select * from help;

select * from backends;

backend_ndx是atlas对数据库节点的编号,使用编号对数据库进行管理

set offline 2;

临时停止对后端主机发送请求

set online 2;

开启对后端数据库的通信

add master "127.0.0.1:3306";

添加主节点,一般很不用到

remove backend 3;

删除节点

add slave 192.168.255.115:3306;

添加从节点,较多使用

select * from clients;

查看连接白名单,如果白名单为空,则允许所有ip连接,否则只允许列表中的ip连接,详情参考备份文件

add client 192.168.255.119;

添加连接白名单

remove client 192.168.255.119;

删除连接白名单

select * from pwds;

首先要在后端主库添加生产用户

grant all on *.* to app01@'%' identified by 'app01';

flush privileges;

在atlas中配置用户

add pwd app01:app01

add enpwd app01:"umY97nPrOgE=";

enpwd表示加密后的密码

remove pwd app;

save config;

保存修改内容到配置文件中

select version;

记录的日志

cat log/test.log

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20200331A0MGND00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券