1 Atlas是360的一套基於MySQL-Proxy基礎之上的代理,修改了MySQL-Proxy的一些BUG,並優化了性能。
官方介紹:https://github.com/Qihoo360/Atlas/blob/master/README_ZH.md
官方下載: https://github.com/Qihoo360/Atlas/releases
html
本次使用的 mysql一主兩從+atlas(mysql使用percona5.7)進行讀寫分離環境部署測試。先配置mysql的一主兩從,而後安裝配置atlas。mysql
參考文章:
https://www.cnblogs.com/405845829qq/p/7873140.html
http://www.javashuo.com/article/p-qaktyfdv-es.html
linux
-----------------------------------------------------------------------------c++
2 環境準備git
機器四臺 ,系統centos7.2,2核2G,最小化安裝
github
mysql主 192.168.0.201
mysql從 192.168.0.202
mysql從 192.168.0.203
Atlas 192.168.0.204sql
設置好網絡和防火牆 網絡須要能訪問外網,
下面關閉防火牆
setenforce 0
systemctl stop firewalld
systemctl disable firewalld
sed -i 's/enforcing/disabled/g' /etc/sysconfig/selinux
設置yum源
cd /etc/yum.repos.d/
yum install vim unzip lrzsz wget net-tools -y
wget http://mirrors.aliyun.com/repo/Centos-7.repo
wget http://mirrors.aliyun.com/repo/epel-7.repo
yum -y install epel-release數據庫
先卸載系統自帶的mariadb數據庫 ()
yum -y remove mariadb*
vim
-----------------------------------------------------------------------------
後端
3 安裝Percona-Server-server-57 (三臺機器201,202,203)
執行yum安裝命令
yum install https://repo.percona.com/yum/percona-release-latest.noarch.rpm
yum install Percona-Server-server-57
安裝後的版本是5.7.26-29(5.7系列的最新版本)
------------------------------------------------------------------------------
4 配置三臺數據庫
server_id三臺數據庫要設置成不一樣的
主數據庫配置(201)
[root@localhost ]# vim /etc/my.cnf 增長下面配置 [client] default_character_set = utf8mb4 socket=/var/lib/mysql/mysql.sock [mysqld] port=3306 socket=/var/lib/mysql/mysql.sock datadir = /var/lib/mysql pid_file = /var/run/mysqld/mysql.pid character_set_server = utf8mb4 default_storage_engine = InnoDB explicit_defaults_for_timestamp federated skip-name-resolve gtid-mode = ON enforce-gtid-consistency = ON log-slave-updates = ON innodb_flush_method = O_DIRECT innodb_log_files_in_group = 2 innodb_lock_wait_timeout = 100 innodb_log_file_size = 256M innodb_flush_log_at_trx_commit = 1 innodb_file_per_table = 1 innodb_thread_concurrency = 8 innodb_buffer_pool_size = 1G innodb_read_io_threads = 24 innodb_write_io_threads = 24 log_bin_trust_function_creators=1 innodb_page_cleaners=8 innodb_lru_scan_depth=256 innodb_locks_unsafe_for_binlog = 1 innodb_autoinc_lock_mode = 2 sql_mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION group_concat_max_len = 18446744073709551615 key_buffer_size = 128M myisam_recover_options = FORCE,BACKUP lower_case_table_names=1 event_scheduler=1 max_allowed_packet = 128M max_connect_errors = 1000000 skip_name_resolve = 1 server_id = 201 log_bin = mysql-bin binlog_format = ROW sync_binlog = 1 tmp_table_size = 32M max_heap_table_size = 32M max_connections = 1000 thread_cache_size = 50 open_files_limit = 65535 table_definition_cache = 4096 table_open_cache = 5000 log_error = /var/log/mysqld.log log_queries_not_using_indexes = 0 slow_query_log = 1 long_query_time = 1 slow_query_log_file = /var/lib/mysql/mysql-slow.log relay_log = relay-bin slave_net_timeout = 60 symbolic-links = 0 transaction_isolation = READ-COMMITTED [mysql] no-auto-rehash default_character_set = utf8mb4 [xtrabackup] default-character-set = utf8mb4
從數據庫配置(202)
[root@localhost ~]# vim /etc/my.cnf 添加以下配置 [client] default_character_set = utf8mb4 socket=/var/lib/mysql/mysql.sock [mysqld] port=3306 socket=/var/lib/mysql/mysql.sock datadir = /var/lib/mysql pid_file = /var/run/mysqld/mysqld.pid character_set_server = utf8mb4 default_storage_engine = InnoDB explicit_defaults_for_timestamp federated skip-name-resolve gtid-mode = ON enforce-gtid-consistency = ON log-slave-updates = ON slave_type_conversions="ALL_NON_LOSSY" innodb_flush_method = O_DIRECT innodb_log_files_in_group = 2 innodb_lock_wait_timeout = 100 innodb_log_file_size = 256M innodb_flush_log_at_trx_commit = 1 innodb_file_per_table = 1 innodb_thread_concurrency = 8 innodb_buffer_pool_size = 1G innodb_read_io_threads = 24 innodb_write_io_threads = 24 log_bin_trust_function_creators=1 innodb_page_cleaners=4 innodb_lru_scan_depth=256 innodb_buffer_pool_instances=2 innodb_locks_unsafe_for_binlog = 1 innodb_autoinc_lock_mode = 2 sql_mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION group_concat_max_len = 18446744073709551615 key_buffer_size = 128M myisam_recover_options = FORCE,BACKUP lower_case_table_names=1 event_scheduler=1 slave_pending_jobs_size_max = 128M max_allowed_packet = 128M max_connect_errors = 1000000 skip_name_resolve = 1 slave-skip-errors=1007,1008,1032,1062 server_id = 202 log_bin = mysql-bin binlog_format = ROW sync_binlog = 1 tmp_table_size = 32M max_heap_table_size = 32M max_connections = 1000 thread_cache_size = 50 open_files_limit = 65535 table_definition_cache = 4096 table_open_cache = 5000 log_error = /var/log/mysqld.log log_queries_not_using_indexes = 0 slow_query_log = 1 long_query_time = 1 slow_query_log_file = /var/lib/mysql/mysql-slow.log relay_log = relay-bin slave_net_timeout = 60 symbolic-links = 0 slave-parallel-type=LOGICAL_CLOCK slave-parallel-workers=16 master_info_repository=TABLE relay_log_info_repository=TABLE relay_log_recovery=ON [mysql] no-auto-rehash default_character_set = utf8mb4 [xtrabackup] default-character-set = utf8mb4
從數據庫配置(203)
[root@localhost ~]# vim /etc/my.cnf 添加以下配置 [client] default_character_set = utf8mb4 socket=/var/lib/mysql/mysql.sock [mysqld] port=3306 socket=/var/lib/mysql/mysql.sock datadir = /var/lib/mysql pid_file = /var/run/mysqld/mysqld.pid character_set_server = utf8mb4 default_storage_engine = InnoDB explicit_defaults_for_timestamp federated skip-name-resolve gtid-mode = ON enforce-gtid-consistency = ON log-slave-updates = ON slave_type_conversions="ALL_NON_LOSSY" innodb_flush_method = O_DIRECT innodb_log_files_in_group = 2 innodb_lock_wait_timeout = 100 innodb_log_file_size = 256M innodb_flush_log_at_trx_commit = 1 innodb_file_per_table = 1 innodb_thread_concurrency = 8 innodb_buffer_pool_size = 1G innodb_read_io_threads = 24 innodb_write_io_threads = 24 log_bin_trust_function_creators=1 innodb_page_cleaners=4 innodb_lru_scan_depth=256 innodb_buffer_pool_instances=2 innodb_locks_unsafe_for_binlog = 1 innodb_autoinc_lock_mode = 2 sql_mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION group_concat_max_len = 18446744073709551615 key_buffer_size = 128M myisam_recover_options = FORCE,BACKUP lower_case_table_names=1 event_scheduler=1 slave_pending_jobs_size_max = 128M max_allowed_packet = 128M max_connect_errors = 1000000 skip_name_resolve = 1 slave-skip-errors=1007,1008,1032,1062 server_id = 203 log_bin = mysql-bin binlog_format = ROW sync_binlog = 1 tmp_table_size = 32M max_heap_table_size = 32M max_connections = 1000 thread_cache_size = 50 open_files_limit = 65535 table_definition_cache = 4096 table_open_cache = 5000 log_error = /var/log/mysqld.log log_queries_not_using_indexes = 0 slow_query_log = 1 long_query_time = 1 slow_query_log_file = /var/lib/mysql/mysql-slow.log relay_log = relay-bin slave_net_timeout = 60 symbolic-links = 0 slave-parallel-type=LOGICAL_CLOCK slave-parallel-workers=16 master_info_repository=TABLE relay_log_info_repository=TABLE relay_log_recovery=ON [mysql] no-auto-rehash default_character_set = utf8mb4 [xtrabackup] default-character-set = utf8mb4
---------------------------------------------------------------
5 初始化三臺機器的數據庫
修改完配置後 初始化數據庫
[root@localhost ~]# mysqld --initialize --user=mysql
啓動數據庫
[root@localhost ~]# systemctl start mysqld
查看數據庫進程
[root@localhost ~]# ps -ef |grep mysql mysql 12089 1 13 12:08 ? 00:00:02 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid root 12174 11932 0 12:08 pts/1 00:00:00 grep --color=auto mysql
查詢初始化密碼
grep "password" /var/log/mysqld.log
[root@localhost ~]# grep "password" /var/log/mysqld.log 2019-07-11T04:07:31.642390Z 1 [Note] A temporary password is generated for root@localhost: eF(pg?&wr9,v
修改root密碼爲Pass_123
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Pass_123';
[root@localhost ~]# mysql -uroot -p Enter password: eF(pg?&wr9,v mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Pass_123'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
---------------------------------------------------------------------------------
6 配置主從同步
在主機器上建立同步帳號
在主數據庫機器上建立同步帳號repl:123456 同時受權root用戶給% [root@localhost ~]# mysql -uroot -pPass_123 mysql> grant all on *.* to root@'%' identified by "Pass_123"; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> grant all on *.* to repl@'%' identified by "123456"; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> create user 'repl'@'192.168.0.202' identified by '123456'; Query OK, 0 rows affected (0.01 sec) mysql> create user 'repl'@'192.168.0.203' identified by '123456'; Query OK, 0 rows affected (0.00 sec) mysql> grant replication slave on *.* to 'repl'@'192.168.0.202'; Query OK, 0 rows affected (0.00 sec) mysql> grant replication slave on *.* to 'repl'@'192.168.0.203'; Query OK, 0 rows affected (0.02 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> quit
查看主庫狀態 (用於從庫設置同步參數)
mysql> show master status; +------------------+----------+--------------+------------------+------------------------------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+------------------------------------------+ | mysql-bin.000002 | 1632 | | | 6766c88d-a391-11e9-a0b0-000c2960d4ff:1-7 | +------------------+----------+--------------+------------------+------------------------------------------+ 1 row in set (0.00 sec)
在兩個slave上執行配置主從
mysql> change master to -> master_host='192.168.0.201', -> master_user='repl', -> master_password='123456', -> master_log_file='mysql-bin.000002', -> master_log_pos=1632; Query OK, 0 rows affected, 2 warnings (0.06 sec) 啓動slave mysql> start slave; Query OK, 0 rows affected (0.13 sec) mysql> show slave status\G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.0.201 Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000002 Read_Master_Log_Pos: 1632 Relay_Log_File: relay-bin.000002 Relay_Log_Pos: 320 Relay_Master_Log_File: mysql-bin.000002 Slave_IO_Running: Yes ##必須是yes Slave_SQL_Running: Yes ##必須是yes Replicate_Do_DB: Replicate_Ignore_DB:
----------------------------------------------------------------------------------------
7 測試主從同步是否正常,主庫上建立庫和表,看從庫是否同步成功
在主庫上::: mysql> create database yan; Query OK, 1 row affected (0.01 sec) mysql> create database lili; Query OK, 1 row affected (0.00 sec) mysql> create database masu; Query OK, 1 row affected (0.00 sec) mysql> use yan Database changed mysql> create table tom (id int not null,name varchar(100)not null ,age tinyint); Query OK, 0 rows affected (0.04 sec) mysql> insert tom (id,name,age) values(1,'zhangshan',20),(2,'wangwu',7),(3,'lisi',23); Query OK, 3 rows affected (0.08 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> select * from tom; +----+-----------+------+ | id | name | age | +----+-----------+------+ | 1 | zhangshan | 20 | | 2 | wangwu | 7 | | 3 | lisi | 23 | +----+-----------+------+ 3 rows in set (0.00 sec) mysql> 在從庫上查詢驗證 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | lili | | masu | | mysql | | performance_schema | | sys | | yan | +--------------------+ 7 rows in set (0.01 sec) mysql> use yan Database changed mysql> select * from tom; +----+-----------+------+ | id | name | age | +----+-----------+------+ | 1 | zhangshan | 20 | | 2 | wangwu | 7 | | 3 | lisi | 23 | +----+-----------+------+ 3 rows in set (0.00 sec) mysql> 兩臺slave均同步成功
-----------------------------------------------------------------------------
8 使用Atlas實現讀寫分離
到204上安裝Atlas
安裝依賴 (204機器不能安裝數據庫yum remove Percona-Server*)
yum -y install libevent glib2 lua gcc gcc-c++ autoconf mysql-devel libtool pkgconfig ncurses ncurses-devel libevent-devel
下載Atlas包
wget https://github.com/Qihoo360/Atlas/releases/download/2.2.1/Atlas-2.2.1.el6.x86_64.rpm
安裝atlas
yum install Atlas-2.2.1.el6.x86_64.rpm -y
安裝後查看軟件包內容
[root@localhost home]# ll /usr/local/mysql-proxy/ 總用量 4 drwxr-xr-x 2 root root 71 7月 11 13:33 bin drwxr-xr-x 2 root root 21 7月 11 13:33 conf drwxr-xr-x 3 root root 4096 7月 11 13:33 lib drwxr-xr-x 2 root root 6 12月 17 2014 log [root@localhost home]# ll /usr/local/mysql-proxy/bin/ 總用量 44 -rwxr-xr-x 1 root root 9696 12月 17 2014 encrypt -rwxr-xr-x 1 root root 23564 12月 17 2014 mysql-proxy -rwxr-xr-x 1 root root 1552 12月 17 2014 mysql-proxyd -rw-r--r-- 1 root root 6 12月 17 2014 VERSION [root@localhost home]# ll /usr/local/mysql-proxy/conf/ 總用量 4 -rw-r--r-- 1 root root 2810 12月 17 2014 test.cnf bin目錄下放的都是可執行文件 「encrypt」是用來生成MySQL密碼加密的,在配置的時候會用到 「mysql-proxy」是MySQL本身的讀寫分離代理 「mysql-proxyd」是360弄出來的,後面有個「d」,服務的啓動、重啓、中止。都是用他來執行的 conf目錄下放的是配置文件 「test.cnf」只有一個文件,用來配置代理的,可使用vim來編輯 lib目錄下放的是一些包,以及Atlas的依賴 log目錄下放的是日誌,如報錯等錯誤信息的記錄
---------------------------------------------------------------------------
9 配置啓動 Atlas
***使用encrypt來對須要代理的數據庫的密碼進行加密,配置文件裏要用,
帳號:repl,密碼:123456 帳號:root,密碼:Pass_123
[root@localhost home]# /usr/local/mysql-proxy/bin/encrypt 123456
/iZxz+0GRoA=
[root@localhost yum.repos.d]# /usr/local/mysql-proxy/bin/encrypt Pass_123
oIqxCTi4FY8a8s/oWZlMvQ==
那麼配置文件中pwds 一項能夠設置爲 pwds = repl:/iZxz+0GRoA= 或者pwds = root:oIqxCTi4FY8a8s/oWZlMvQ==
配置文件:
vim /usr/local/mysql-proxy/conf/test.cnf [mysql-proxy] admin-username = user admin-password = pwd proxy-backend-addresses = 192.168.0.201:3306 proxy-read-only-backend-addresses = 192.168.0.202:3306@1,192.168.0.203:3306@1 pwds = repl:/iZxz+0GRoA= daemon = true keepalive = true event-threads = 8 log-level = message log-path = /usr/local/mysql-proxy/log proxy-address = 0.0.0.0:1234 admin-address = 0.0.0.0:2345 charset = utf8
++++++++++++++++++++++++++++++++++++++
配置文件參數解讀:
[mysql-proxy] #帶#號的爲非必需的配置項目 #管理接口的用戶名 admin-username = user #管理接口的密碼 admin-password = pwd #Atlas後端鏈接的MySQL主庫的IP和端口,可設置多項,用逗號分隔 proxy-backend-addresses = 192.168.0.201:3306 #Atlas後端鏈接的MySQL從庫的IP和端口,@後面的數字表明權重,用來做負載均衡,若省略則默認爲1,可設置多項,用逗號分隔 proxy-read-only-backend-addresses = 192.168.0.202:3306@1,192.168.0.203:3306@1 #用戶名與其對應的加密過的MySQL密碼,密碼使用PREFIX/bin目錄下的加密程序encrypt加密,下行的user1和user2爲示例,將其替換爲你的MySQL的用戶名和加密密碼! pwds = repl:/iZxz+0GRoA= #設置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
++++++++++++++++++++++++++++++++++++++
啓動atlas
/usr/local/mysql-proxy/bin/mysql-proxyd test start
[root@localhost ]# /usr/local/mysql-proxy/bin/mysql-proxyd test start OK: MySQL-Proxy of test is started
安裝數據庫(爲了使用mysql命令)
yum install mysql-server mysql -y ##安裝後不可啓動
登錄proxy查看,使用proxy管理接口2345 管理帳戶 user:pwd
mysql -h127.0.0.1 -P2345 -uuser -ppwd
[root@localhost ]# mysql -h127.0.0.1 -P2345 -uuser -ppwd MySQL [(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) MySQL [(none)]>
使用數據庫工做接口1234來訪問 mysql -h127.0.0.1 -P1234 -urepl -p123456
MySQL [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | lili | | masu | | mysql | | performance_schema | | sys | | yan | +--------------------+ 7 rows in set (0.00 sec)
使用代理機器,在代理上訪問數據庫正常
----------------------------------------------------------------------------------
10 驗證查詢 讀的分發負載
在salve機器上,用下面命令查詢訪問量 show global status like 'Question%'; mysql202 > show global status like 'Question%'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | Questions | 100 | +---------------+-------+ 1 row in set (0.01 sec) mysql203 > show global status like 'Question%'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | Questions | 100 | +---------------+-------+ 1 row in set (0.01 sec) 該命令每執行一次,量加1, 當兩個機器都調到相等時候好比100, 去proxy機器執行一次 show databases;查詢, 而後回到salve機器執行查看,步長爲2的即爲訪問的機器) proxy機器上使用工做接口來訪問 mysql -h127.0.0.1 -P1234 -urepl -p123456 MySQL [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | lili | | masu | | mysql | | performance_schema | | sys | | yan | +--------------------+ 7 rows in set (0.00 sec) MySQL [(none)]> 202機器上: mysql202 > show global status like 'Question%'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | Questions | 101 | +---------------+-------+ 1 row in set (0.01 sec) 203機器上 mysql203 > show global status like 'Question%'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | Questions | 102 | +---------------+-------+ 1 row in set (0.01 sec) 上面查詢結果說明訪問的是203機器 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 而後將202機器調整到102訪問量(再執行一次 show global status like 'Question%';) mysql202 > show global status like 'Question%'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | Questions | 102 | +---------------+-------+ 1 row in set (0.01 sec) 接着去proxy機器執行一次show databases;查詢, MySQL [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | lili | | masu | | mysql | | performance_schema | | sys | | yan | +--------------------+ 7 rows in set (0.00 sec) MySQL [(none)]> 而後回到salve機器執行查看show global status like 'Question%'; mysql202 > show global status like 'Question%'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | Questions | 104 | +---------------+-------+ 1 row in set (0.01 sec) mysql203 > show global status like 'Question%'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | Questions | 103 | +---------------+-------+ 1 row in set (0.01 sec) 說明此次訪問的是202機器,讀分發成功正常。
到此atlas 實現了讀寫分離和讀負載均衡,更過內容能夠參考atlas和Percona 官網學習。