Mysql Access Middleware--A Preliminary Study of Atlas

Atlas is a MySQL protocol-based data middle-tier project developed and maintained by the infrastructure team of Qihoo 360's Web Platform Department. Based on the MySQL-Proxy 0.8.2 version officially launched by MySQL, it has modified a lot of bugs and added many features. At present, the project has been widely used in 360 company.

Atlas mainly has the following functions

1.读写分离

2.从库负载均衡

3.IP过滤

4.自动分表(目前只支持在同一个库中进行分表)

5.DBA可平滑上下线DB

6.自动摘除宕机的DB

Atlas has the following advantages over the official MySQL-Proxy

1.将主流程中所有Lua代码用C重写,Lua仅用于管理接口

2.重写网络模型、线程模型

3.实现了真正意义上的连接池

4.优化了锁机制,性能提高数十倍

The following will take you step by step to install and use the Atlas database middleware

Install the Atlas-sharding_1.0.1-el6.x86_64.rpm package

You can download the latest rpm package from https://github.com/Qihoo360/Atlas/releases website, it is recommended to use rpm package to install

Encrypted application access mysql database access password

After installing the Atlas rpm package, go to the /usr/local/mysql-proxy/bin directory and use the following command to encrypt the password

./encrypt tony

ANDKNNypf4k=   <--这个就是加密后的密码

Configure the Atlas configuration file (/usr/local/mysql-proxy/conf/opentest.cnf)

[mysql-proxy]



#带#号的为非必需的配置项目



#管理接口的用户名

admin-username = user



#管理接口的密码

admin-password = pwd12345



#Atlas后端连接的MySQL主库的IP和端口,可设置多项,用逗号分隔

proxy-backend-addresses = 10.10.57.206:3306



#Atlas后端连接的MySQL从库的IP和端口,@后面的数字代表权重,用来作负载均衡,若省略则默认为1,可设置多项,用逗号分隔

proxy-read-only-backend-addresses = 10.10.57.207:3306@1,10.10.57.208:3306@1



#用户名与其对应的加密过的MySQL密码,密码使用PREFIX/bin目录下的加密程序encrypt加密,下行的user1和user2为示例,将其替换为你的MySQL的用户名和加密密码!

pwds = tony:ANDKNNypf4k=



#设置Atlas的运行方式,设为true时为守护进程方式,设为false时为前台方式,一般开发调试时设为false,线上运行时设为true,true后面不能有空格。

daemon = true



#设置Atlas的运行方式,设为true时Atlas会启动两个进程,一个为monitor,一个为worker,monitor在worker意外退出后会自动将其重启,设为false时只有worker,没有monitor,一般开发调试时设为false,线上运行时设为true,true后面不能有空格。

keepalive = true



#工作线程数,对Atlas的性能有很大影响,推荐设置成系统的CPU核数的2至4倍

event-threads = 2



#日志级别,分为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 = REALTIME



#实例名称,用于同一台机器上多个Atlas实例间的区分

instance = opentest



#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

Start the Atlas service

/usr/local/mysql-proxy/bin/mysql-proxyd opentest start

Check Atlas Service Status

ps -ef||grep -i mysql

/usr/local/mysql-proxy/bin/mysql-proxyd opentest status

Connect to Atlas Management

mysql -h10.10.57.205 -P2345 -uuser -ppwd12345

After the connection is complete, you can use select * from help; to view the management commands that can be viewed in Atlas.
insert image description here
For example: view the read-write separation information of the mysql library

mysql> SELECT * FROM backends;

+----------+-------------------+-------+------+-------------+

| group_id | address           | state | type | backend_ndx |

+----------+-------------------+-------+------+-------------+

|       -1 | 10.10.57.206:3306 | up    | rw   |           1 |

|       -1 | 10.10.57.207:3306 | up    | ro   |           2 |

|       -1 | 10.10.57.208:3306 | up    | ro   |           3 |

+----------+-------------------+-------+------+-------------+

3 rows in set (0.00 sec)

Test the application to connect to the Atlas service

mysql -h10.10.57.205 -P1234 -utony -ptony

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 11

Server version: 5.0.81-log MySQL Community Server (GPL)



Copyright (c) 2000, 2014, 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.



mysql> 

mysql> select * from test.t_test;

+----+-------+

| id | name  |

+----+-------+

| 1  | test1 |

| 2  | test2 |

+----+-------+

2 rows in set (0.00 sec)

By viewing the sql running log, you can see that the application has achieved read-write separation and load balancing

[08/30/2018 16:48:18] C:10.10.57.208:56858 S:10.10.57.206:3306 OK 13.602 "insert into t_test values('1','test1')"

[08/30/2018 16:48:35] C:10.10.57.208:56858 S:10.10.57.206:3306 OK 12.519 "insert into t_test values('2','test2')"

[08/30/2018 16:48:47] C:10.10.57.208:56858 S:10.10.57.208:3306 OK 0.414 "select * from t_test"

[08/30/2018 16:48:47] C:10.10.57.208:56858 S:10.10.57.207:3306 OK 0.456 "select * from t_test"

[08/30/2018 16:48:48] C:10.10.57.208:56858 S:10.10.57.208:3306 OK 0.413 "select * from t_test"

Reference link:

Mysql access middleware - a preliminary study of Atlas

https://mp.weixin.qq.com/s/PYs93l0x9jzPk28VfvMAFg

Guess you like

Origin blog.csdn.net/qq_40907977/article/details/119915298