Mysql Access Middleware--A Preliminary Study of Atlas

Keywords: Database MySQL SQL RPM

Atlas is a MySQL-based data intermediate project developed and maintained by the Infrastructure Team of Qihoo 360's Web Platform Department.On the basis of MySQL's official version of MySQL-Proxy 0.8.2, it modifies a large number of bug s and adds a lot of functional features. At present, the project is widely used in 360 companies.

Atlas has the following main functions

  1. Read-Write Separation

  2. Load Balancing From Library

  3. IP filter

  4. Automatic Tabulation (currently only supported in the same library)

  5. DBA smoothes up and down DB

  6. Automatic removal of downtime DB

Atlas has the following advantages over the official MySQL-Proxy

  1. Rewrite all Lua code in the main process in C, Lua is only used to manage interfaces

  2. Rewrite network model, thread model

  3. Realize a true connection pool

  4. Optimized locking mechanism, tens of times better performance

Let's take you step by step to install and use Atlas database middleware Install the Atlas-sharding_1.0.1-el6.x86_64.rpm package You can learn from ++. https://github.com/Qihoo360/Atlas/releases++ website to download the latest rpm package, recommended for installation Encryption application access mysql database access password
After installing the Atlas rpm package, go to the / usr/local/mysql-proxy/bin directory and encrypt the password using the following command

./encrypt tony
 ANDKNypf4k= <--This is the encrypted password

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

[mysql-proxy]
#belt#No. is not a required configuration item
#User name of management interface

admin-username = user
#Password for management interface

admin-password = pwd12345
#The IP and port of the MySQL primary library to which the Atlas backend connects, which can be set up in multiple, comma-separated ways

proxy-backend-addresses = 10.10.57.206:3306
#MySQL slave library IP and port for Atlas backend connection, @followed by a number representing weight, used for load balancing, defaults to 1 if omitted, multiple items can be set, separated by commas

proxy-read-only-backend-addresses = 10.10.57.207:3306@1,10.10.57.208:3306@1
#User name and corresponding encrypted MySQL password, password is encrypted using encrypt encryption program under PREFIX/bin directory, downstream user1 and user2 are examples, replace with your MySQL user name and encrypted password!

pwds = tony:ANDKNNypf4k=
#Set how Atlas runs, daemon when true, foreground when false, false when development debugging, true when running online, and no spaces after true.

daemon = true
#Set how Atlas runs. When set to true, Atlas starts two processes, one is monitor and the other is worker. The monitor automatically restarts the worker after it exits unexpectedly. When set to false, only worker, no monitor, generally false for development debugging, true for online runtime, and no space after true.

keepalive = true
#Number of worker threads, which has a significant impact on Atlas performance, is recommended to be set to two to four times the number of CPU cores on the system

event-threads = 2
#Log level, divided into message, warning, critical, error, debug five levels

log-level = message

#Path to log storage

log-path = /usr/local/mysql-proxy/log
#Switch on SQL log, can be set to OFF, ON, REALTIME, OFF for not logging SQL log, ON for logging SQL log, REALTIME for logging SQL log and writing to disk in real time, default is OFF

sql-log = REALTIME
#Instance name, used to distinguish between multiple Atlas instances on the same machine

instance = opentest
#Work interface IP and port for Atlas listening

proxy-address = 0.0.0.0:1234
#Management interface IP and port for Atlas listening

admin-address = 0.0.0.0:2345
#Tabulation settings, in this case, person is the library name, mt is the table name, id is the table field, and 3 is the number of subtables. Multiple items can be set separated by commas. If you do not split the table, you do not need to set this item

#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 Atlas Management

mysql -h10.10.57.205 -P2345 -uuser -ppwd12345

Once connected, you can use select * from help; view administrative commands that allow you to view Atlas

For example, view the read-write separation information for 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 Application Connection to 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 looking at the sql run 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"

Favorite students can follow my public number (db_arch) (Mysql database operations and architecture design)

Favorite students can follow my public number (db_arch) (Mysql database operations and architecture design)

Posted by JasonO on Wed, 27 Nov 2019 19:53:23 -0800