MySQL Atlas介绍

一、MySQL Atlas介绍

1.1.1 MySQL Atlas介绍

  1. 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官方

  1. 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 #配置文件
  1. 配置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
  1. 启动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
  1. 读写验证
读操作验证:
[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)
  1. 生产用户要求 (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基本管理

  1. 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)
  1. 临时关闭维护和开启
 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 |
+-------------+----------------+-------+------+
  1. 动态删除和添加从库(读库)
删除:
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添加成功 #注意最后一定要保存
  1. 动态删除和添加用户
删除用户:
删除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 读写分离软件介绍的更多相关文章

  1. MySQL主从复制与Atlas读写分离

    配置主从复制 1. 增加主从配置 # 主库配置文件 server-id = 1 log-bin = /var/lib/mysql/mysql-bin expire_logs_days = 10 ski ...

  2. mysql主从之基于atlas读写分离

    一 mysql读写分离的概念 写在主库,主库一般只有一个,读可以分配在多个从库上,如果写压力不大的话,也能把读分配到主库上. 实现是基于atlas实现的,atlas是数据库的中间件,程序只需要连接at ...

  3. Atlas mysql的读写分离和负载均衡<转>

    mysql的读写分离和负载均衡 http://my.oschina.net/superbigfu/blog/178134

  4. MySQL-18-MHA+Atlas读写分离架构

    Atlas介绍 Atlas是由Qihoo 360 Web平台部基础架构团队开发维护的一个基于MySQL协议的数据中间层项目 它是在mysql-proxy 0.8.2版本的基础上,对其进行了优化,增加了 ...

  5. Amoeba搞定mysql主从读写分离

    前言:一直想找一个工具,能很好的实现mysql主从的读写分离架构,曾经试用过mysql-proxy发现lua用起来很不爽,尤其是不懂lua脚本,突然发现了Amoeba这个项目,试用了下,感觉还不错,写 ...

  6. Centos7源码安装mysql及读写分离,互为主从

       Linux服务器 -源码安装mysql 及读写分离,互为主从   一.环境介绍: Linux版本: CentOS 7 64位 mysq版本: mysql-5.6.26 这是我安装时所使用的版本, ...

  7. MySQL数据库读写分离、读负载均衡方案选择

    MySQL数据库读写分离.读负载均衡方案选择 一.MySQL Cluster外键所关联的记录在别的分片节点中性能很差对需要进行分片的表需要修改引擎Innodb为NDB因此MySQL Cluster不适 ...

  8. MySQL的读写分离的几种选择

    MySQL的读写分离的几种选择 MySQL主从复制(Master-Slave)与读写分离(MySQL-Proxy)实践 原址如下: http://heylinux.com/archives/1004. ...

  9. MySQL/MariaDB读写分离配置

    DB读写分离描述 数据库的读写分离其实就是为了加减少数据库的压力:数据库的写入操作由主数据库来进行,读取操作由从数据库来进行操作.实现数据库读写分离技术是有很多方法的,在这里我就用一个比较简单的mys ...

  10. Amoeba实现mysql主从读写分离

    Amoeba实现mysql主从读写分离 这段在网上看了下关于amoeba的文章,总体感觉好像要比mysql-proxy好的多,也参考了不少的资料,此文章可能与其他文章作者会有雷同的地方,请谅解,但是此 ...

随机推荐

  1. global 函数

    x = 15 # 全局变量Gdef func_a(): print(x)def func_b(): print(x)def func_c(): global x # 在定义函数内声明x为全局变量后,才 ...

  2. nginx(一) の 入门解析

    OSI 模型的前三层 应用层: 每一个应用程序自定义的协议 表示层: 数据的压缩与解压缩.图片的编码与解码 会话层: 会话管理(session) 和 网络验证 .包括断点续传和服务器验证用户登录等.比 ...

  3. 【java数据结构与算法】选择排序

    选择排序原理剖析: 假设数组arr使用选择排序 每一轮选出数组最小的元素 arr.lenth个元素,只需要找出arr.length-1个元素的正确位置 选择排序便进行结束 外层for循环控制选择排序的 ...

  4. 基2和基4FFT

    1.1 FFT的必要索引变换 基2算法需要位顺序的反转位逆序,而基4算法需要首先构成一个2位的数字,再反转这些数字,称为数字逆序. 1.1 位逆序和数字逆序 1.2 FFT的复数乘法转实数乘法 \[X ...

  5. Nuget管理器下载插件出现依赖性相关无法正确下载

    话不多说,直接上图: 上面我采用的是PM控制台下载EntityFrameWork最新版本,之所以要这样做,是因为利用Nuget管理器好像不咋管用呀,一直说这个依赖那个依赖啥的,还不如最底层 用命令控制 ...

  6. js之new的原理和源码

    new的原理即作用: function Student(name,age){ this.name=name; this.age=age; } var stu=new Student("小明& ...

  7. linux 服务器下发布前端

    前提: 1.本地安装xshell和xftp 2.第一次需重置实例密码 3.22端口必须开启(默认开启) Linux安装nginx在linux下安装nginx,首先需要安装 gcc-c++编译器.然后安 ...

  8. composer disgnoize public key fail

    https://composer.github.io/pubkeys.html 还有这事, 太不可思议了哦.--怎么进去的, 真的不知道哦.

  9. alpine镜像安装sshd以进行远程debug

    FROM alpine:latest RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories ...

  10. goland使用go mod模式

    使用go mod之后,想要在goland中有代码提示,有两种方式,一种是使用gopath下的goimport工具,另一种是使用gomod自身的管理工具 我是用的是非gopath的方式,每次新建项目后总 ...