本文接上文介绍atlas的安装配置,以及借助keepalive软件实现altas的ha,避免由于atlas故障,导致数据库服务中断的情况出现:
一:环境介绍
Atlas 主:192.168.1.12/24
Atlas 从:192.168.1.81/24
Atlas vip: 192.168.1.230/24
Atlas write:
master:192.168.1.225/24
Slave1:192.168.1.226/24
Slave2:192.168.1.227/24
管理节点:192.168.1.12/24
Mha vip: 192.168.1.231/24
Atlas read:
Slave2:192.168.1.227/24
Slave3:192.168.1.228/24
二:安装atlas,12服务器及81服务器执行同样的操作
# grep -v '^#' /usr/local/mysql-proxy/conf/test.cnf |grep -v '^$'
# /usr/local/mysql-proxy/bin/mysql-proxyd test start
OK: MySQL-Proxy of test is started
# netstat -ntpl |grep mysql-proxy
tcp 0 0 0.0.0.0:2345 0.0.0.0:* LISTEN 29643/mysql-proxy
tcp 0 0 0.0.0.0:1234 0.0.0.0:* LISTEN 29643/mysql-proxy
# tail -f /usr/local/mysql-proxy/log/test.log
# /usr/local/mysql/bin/mysql -h 192.168.1.12 -P 1234 -u root -p123456
# /usr/local/mysql/bin/mysql -h 192.168.1.12-P 2345 -uadmin -padmin
三:安装keepalived
此处以12服务器为例,81服务器执行同样的操作
四:配置12服务器keepalive
1:keepalive主配置文件
# cat /usr/local/keepalived/etc/keepalived/keepalived.conf
2:监控atlas脚本
# cat /usr/local/scripts/monitor_atlas.sh
# chmod +x /usr/local/scripts/monitor_atlas.sh
五:配置81服务器keepalive
1:keepalive主配置文件
# cat /usr/local/keepalived/etc/keepalived/keepalived.conf
2:监控atlas脚本
# cat /usr/local/scripts/monitor_atlas.sh
# chmod +x /usr/local/scripts/monitor_atlas.sh
六:启动keepalive服务及测试
1:12服务器
# /usr/local/keepalived/sbin/keepalived -D -f /usr/local/keepalived/etc/keepalived/keepalived.conf
# tail -f /var/log/messages
2: 81服务器
# /usr/local/keepalived/sbin/keepalived -D -f /usr/local/keepalived/etc/keepalived/keepalived.conf
# tail -f /var/log/messages
3:连接atlas测试
# /usr/local/mysql/bin/mysql -h 192.168.1.230 -P 1234 -uroot -p123456
mysql> select user,host,password from mysql.user;
# /usr/local/mysql/bin/mysql -h 192.168.1.230 -P 2345 -uadmin -padmin
mysql> SELECT * FROM backends;
4:故障测试
12服务器上关闭keepalive服务
81服务器的keepalive会自动接管vip服务
# tail -f /var/log/messages
本文转自斩月博客51CTO博客,原文链接http://blog.51cto.com/ylw6006/1569276如需转载请自行联系原作者
ylw6006