跳转至

36. Atlas基本管理

1. 前提

#MHA高可用+Atlas读写分离架构
#Atlas优点:可以实现在线平滑的上下线节点(添加、删除节点)

2. 连接管理接口命令

#151、161、162都可登录
mysql -uuser -ppwd -h192.168.178.152 -P2345
[root@151 ~]# mysql -uuser -ppwd -h192.168.178.152 -P2345
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 1
Server version: 5.0.99-agent-admin

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

3. 打印帮助

#显示所有命令操作及说明:select * from help;
mysql> 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.01 sec)

mysql>

4. 查看所有节点

# SELECT * FROM backends
mysql>  SELECT * FROM backends;
+-------------+----------------------+-------+------+
| backend_ndx | address              | state | type |
+-------------+----------------------+-------+------+
|           1 | 192.168.178.150:3306 | up    | rw   |
|           2 | 192.168.178.161:3306 | up    | ro   |
|           3 | 192.168.178.162:3306 | up    | ro   |
+-------------+----------------------+-------+------+
3 rows in set (0.00 sec)

mysql>

5. 删除节点

# 删除2号从库:REMOVE BACKEND 2;
mysql> remove backend 2;
Empty set (0.00 sec)

mysql>  SELECT * FROM backends;
+-------------+----------------------+-------+------+
| backend_ndx | address              | state | type |
+-------------+----------------------+-------+------+
|           1 | 192.168.178.150:3306 | up    | rw   |
|           2 | 192.168.178.162:3306 | up    | ro   |
+-------------+----------------------+-------+------+
2 rows in set (0.00 sec)

mysql>
#查看Atlas配置文件
[root@152 conf]# cat test.cnf
[mysql-proxy]
admin-username=user
admin-password=pwd
proxy-backend-addresses=192.168.178.150:3306
proxy-read-only-backend-addresses=192.168.178.161:3306,192.168.178.162:3306
pwds=root:3yb5jEku5h4=,oldboy:3yb5jEku5h4=
daemon=true
keepalive=true
event-threads=8
log-level=message
log-path=/usr/local/mysql-proxy/log
sql-log=ON
proxy-address=0.0.0.0:33060
admin-address=0.0.0.0:2345
charset=utf8
[root@152 conf]#
#执行保存到配置文件命令:
save config;

#再次查看配置文件
[root@152 conf]# cat test.cnf
[mysql-proxy]
admin-username=user
admin-password=pwd
proxy-backend-addresses=192.168.178.150:3306
proxy-read-only-backend-addresses=192.168.178.162:3306
pwds=root:3yb5jEku5h4=,oldboy:3yb5jEku5h4=
daemon=true
keepalive=true
event-threads=8
log-level=message
log-path=/usr/local/mysql-proxy/log
sql-log=ON
proxy-address=0.0.0.0:33060
admin-address=0.0.0.0:2345
charset=utf8
client-ips=
[root@152 conf]#

6. 添加节点

#添加2号从库: add slave 192.168.178.161:3306;

mysql> add slave 192.168.178.161:3306;
Empty set (0.00 sec)

mysql>  SELECT * FROM backends;
+-------------+----------------------+-------+------+
| backend_ndx | address              | state | type |
+-------------+----------------------+-------+------+
|           1 | 192.168.178.150:3306 | up    | rw   |
|           2 | 192.168.178.162:3306 | up    | ro   |
|           3 | 192.168.178.161:3306 | up    | ro   |
+-------------+----------------------+-------+------+
3 rows in set (0.00 sec)

mysql>
#查看配置文件
[root@152 conf]# cat test.cnf
[mysql-proxy]
admin-username=user
admin-password=pwd
proxy-backend-addresses=192.168.178.150:3306
proxy-read-only-backend-addresses=192.168.178.162:3306
pwds=root:3yb5jEku5h4=,oldboy:3yb5jEku5h4=
daemon=true
keepalive=true
event-threads=8
log-level=message
log-path=/usr/local/mysql-proxy/log
sql-log=ON
proxy-address=0.0.0.0:33060
admin-address=0.0.0.0:2345
charset=utf8
client-ips=
[root@152 conf]#
#执行保存到配置文件命令:
save config;

#再次查看配置文件
[root@152 conf]# cat test.cnf
[mysql-proxy]
admin-username=user
admin-password=pwd
proxy-backend-addresses=192.168.178.150:3306
proxy-read-only-backend-addresses=192.168.178.162:3306,192.168.178.161:3306
pwds=root:3yb5jEku5h4=,oldboy:3yb5jEku5h4=
daemon=true
keepalive=true
event-threads=8
log-level=message
log-path=/usr/local/mysql-proxy/log
sql-log=ON
proxy-address=0.0.0.0:33060
admin-address=0.0.0.0:2345
charset=utf8
client-ips=
[root@152 conf]#

最后更新: 2022-02-20 08:44:07