1:登录代理端口1234
[[email protected] bin]# mysql -uroot -p -P1234 -h127.0.0.1 proxy-address项配置,例如proxy-address = 0.0.0.0:1234代表客户端应该使用1234这个端口连接Atlas来发送SQL请求。
2:登录管理端口2345
[[email protected] bin]# mysql -ugechong -p -P2345 -h127.0.0.1 admin-address项配置,例如admin-address = 0.0.0.0:2345代表DBA应该使用2345这个端口连接Atlas来执行运维管理操作。 #管理接口的用户名 admin-username = gechong #管理接口的密码 admin-password = gechong.atlas
3:管理界面
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.00 sec)
SELECT * FROM help #查看帮助 SELECT * FROM backends #查看主从节点状态 SET OFFLINE $backend_id #set offline 2; SET ONLINE $backend_id ADD MASTER $backend #add master 192.168.91.132:3306可以用来更改读写状态 ADD SLAVE $backend REMOVE BACKEND $backend_id#删除 SELECT * FROM clients # ADD CLIENT $client REMOVE CLIENT $client SELECT * FROM pwds ADD PWD $pwd ADD ENPWD $pwd REMOVE PWD $pwd SAVE CONFIG SELECT VERSION
select * from backends;
mysql> select * from backends; +-------------+---------------------+-------+------+ | backend_ndx | address | state | type | +-------------+---------------------+-------+------+ | 1 | 192.168.91.132:3306 | up | rw | | 2 | 192.168.91.144:3306 | up | ro | +-------------+---------------------+-------+------+ 2 rows in set (0.00 sec) #Atlas后端连接的MySQL主库的IP和端口,可设置多项,用逗号分隔 proxy-backend-addresses = 192.168.91.132:3306 #Atlas后端连接的MySQL从库的IP和端口,@后面的数字代表权重,用来作负载均衡,若省略则默认为1,可设置多项,用逗号分隔 proxy-read-only-backend-addresses = 192.168.91.144:[email protected]
set offline 2;
mysql> set offline 2; +-------------+---------------------+---------+------+ | backend_ndx | address | state | type | +-------------+---------------------+---------+------+ | 2 | 192.168.91.144:3306 | offline | ro | +-------------+---------------------+---------+------+ 1 row in set (0.00 sec)
mysql> select * from backends; +-------------+---------------------+---------+------+ | backend_ndx | address | state | type | +-------------+---------------------+---------+------+ | 1 | 192.168.91.132:3306 | up | rw | | 2 | 192.168.91.144:3306 | offline | ro | +-------------+---------------------+---------+------+ 2 rows in set (0.00 sec)
add master 192.168.91.144:3306
mysql> add master 192.168.91.144:3306; Empty set (0.00 sec) mysql> select * from backends; +-------------+---------------------+-------+------+ | backend_ndx | address | state | type | +-------------+---------------------+-------+------+ | 1 | 192.168.91.132:3306 | up | rw | | 2 | 192.168.91.144:3306 | up | rw | | 3 | 192.168.91.144:3306 | up | ro | +-------------+---------------------+-------+------+ 3 rows in set (0.00 sec)
remove backend 2;
mysql> set offline 2; +-------------+---------------------+---------+------+ | backend_ndx | address | state | type | +-------------+---------------------+---------+------+ | 2 | 192.168.91.144:3306 | offline | rw | +-------------+---------------------+---------+------+ 1 row in set (0.00 sec) mysql> select * from backends; +-------------+---------------------+---------+------+ | backend_ndx | address | state | type | +-------------+---------------------+---------+------+ | 1 | 192.168.91.132:3306 | up | rw | | 2 | 192.168.91.144:3306 | offline | rw | | 3 | 192.168.91.144:3306 | up | ro | +-------------+---------------------+---------+------+ 3 rows in set (0.00 sec)
mysql> remove backend 2; Empty set (0.00 sec) mysql> select * from backends; +-------------+---------------------+-------+------+ | backend_ndx | address | state | type | +-------------+---------------------+-------+------+ | 1 | 192.168.91.132:3306 | up | rw | | 2 | 192.168.91.144:3306 | up | ro | +-------------+---------------------+-------+------+ 2 rows in set (0.00 sec)
ADD PWD $pwd 用来添加登录1234端口的用户;
mysql> add pwd gechong:gechong; mysql> select * from pwds; +----------+--------------------------+ | username | password | +----------+--------------------------+ | root | sqoz56tuS587tWqbqy+SiQ== | | gechong | YenmSjAqxT4= | +----------+--------------------------+ 2 rows in set (0.00 sec) 增加允许代理接口1234的用户名和密码 另外起一个端口登录 [[email protected] bin]# mysql -ugechong -p -P1234 -h127.0.0.1 Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.0.81-log Copyright (c) 2000, 2013, 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>
该效果跟test.cnf配置一样的。pwds=root:sqoz56tuS587tWqbqy+SiQ==,gechong:YenmSjAqxT4=
ADD ENPWD $pwd 允许使用加密后的密码
mysql> select * from pwds; +----------+--------------------------+ | username | password | +----------+--------------------------+ | root | sqoz56tuS587tWqbqy+SiQ== | | gechong | YenmSjAqxT4= | +----------+--------------------------+ 2 rows in set (0.00 sec) mysql> add enpwd testlogin:YenmSjAqxT4=; Empty set (0.00 sec) mysql> select * from pwds; +-----------+--------------------------+ | username | password | +-----------+--------------------------+ | root | sqoz56tuS587tWqbqy+SiQ== | | gechong | YenmSjAqxT4= | | testlogin | YenmSjAqxT4= | +-----------+--------------------------+ 3 rows in set (0.00 sec)
时间: 2024-10-25 16:04:14