MySQL Atlas 读写分离软件介绍
MySQL Atlas介绍
一、MySQL Atlas介绍
1.1.1 MySQL Atlas介绍
- MySQL Atlas介绍
Atlas是由 Qihoo 360, Web平台部基础架构团队开发维护的一个基于MySQL协议的数据中间层项目。
它是在mysql-proxy 0.8.2版本的基础上,对其进行了优化,增加了一些新的功能特性。
360内部使用Atlas运行的mysql业务,每天承载的读写请求数达几十亿条。
软件下载地址:https://github.com/Qihoo360/Atlas/releases
常用读写分离软件
1、Atlas 下载地址:https://github.com/Qihoo360/Atlas/releases
2、proxySQL 官方地址:https://www.proxysql.com/
3、maxscale 官方地址:https://mariadb.com/kb/en/maxscale-22-getting-started/
4、MySQL-Router MySQL官方
- Atlas 部署
MHA+Atlas 高可用读写分离(部署前提有MHA高可用环境)
MHA高可用部署:https://www.cnblogs.com/woaiyunwei/p/13210749.html
[root@db03 /server/tools]# ll Atlas-2.2.1.el6.x86_64.rpm
-rw-r--r-- 1 root root 4963681 Jul 2 14:41 Atlas-2.2.1.el6.x86_64.rpm
[root@db03 /server/tools]# rpm -ivh Atlas-2.2.1.el6.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:Atlas-2.2.1-1 ################################# [100%]
[root@db03 /server/tools]# rpm -qa Atlas
Atlas-2.2.1-1.x86_64
[root@db03 /server/tools]# rpm -ql Atlas
/usr/local/mysql-proxy/bin/VERSION
/usr/local/mysql-proxy/bin/encrypt
/usr/local/mysql-proxy/bin/mysql-proxy
/usr/local/mysql-proxy/bin/mysql-proxyd
/usr/local/mysql-proxy/conf/test.cnf #配置文件
- 配置Atlas配置文件
[root@db03 /server/tools]# cd /usr/local/mysql-proxy/conf/
[root@db03 /usr/local/mysql-proxy/conf]# cp test.cnf{,.backup}
[root@db03 /usr/local/mysql-proxy/conf]# ll
total 8
-rw-r--r-- 1 root root 2810 Dec 17 2014 test.cnf
-rw-r--r-- 1 root root 2810 Jul 2 14:52 test.cnf.backup
[root@db03 /usr/local/mysql-proxy/conf]# cat test.cnf
[mysql-proxy]
#带#号的为非必需的配置项目
#管理接口的用户名
admin-username = user
#管理接口的密码
admin-password = pwd
#Atlas后端连接的MySQL主库的IP和端口,可设置多项,用逗号分隔
proxy-backend-addresses = 127.0.0.1:3306
#Atlas后端连接的MySQL从库的IP和端口,@后面的数字代表权重,用来作负载均衡,若省略则默认为1,可设置多项,用逗号分隔
#proxy-read-only-backend-addresses = 127.0.0.1:3305@1
#用户名与其对应的加密过的MySQL密码,密码使用PREFIX/bin目录下的加密程序encrypt加密,下行的user1和user2为示例,将其替换为你的MySQL的用户名和加密密码!
pwds = user1:+jKsgB3YAG8=, user2:GS+tr4TPgqc=
#设置Atlas的运行方式,设为true时为守护进程方式,设为false时为前台方式,一般开发调试时设为false,线上运行时设为true,true后面不能有空格。
daemon = true
#设置Atlas的运行方式,设为true时Atlas会启动两个进程,一个为monitor,一个为worker,monitor在worker意外退出后会自动将其重启,设为false时只有worker,没有monitor,一般开发调试时设为false,线上运行时设为true,true后面不能有空格。
keepalive = true
#工作线程数,对Atlas的性能有很大影响,可根据情况适当设置
event-threads = 8
#日志级别,分为message、warning、critical、error、debug五个级别
log-level = message
#日志存放的路径
log-path = /usr/local/mysql-proxy/log
#SQL日志的开关,可设置为OFF、ON、REALTIME,OFF代表不记录SQL日志,ON代表记录SQL日志,REALTIME代表记录SQL日志且实时写入磁盘,默认为OFF
#sql-log = OFF
#慢日志输出设置。当设置了该参数时,则日志只输出执行时间超过sql-log-slow(单位:ms)的日志记录。不设置该参数则输出全部日志。
#sql-log-slow = 10
#实例名称,用于同一台机器上多个Atlas实例间的区分
#instance = test
#Atlas监听的工作接口IP和端口
proxy-address = 0.0.0.0:1234
#Atlas监听的管理接口IP和端口
admin-address = 0.0.0.0:2345
#分表设置,此例中person为库名,mt为表名,id为分表字段,3为子表数量,可设置多项,以逗号分隔,若不分表则不需要设置该项
#tables = person.mt.id.3
#默认字符集,设置该项后客户端不再需要执行SET NAMES语句
#charset = utf8
#允许连接Atlas的客户端的IP,可以是精确IP,也可以是IP段,以逗号分隔,若不设置该项则允许所有IP连接,否则只允许列表中的IP连接
#client-ips = 127.0.0.1, 192.168.1
#Atlas前面挂接的LVS的物理网卡的IP(注意不是虚IP),若有LVS且设置了client-ips则此项必须设置,否则可以不设置
#lvs-ips = 192.168.1.1
配置mysql管理员和后端连接用户的密码加密
rep用户
[root@db03 /usr/local/mysql-proxy/bin]# ./encrypt 123456
/iZxz+0GRoA=
mha用户
[root@db03 /usr/local/mysql-proxy/bin]# ./encrypt mha
O2jBXONX098=
修改如下:
[root@db03 /usr/local/mysql-proxy/conf]# cat test.cnf
[mysql-proxy]
admin-username = user #atlas 用户
admin-password = pwd #atlas 密码
proxy-backend-addresses = 10.4.7.55:3306 #写操作数据库 一般为MHAVIP
proxy-read-only-backend-addresses = 10.4.7.52:3306,10.4.7.53:3306 #读操作数据库
pwds = rep:/iZxz+0GRoA=,mha:O2jBXONX098= #mysql数据库管理员,后端连接用户的用户名和密码(这里是测试不代表生产环境) 上面的加密密码就放在这里(注意:密码需要对应用户)
daemon = true
keepalive = true
event-threads = 8
log-level = message
log-path = /usr/local/mysql-proxy/log #log日志
sql-log=ON
proxy-address = 0.0.0.0:33060
admin-address = 0.0.0.0:2345
charset=utf8
- 启动Atlas
[root@db03 /usr/local/mysql-proxy/bin]# /usr/local/mysql-proxy/bin/mysql-proxyd test start
OK: MySQL-Proxy of test is started
注意:Atlas可以通过不同配置文件,管理多个读写分离项目
比如:
/usr/local/mysql-proxy/bin/mysql-proxyd test start (test=test.conf的前缀)
/usr/local/mysql-proxy/bin/mysql-proxyd test1 start
查看进程
[root@db03 /usr/local/mysql-proxy/bin]# ps -ef |grep proxy
root 53814 1 0 15:52 ? 00:00:00 /usr/local/mysql-proxy/bin/mysql-proxy --defaults-file=/usr/local/mysql-proxy/conf/test.cnf
root 53815 53814 0 15:52 ? 00:00:00 /usr/local/mysql-proxy/bin/mysql-proxy --defaults-file=/usr/local/mysql-proxy/conf/test.cnf
root 53980 18787 0 15:57 pts/5 00:00:00 grep --color=auto proxy
- 读写验证
读操作验证:
[root@db02 ~]# mysql -umha -pmha -h 10.4.7.53 -P33060 #这里的端口是Atlas proxy-address 代理的端口 而不是mysql的端口
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.81-log MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
db02 [(none)]>select @@server_id;
+-------------+
| @@server_id |
+-------------+
| 52 |
+-------------+
1 row in set (0.00 sec)
db02 [(none)]>select @@server_id;
+-------------+
| @@server_id |
+-------------+
| 53 |
+-------------+
1 row in set (0.00 sec)
读操作的sever_id轮询到52 53 证明读写分离 读操作成功
写操作验证:
db02 [(none)]>begin;select @@server_id;commit; #这是三条语句,分号隔开的。
Query OK, 0 rows affected (0.00 sec)
+-------------+
| @@server_id |
+-------------+
| 51 |
+-------------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.01 sec)
- 生产用户要求 (Atlas+MHA+VIP+SENDREPORT+BINLOG)
需求:开发人员申请一个应用用户 app( select update insert) 密码123456,要通过10网段登录
1. 在主库中,创建用户
grant select ,update,insert on *.* to app@'10.0.0.%' identified by '123456';
2. 在atlas中添加生产用户
/usr/local/mysql-proxy/bin/encrypt 123456 ---->制作加密密码
3. 改配置文件
vim test.cnf
pwds = rep:/iZxz+0GRoA=,mha:O2jBXONX098=,app:/iZxz+0GRoA=
/usr/local/mysql-proxy/bin/mysql-proxyd test restart
[root@db03 conf]# mysql -uapp -p123456 -h 10.4.7.53 -P 33060
1.1.2 Atlas基本管理
- Atlas基本管理
登录:
[root@db03 ~]# mysql -uuser -ppwd -h 10.4.7.53 -P2345
查看帮助:
db03 [(none)]>select * from help;
+----------------------------+---------------------------------------------------------+
| command | description |
+----------------------------+---------------------------------------------------------+
| SELECT * FROM help | shows this help |
| SELECT * FROM backends | lists the backends and their state |
| SET OFFLINE $backend_id | offline backend server, $backend_id is backend_ndx's id |
| SET ONLINE $backend_id | online backend server, ... |
| ADD MASTER $backend | example: "add master 127.0.0.1:3306", ... |
| ADD SLAVE $backend | example: "add slave 127.0.0.1:3306", ... |
| REMOVE BACKEND $backend_id | example: "remove backend 1", ... |
| SELECT * FROM clients | lists the clients |
| ADD CLIENT $client | example: "add client 192.168.1.2", ... |
| REMOVE CLIENT $client | example: "remove client 192.168.1.2", ... |
| SELECT * FROM pwds | lists the pwds |
| ADD PWD $pwd | example: "add pwd user:raw_password", ... |
| ADD ENPWD $pwd | example: "add enpwd user:encrypted_password", ... |
| REMOVE PWD $pwd | example: "remove pwd user", ... |
| SAVE CONFIG | save the backends to config file |
| SELECT VERSION | display the version of Atlas |
+----------------------------+---------------------------------------------------------+
16 rows in set (0.00 sec)
查看后端节点:
db03 [(none)]> SELECT * FROM backends;
+-------------+----------------+-------+------+
| backend_ndx | address | state | type |
+-------------+----------------+-------+------+
| 1 | 10.4.7.55:3306 | up | rw |
| 2 | 10.4.7.52:3306 | up | ro |
| 3 | 10.4.7.53:3306 | up | ro |
+-------------+----------------+-------+------+
3 rows in set (0.00 sec)
- 临时关闭维护和开启
SET OFFLINE $backend_id | offline backend server, $backend_id is backend_ndx's id |
| SET ONLINE $backend_id | online backend server, ...
例如:需要临时维护一下53 ,就可以临时关闭53,维护好之后在开启
db03 [(none)]>set offline 3; #3是backend_ndx 索引号
+-------------+----------------+---------+------+
| backend_ndx | address | state | type |
+-------------+----------------+---------+------+
| 3 | 10.4.7.53:3306 | offline | ro |
+-------------+----------------+---------+------+
1 row in set (0.00 sec)
db03 [(none)]> SELECT * FROM backends;
+-------------+----------------+---------+------+
| backend_ndx | address | state | type |
+-------------+----------------+---------+------+
| 1 | 10.4.7.55:3306 | up | rw |
| 2 | 10.4.7.52:3306 | up | ro |
| 3 | 10.4.7.53:3306 | offline | ro |
+-------------+----------------+---------+------+
3 rows in set (0.00 sec)
维护完成开启
db03 [(none)]>set online 3;
+-------------+----------------+---------+------+
| backend_ndx | address | state | type |
+-------------+----------------+---------+------+
| 3 | 10.4.7.53:3306 | unknown | ro |
+-------------+----------------+---------+------+
1 row in set (0.00 sec)
db03 [(none)]> SELECT * FROM backends;
+-------------+----------------+-------+------+
| backend_ndx | address | state | type |
+-------------+----------------+-------+------+
| 1 | 10.4.7.55:3306 | up | rw |
| 2 | 10.4.7.52:3306 | up | ro |
| 3 | 10.4.7.53:3306 | up | ro |
+-------------+----------------+-------+------+
- 动态删除和添加从库(读库)
删除:
db03 [(none)]> SELECT * FROM backends;
+-------------+----------------+-------+------+
| backend_ndx | address | state | type |
+-------------+----------------+-------+------+
| 1 | 10.4.7.55:3306 | up | rw |
| 2 | 10.4.7.52:3306 | up | ro |
| 3 | 10.4.7.53:3306 | up | ro |
+-------------+----------------+-------+------+
3 rows in set (0.00 sec)
db03 [(none)]>remove backend 3;
Empty set (0.00 sec)
db03 [(none)]> SELECT * FROM backends;
+-------------+----------------+-------+------+
| backend_ndx | address | state | type |
+-------------+----------------+-------+------+
| 1 | 10.4.7.55:3306 | up | rw |
| 2 | 10.4.7.52:3306 | up | ro |
+-------------+----------------+-------+------+
2 rows in set (0.00 sec)
保存:
db03 [(none)]>SAVE CONFIG; 保存到配置文件
Empty set (0.00 sec)
查看配置文件:
[root@db03 /usr/local/mysql-proxy/bin]# grep -i read-only /usr/local/mysql-proxy/conf/test.cnf
proxy-read-only-backend-addresses=10.4.7.52:3306
#配置文件里只剩下52了
添加从库(读库)
db03 [(none)]>add slave 10.4.7.53:3306;
Empty set (0.00 sec)
db03 [(none)]> SELECT * FROM backends;
+-------------+----------------+-------+------+
| backend_ndx | address | state | type |
+-------------+----------------+-------+------+
| 1 | 10.4.7.55:3306 | up | rw |
| 2 | 10.4.7.52:3306 | up | ro |
| 3 | 10.4.7.53:3306 | up | ro |
+-------------+----------------+-------+------+
3 rows in set (0.00 sec)
保存到配置文件:
db03 [(none)]>SAVE CONFIG;
Empty set (0.00 sec)
查看配置文件:
[root@db03 /usr/local/mysql-proxy/bin]# grep -i read-only /usr/local/mysql-proxy/conf/test.cnf
proxy-read-only-backend-addresses=10.4.7.52:3306,10.4.7.53:3306
#53添加成功
#注意最后一定要保存
- 动态删除和添加用户
删除用户:
删除rep用户:
db03 [(none)]>remove pwd rep;
Empty set (0.00 sec)
保存:
db03 [(none)]>save config;
Empty set (0.00 sec)
查看配置文件:
[root@db03 /usr/local/mysql-proxy/bin]# grep -i pwds /usr/local/mysql-proxy/conf/test.cnf
pwds=mha:O2jBXONX098=
#rep 用户被删除了
添加用户:
db03 [(none)]>add pwd rep:123456; #add pwd 用户:密码
Empty set (0.00 sec)
保存:
db03 [(none)]>save config;
Empty set (0.00 sec)
查看配置文件:
[root@db03 /usr/local/mysql-proxy/bin]# grep -i pwds /usr/local/mysql-proxy/conf/test.cnf
pwds=mha:O2jBXONX098=,rep:/iZxz+0GRoA=
#添加成功
db03 [(none)]>SELECT * FROM pwds ;
+----------+--------------+
| username | password |
+----------+--------------+
| mha | O2jBXONX098= |
| rep | /iZxz+0GRoA= |
+----------+--------------+
2 rows in set (0.00 sec)
MySQL Atlas 读写分离软件介绍的更多相关文章
- MySQL主从复制与Atlas读写分离
配置主从复制 1. 增加主从配置 # 主库配置文件 server-id = 1 log-bin = /var/lib/mysql/mysql-bin expire_logs_days = 10 ski ...
- mysql主从之基于atlas读写分离
一 mysql读写分离的概念 写在主库,主库一般只有一个,读可以分配在多个从库上,如果写压力不大的话,也能把读分配到主库上. 实现是基于atlas实现的,atlas是数据库的中间件,程序只需要连接at ...
- Atlas mysql的读写分离和负载均衡<转>
mysql的读写分离和负载均衡 http://my.oschina.net/superbigfu/blog/178134
- MySQL-18-MHA+Atlas读写分离架构
Atlas介绍 Atlas是由Qihoo 360 Web平台部基础架构团队开发维护的一个基于MySQL协议的数据中间层项目 它是在mysql-proxy 0.8.2版本的基础上,对其进行了优化,增加了 ...
- Amoeba搞定mysql主从读写分离
前言:一直想找一个工具,能很好的实现mysql主从的读写分离架构,曾经试用过mysql-proxy发现lua用起来很不爽,尤其是不懂lua脚本,突然发现了Amoeba这个项目,试用了下,感觉还不错,写 ...
- Centos7源码安装mysql及读写分离,互为主从
Linux服务器 -源码安装mysql 及读写分离,互为主从 一.环境介绍: Linux版本: CentOS 7 64位 mysq版本: mysql-5.6.26 这是我安装时所使用的版本, ...
- MySQL数据库读写分离、读负载均衡方案选择
MySQL数据库读写分离.读负载均衡方案选择 一.MySQL Cluster外键所关联的记录在别的分片节点中性能很差对需要进行分片的表需要修改引擎Innodb为NDB因此MySQL Cluster不适 ...
- MySQL的读写分离的几种选择
MySQL的读写分离的几种选择 MySQL主从复制(Master-Slave)与读写分离(MySQL-Proxy)实践 原址如下: http://heylinux.com/archives/1004. ...
- MySQL/MariaDB读写分离配置
DB读写分离描述 数据库的读写分离其实就是为了加减少数据库的压力:数据库的写入操作由主数据库来进行,读取操作由从数据库来进行操作.实现数据库读写分离技术是有很多方法的,在这里我就用一个比较简单的mys ...
- Amoeba实现mysql主从读写分离
Amoeba实现mysql主从读写分离 这段在网上看了下关于amoeba的文章,总体感觉好像要比mysql-proxy好的多,也参考了不少的资料,此文章可能与其他文章作者会有雷同的地方,请谅解,但是此 ...
随机推荐
- nginx从仅支持80到支持80和443
测试环境的域名,之前只支持http.开发同学不知啥时候改了数据库配置,导致所有跳转到到了https了.所以得加上https访问. 配置文件之前是这样的: 1 server { 2 listen 80; ...
- 我们后端代码这样子设置虽然这样子返回的是字符串,但是json字符串也是字符串
我们后端代码这样子设置虽然这样子返回的是字符串 但是json字符串也是字符串,后端如果想接收的话,直接百度下怎么接收json字符串就行
- redis分布锁
1.redis分布式锁应用的场景? 1)防止缓存穿透:热点数据过期,大量线程访问mysql 2) 防止秒杀超卖:库存数量同步给redis后,对redis数据进行扣减 3)双写一致性:缓存的数据,被修 ...
- windows平台下软件最小化后无法打开的解决方法
今天打开电脑后,双击桌面软件图标,软件启动画面出现,等了几秒后直接最小化窗口,感觉有点奇怪.点击任务栏图标后没有反应,软件界面没出现. 以为软件是不是安装破损什么的,重新安装后问题依旧,奇怪,究竟是什 ...
- nop4.3 用户权限管理
权限管理涉及到5张表: //用户表 select * from Customer //角色表select * from CustomerRole //用户和角色对应关系select * from Cu ...
- 可汗儿童版kids安卓版下载安装教程
可汗儿童版kids安卓版幼儿版下载安装教程 点击下面 http://vip.ho27.com/Khan.apk 备用下载链接 天翼网盘下载安装就行 https://cloud.189.cn/t/6RV ...
- nginx: the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf
Nginx如果未开启SSL模块,配置Https时将提示如题错误 原因:nginx缺少http_ssl_module模块,编译安装的时候带上--with-http_ssl_module配置就行了,但是现 ...
- HTML基础知道了解
第1章 Html介绍 1.Html和CSS的关系 1.1 学习web前端开发基础技术需要掌握:HTML.CSS.JavaScript语言.下面我们就来了解下这三门技术都是用来实现什么的: 1.2 HT ...
- windows上Yii2使用workerman整套流程
1.在根目录下新建Worker目录 进入新建的Worker文件夹 运行 LINUX下运行 composer require workerman/workerman win 下运行 composer r ...
- mysql 删除商品名字重复数据,同时保留最新一条
delete goods where goods_id in (SELECT goods_id FROM goodswhere goods_name in (select goods_name fro ...

