软件下载:
https://github.com/Qihoo360/Atlas/releases
配置说明:
[mysql-proxy]
#带#号的为非必需的配置项目
#管理接口的用户名
admin-username = user
#管理接口的密码
admin-password = pwd
#Atlas后端连接的MySQL主库的IP和端口,可设置多项,用逗号分隔
proxy-backend-addresses = 127.0.0.1:3306
#Atlas后端连接的MySQL从库的IP和端口,@后面的数字代表权重,用来作负载均衡,若省略则默认为1,可设置多项,用逗号分隔
#proxy-read-only-backend-addresses = 127.0.0.1:3305@1
#用户名与其对应的加密过的MySQL密码,密码使用PREFIX/bin目录下的加密程序encrypt加密,下行的user1和user2为示例,将其替换为你的MySQL
的用户名和加密密码!
pwds = user1:+jKsgB3YAG8=, user2:GS+tr4TPgqc=
#设置Atlas的运行方式,设为true时为守护进程方式,设为false时为前台方式,一般开发调试时设为false,线上运行时设为true,true后面不能
有空格。
daemon = true
#设置Atlas的运行方式,设为true时Atlas会启动两个进程,一个为monitor,一个为worker,monitor在worker意外退出后会自动将其重启,设为f
alse时只有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
配置文件模块:
[mysql-proxy]
admin-username=user
admin-password=pwd
proxy-backend-addresses=192.168.1.199:3306
proxy-read-only-backend-addresses=192.168.1.130:3306,192.168.1.145:3306
pwds=repl:tF5TeinkMj8=,mha:tF5TeinkMj8=,root:tF5TeinkMj8=
daemon=true
keepalive=true
event-threads=2
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
atlas 的几个命令
[root@s11 bin]# ls
encrypt mysql-proxy mysql-proxyd VERSION
启动atlas
/usr/local/mysql-proxy/bin/mysql-proxyd test start
1、首先登录atlas 然后执行select 及update命令(使用的用户必须在mysql数据库上存在并且在atlas 的配置文件中设置好)
atals的33060 是sql 操作界面
mysql -uroot -p -h 192.168.1.146 -P 33060
2、登录atlas 管理端进行管理
mysql -uroot -p -h 192.168.1.146 -P 345
[root@s9 ~]# mysql -h 192.168.1.146 -uuser -p -P 2345
查看帮助
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)
16 rows in set (0.00 sec)
查看后端所有的服务器
mysql> select * from backends;
+-------------+--------------------+-------+------+
| backend_ndx | address | state | type |
+-------------+--------------------+-------+------+
| 1 | 192.168.1.199:3306 | down | rw |
| 2 | 192.168.1.130:3306 | up | ro |
| 3 | 192.168.1.145:3306 | up | ro |
+-------------+--------------------+-------+------+
3 rows in set (0.00 sec)
删除后端的某一台服务器
mysql> remove backend 3;
Empty set (0.00 sec)
mysql> select * from backend;
ERROR 1105 (07000): use 'SELECT * FROM help' to see the supported commands
mysql> select * from backends;
+-------------+--------------------+-------+------+
| backend_ndx | address | state | type |
+-------------+--------------------+-------+------+
| 1 | 192.168.1.199:3306 | down | rw |
| 2 | 192.168.1.130:3306 | up | ro |
+-------------+--------------------+-------+------+
2 rows in set (0.00 sec)
将修改的配置同步到配置文件test.conf.
mysql> save config
-> ;
Empty set (0.00 sec)
mysql> save config;
Empty set (0.00 sec)
mysql> select * from backends;
+-------------+--------------------+-------+------+
| backend_ndx | address | state | type |
+-------------+--------------------+-------+------+
| 1 | 192.168.1.199:3306 | down | rw |
| 2 | 192.168.1.130:3306 | up | ro |
+-------------+--------------------+-------+------+
2 rows in set (0.00 sec)
添加后端服务器
mysql> add slave 192.168.1.145:3306;
Empty set (0.00 sec)
mysql> select * from backends;
+-------------+--------------------+-------+------+
| backend_ndx | address | state | type |
+-------------+--------------------+-------+------+
| 1 | 192.168.1.199:3306 | down | rw |
| 2 | 192.168.1.130:3306 | up | ro |
| 3 | 192.168.1.145:3306 | up | ro |
+-------------+--------------------+-------+------+
3 rows in set (0.00 sec)
mysql> save config;
Empty set (0.00 sec)
添加sql 用户
首先使用加密命令对密码进行加密:
encrypt 123.com
mysql> add pwd app:tF5TeinkMj8=;
Empty set (0.00 sec)
mysql> slave config;
ERROR 1105 (07000): use 'SELECT * FROM help' to see the supported commands
mysql> slave config;
ERROR 1105 (07000): use 'SELECT * FROM help' to see the supported commands
mysql> save config;
Empty set (0.00 sec)
mysql>
查看配置文件:
root@s11 conf]# more test.cnf
[mysql-proxy]
admin-username=user
admin-password=pwd
proxy-backend-addresses=192.168.1.199:3306
proxy-read-only-backend-addresses=192.168.1.130:3306,192.168.1.145:3306
pwds=repl:tF5TeinkMj8=,mha:tF5TeinkMj8=,root:tF5TeinkMj8=
daemon=true
keepalive=true
event-threads=2
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=