mysql的MHA之Atlas 配置, 读写分离实现
Posted gukai
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql的MHA之Atlas 配置, 读写分离实现相关的知识,希望对你有一定的参考价值。
1.安装 Atlas
#在主库安装,进入安装包目录 [[email protected]-db01 ~]# cd /home/oldboy/tools/ #下载Atlas [[email protected]-db01 tools]# wget httpss://github.com/Qihoo360/Atlas/releases/download/2.2.1/Atlas-2.2.1.el6.x86_64.rpm #安装 [[email protected]-db01 tools]# rpm -ivh Atlas-2.2.1.el6.x86_64.rpm Preparing... ########################################### [100%] 1:Atlas ########################################### [100%]
2.编辑配置文件
#进入Atlas工具目录 [[email protected]-db01 ~]# cd /usr/local/mysql-proxy/bin/ #生成密码 [[email protected]-db01 bin]# ./encrypt oldboy123 #注意这里的oldboy123是链接mysql的密码, 我们的密码是123456 他会生成如下: [[email protected] bin]# ./encrypt 123456 /iZxz+0GRoA= #生成密码的密钥对
[[email protected] ~]# 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. 启动测试
[[email protected] ~]# /usr/local/mysql-proxy/bin/mysql-proxyd test start OK: MySQL-Proxy of test is started
4. 管理Atlas
#用atlas管理用户登录 [[email protected]-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)
以上是关于mysql的MHA之Atlas 配置, 读写分离实现的主要内容,如果未能解决你的问题,请参考以下文章
专职DBA-基于MHA高可用搭建MySQL读写分离架构-Atlas