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. SQL开窗函数用法

    开窗函数分类: 根据使用的目的,开窗函数可以分为两类:聚合开窗函数和排序开窗函数. 下面主要解析四种常用的排序开窗函数: 1.ROW_NUMBER() OVER () : 对相等的值不进行区分,序号连 ...

  2. Scoped方法(防止样式名称冲突)

    App.vue <template> <div> <Student/> <School></School> </div> < ...

  3. SourceInsight4.0修改字体大小

    SourceInsight4.0修改字体大小 1.右键Options->Preferences.如图所示,然后找到Syntax Decorations选项,点击File Types 2.点击Fi ...

  4. Scala集合排序

    Scala集合排序有三种方法:sorted.sortBy().sortWith() (1)sorted 对一个集合进行自然排序,通过传递隐式的Ordering源码中有两点值得注意的地方:1.sorte ...

  5. Django-django-celery的配置

    1.安装django-celery   pip install django-celery 2.添加配置 demos/demos/settings.py(我的项目名为demos,这里只是示范,切勿搞混 ...

  6. Excel 的盒须图 离群值 Outliers

    Excel 中的盒须图 翻译自https://www.excel-easy.com/examples/box-whisker-plot.html 本示例教您如何在Excel中创建盒须图.盒须图显示了数 ...

  7. Android Studio: how to remove/update the “Created by” comment added to all new classes?

    By default Android Studio automatically adds a header comment to all new classes, e.g. /** * Created ...

  8. yaml文件读取转化为类

    首先你要有一个文件读取的方法,写一个根据传入路径 + 类来自动返回对应类的方法. /** * 根据传入的path,加载配置文件内容到对应class中 */ public static <T> ...

  9. idea 导入项目之后,只显示项目文件,不显示项目结构

    导入项目之后,只显示项目文件,不显示项目结构 解决方法 1.点击file->project structure..->Modules 点击右上角+加号 ->import Module ...

  10. 常见的hash数据结构

    遍历 hash表是一种比较简单和直观的数据结构,在查找时也有很好的性能.但是hash表不能提供有序遍历,这个是其特性决定,所以不足为奇.但是,更为实际的一个问题是如果遍历整个hash表中的所有元素? ...