Atlas installation configuration,
Prepare the environment
192.168.1.1 (Altas) 192.168.1.2 (MySQL master) 192.168.1.3 (MySQL slave)
Link: https://github.com/Qihoo360/Atlas/wiki/Atlas%E7%9A%84%E5% AE %89%E8%A3%85
Master-slave building: http://www.cnblogs.com/cypress/p/8610279.html
1. Configure the master-slave Database Access Connection
# Set the master database in sequence and allow Atlas access to connect to mysql> grant file on *. * TO 'root' @ '192. 168.1.1 'identified BY 'root password'; # create a user # Or mysql> grant all on *. * to root @ '2017. 0.0.1 'identified by "root "; # create a user # Go To mysql> use mysql # change the host permission to "%" mysql> update user set host = '%' where user = 'root '; either of the above two methods can be mysql> select host, user, password from mysql. user; # Check whether the modification is successful mysql> flush privileges; # update the database information. Otherwise, restart the database.
Enable corresponding port: http://blog.csdn.net/u011846257/article/details/54707864
Ii. Install Atlas
Note:
(1). Atlas can only be installed and run on 64-bit systems.
(2). Centos 5.x installation Atlas-XX.el5.x86_64.rpm, Centos 6.x installation Atlas-XX.el6.x86_64.rpm.
(3) If the following error occurs when executing the installation rpm-ivh Atlas-2.2.1.el6.x86_64.rpm, it indicates that it has been installed
Preparing... ######################################## ### [100%]
Package Atlas-2.2.1-1.x86_64 is already installed
Use[root@localhost ~]# rpm -qa|grep Atlas // Query the installed Atlas
[root
@localhost
~] # Rpm-e -- nodeps file name
// Uninstall Atlas. The file name is the file queried by the preceding command.(4). the backend mysql version should be later than 5.1. We recommend that you use Mysql 5.6. 1. Download the installation package.
[root@localhost ~]# cd /home/[root@localhost home]# wget https://github.com/Qihoo360/Atlas/releases/download/2.2.1/Atlas-2.2.1.el6.x86_64.rpm
2. Installation
[root@localhost home]# rpm -ivh Atlas-2.2.1.el6.x86_64.rpm Preparing... ########################################### [100%] 1:Atlas ########################################### [100%]
Installation address
[Root @ localhost home] # ll/usr/local/mysql-proxy/total 16drwxr-xr-x. 2 root 4096 Dec 28 bin # All files under the bin directory are executable files drwxr-xr-x. 2 root 4096 Dec 28 conf # the configuration file drwxr-xr-x is put under the conf directory. 3 root 4096 Dec 28 lib # Some packages are put under the lib directory, and the dependency of Atlas on drwxr-xr-x. 2 root 4096 Dec 17 2014 log # logs are stored in the log directory, such as error messages.
3. encrypt and record the user password of the connected master-slave Database
[root@localhost bin]# cd /usr/local/mysql-proxy/bin/
[root@localhost bin]# ./encrypt hello
4. Configure Atlas and use vim for editing
[root@localhost conf]# cd /usr/local/mysql-proxy/conf/[root@localhost conf]# vim test.cnf
The configuration information is as follows. For more information, see the official website.
### 1. the configuration example and description are as follows: [mysql-proxy] (required, default) admin-username = user of the Management Interface (required, default) admin-password = pwd (required, configured as needed) admin-password = pwd (required) IP address and port proxy-backend-addresses = 192.168.0.12: 3306 of the master database (optional, configured as needed) the IP address and port of the slave database. The number after @ indicates the weight,
Proxy-read-only-backend-addresses = 192.168.0.13: 3306,192.168 .0.14: 3306 (required, configured according to the actual situation) the user name and the corresponding encrypted MySQL password, the password is encrypted using the encryption program encrypt In the PREFIX/bin directory. the user name and password are separated by a colon. You must first create the user and set the password for the master-slave database.
(The user name and password must be consistent on the master-slave database ). For example, if the user name is myuser and the password is mypwd,
Run./encrypt mypwd and the result is HJBoxfRsjeI =. Multiple users can be separated by commas. Set pwds = myuser: HJBoxfRsjeI =, myuser2: HJBoxfRsjeI =,
If it is set to false, it is the foreground mode. Generally, it is set to false during development and debugging, and truedaemon = true (required, default) for online running, if set to true, Atlas starts two processes, one of which is monitor,
If one is worker, the monitor automatically restarts after the worker unexpectedly exits. If it is set to false, only worker has no monitor. Generally, it is set to false during development and debugging, it is set to truekeepalive = true (required, configured according to the actual situation) when running online. It is recommended to set it to 2 to 4 times the number of CPU cores of the System event-threads = 4 (required, the default value is enough. There are five log levels: message, warning, critical, error, and debug. log-level = message (required, default) log storage path: log-path =/usr/local/mysql-proxy/log (required, configured according to the actual situation) SQL log switch, which can be set to OFF, ON, REALTIME, OFF indicates that SQL logs are not recorded, and ON indicates that SQL logs are recorded. In this mode, logs are refreshed Based ON the buffer. logs are flushed to the disk only after the buffer is filled. REALTIME is used for debugging. It indicates that SQL logs are recorded and written to the disk in real time. The default value is OFFsql-log = OFF (optional. When this parameter is set, only logs with execution time exceeding SQL-log-slow (unit: ms) are output. If this parameter is not set, all logs are output. SQL-log-slow = 10 (optional, not set) Disable inactive client connection settings. When this parameter is set, Atlas closes connections that have been inactive since the 'wait-timeout' time. Unit: seconds wait-timeout = 10 (required, default value) the IP address and port proxy-address of the working interface of the Atlas listener = 0.0.0.0: 1234 (required, default value) management Interface IP address and port of the Atlas listener
Admin-address = 0.0.0.0: 2345 (optional) Table sharding settings. In this example, "person" indicates the database name, "mt" indicates the table name, "id" indicates the table sharding field, and "3" indicates the number of sub-tables, you can set multiple items, separated by commas (,). If no table is specified, you do not need to set this item. The sub-table must be created in advance. The sub-table name is a table name_number and the number range is [0, number of child tables-1]. In this example, the sub-table names are mt_0, mt_1, and mt_2tables = person. mt. id.3 (optional, not set) default character set. If this item is not set, the default character set is latin1charset = utf8 (optional, not set). the IP address of the Client Connecting to Atlas is allowed, it can be an exact IP address or an IP segment separated by commas. If this option is not set, all IP addresses are allowed to connect. Otherwise, only the IP addresses in the list can connect to client-ips = 127.0.0.1, 192.168.1 (optional, rarely required) IP address of the physical Nic of LVS attached to Atlas (note that it is not a virtual IP address). If LVS is available and client-ips is set, this option must be set, otherwise, you can choose not to set lvs-ips = 192.168.1.1.
5. Start Atlas
[Root @ localhost bin] #. /mysql-proxyd test start # start OK: MySQL-Proxy of test is started [root @ localhost bin] #. /mysql-proxyd test restart # restart Atlas. [Root @ localhost bin] #./mysql-proxyd test stop # stop Atlas.
Note:
(1) The Running file is mysql-proxyd (not mysql-proxy ).
(2). test is the name of the configuration file in the conf directory.
(3) You can use ps-ef | grep mysql-proxy to check whether Atlas has been started or stopped.
6. Connect to the Atlas test. The MySQL operation interface is displayed as successful.
[Root @ localhost ~] # Yum install mysql # install the mysql client as needed. If the command cannot be found, install the client. MySQL does not need to start [root @ localhost ~]. # Mysql-h127.0.0.1-P1234-u root-p root # user configured [root @ localhost ~] # Mysql-h127.0.0.1-P2345-u user-p pwd # Administrator
You can access the help table to see what you can do.
Mysql> select * from help; # view various database management commands mysql> SELECT * FROM backends; # list the background and their statuses + -------------------------- + running + | command | description | + ------------------------------ + running + | SELECT * FROM help | shows this help | SELECT * FROM backends | lists 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 | + -------------------------- + rows + 16 rows in set (0.00 sec)
Run SQL to test and display execution information.
[Root @ localhost ~] # More/usr/local/mysql-proxy/log/test. log 20: 59: 28: (critical) network-mysqld.c.1387: plugin_call (CON_STATE_READ_QUERY) failed # key 21: 01: 22: (warning) Forbidden SQL: 192.168.3.14: 56397: delete from user; # alarm 09: 55: 22: (message) proxy listening on port 0.0.0.0: 1234 # message 09: 55: 22: (message) added read/write backend: 192.168.1.2: 3306 # write 2016-01-28 09: 55: 22: (message) added read-only backend: 192.168.1.3: 3306 # read