1.安装 Atlas
#在主库安装,进入安装包目录 [root@mysql-db01 ~]# cd /home/oldboy/tools/ #下载Atlas [root@mysql-db01 tools]# wget httpss://github.com/Qihoo360/Atlas/releases/download/2.2.1/Atlas-2.2.1.el6.x86_64.rpm #安装 [root@mysql-db01 tools]# rpm -ivh Atlas-2.2.1.el6.x86_64.rpm Preparing... ########################################### [100%] 1:Atlas ########################################### [100%]
2.编辑配置文件
#进入Atlas工具目录 [root@mysql-db01 ~]# cd /usr/local/mysql-proxy/bin/ #生成密码 [root@mysql-db01 bin]# ./encrypt oldboy123 #注意这里的oldboy123是链接mysql的密码, 我们的密码是123456 他会生成如下: [root@gukai bin]# ./encrypt 123456 /iZxz+0GRoA= #生成密码的密钥对
[root@mysql-db01 ~]# vim /usr/local/mysql-proxy/conf/test.cnf #Atlas后端连接的MySQL主库的IP和端口,可设置多项,用逗号分隔 proxy-backend-addresses = 10.0.0.50:3306 #Atlas后端连接的MySQL从库的IP和端口 proxy-read-only-backend-addresses = 10.0.0.51:3306,10.0.0.52:3306 #用户名与其对应的加密过的MySQL密码 pwds = root:/iZxz+0GRoA= #SQL日志的开关 sql-log = ON #Atlas监听的工作接口IP和端口 proxy-address = 0.0.0.0:3307 #默认字符集,设置该项后客户端不再需要执行SET NAMES语句 charset = utf8
3. 启动测试
[root@mysql-db01 ~]# /usr/local/mysql-proxy/bin/mysql-proxyd test start
OK: MySQL-Proxy of test is started
4. 管理Atlas
#用atlas管理用户登录 [root@mysql-db01 ~]# mysql -uuser -ppwd -h127.0.0.1 -P2345 #查看可用命令帮助 mysql> select * from help; #查看后端代理的库 mysql> SELECT * FROM backends; +-------------+----------------+-------+------+ | backend_ndx | address | state | type | +-------------+----------------+-------+------+ | 1 | 10.0.0.51:3307 | up | rw | | 2 | 10.0.0.53:3307 | up | ro | | 3 | 10.0.0.52:3307 | up | ro | +-------------+----------------+-------+------+ #平滑摘除mysql mysql> REMOVE BACKEND 2; Empty set (0.00 sec) #检查是否摘除成功 mysql> SELECT * FROM backends; +-------------+----------------+-------+------+ | backend_ndx | address | state | type | +-------------+----------------+-------+------+ | 1 | 10.0.0.51:3307 | up | rw | | 2 | 10.0.0.52:3307 | up | ro | +-------------+----------------+-------+------+ #保存到配置文件中 mysql> SAVE CONFIG; Empty set (0.06 sec)