下面介绍atlas的安装和配置,以及借助keepalive软件实现altas的ha,避免由于atlas故障造成数据库服务中断:
1.环境介绍
图集:192.168.1.12/24
图集来源:192.168.1.81/24
图集vip:192.168.1.230/24
阿特拉斯写道:
主数据:192.168.1.225/24
从属1:192.168.1.226/24
从属2:192
管理节点:192.168.1.12/24
Mhavip:192.168.1.231/24
图集阅读:
从属2:192
从属3:192
第二,安装atlas,服务器12和服务器81,执行相同的 *** 作。
# yum -y install openssl openssl-devel # wget https://github.com/Qihoo360/Atlas/releases/download/2.1/Atlas-2.1.el6.x86_64.rpm # rpm -ivh Atlas-2.1.el6.x86_64.rpm # cd /usr/local/mysql-proxy/conf/ # /usr/local/mysql-proxy/bin/encrypt 123456 /iZxz+0GRoA=#'^#'/usr/local/MySQL-proxy/conf/test.cnf|'^$'
[mysql-proxy] admin-username = admin admin-password = admin proxy-backend-addresses = 192.168.1.231:3306 proxy-read-only-backend-addresses = 192.168.1.227:3306,192.168.1.228:3306 pwds = root:/iZxz+0GRoA= daemon = true keepalive = true event-threads = 8 log-level = message log-path = /usr/local/mysql-proxy/log proxy-address = 0.0.0.0:1234 admin-address = 0.0.0.0:2345#/usr/local/MySQL-proxy/bin/MySQL-proxy测试开始
好:测试的MySQL-Proxy已启动
#netstat-ntpl|grepmysql-proxy
TCP0000000:234500000:*列表EN29643/mysql-proxy
TCP0000000:123400000:*列表EN29643/mysql-proxy
#tail-f/usr/local/MySQL-proxy/log/test.log
2014-10-29 11:12:11: (message) mysql-proxy 0.8.2 started - instance: test 2014-10-29 11:12:11: (message) proxy listening on port 0.0.0.0:1234 2014-10-29 11:12:11: (message) added read/write backend: 192.168.1.231:3306 2014-10-29 11:12:11: (message) added read-only backend: 192.168.1.227:3306 2014-10-29 11:12:11: (message) chassis-unix-daemon.c:138: [angel] we try to keep PID=29643 alive2014-10-29 11:12:11: (message) added read-only backend: 192.168.1.228:3306 2014-10-29 11:12:11: (message) chassis-event-thread.c:235: starting 8 threads#/usr/local/MySQL/bin/MySQL-h192.168.1.12-P1234-uroot-P123456
#/usr/local/MySQL/bin/MySQL-h192.168.1.12-P2345-uadmin-padmin
三:安装keepalived
以服务器12为例,服务器81执行相同的 *** 作。
# cd /usr/local/src/ # wget http://www.keepalived.org/software/keepalived-1.2.13.tar.gz # tar -zxvpf keepalived-1.2.13.tar.gz # cd keepalived-1.2.13 # ./configure --prefix=/usr/local/keepalived && make && make install四:配置12台服务器keepalive
1:Keepalive主配置文件
#cat/usr/local/keepalived/etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs { router_id LVS_DEVEL } vrrp_script Monitor_Atlas { script "/usr/local/scripts/monitor_atlas.sh" interval 2 weight 2 } vrrp_instance VI_1{ state MASTER interface eth0 virtual_router_id 51 mcast_src_ip 192.168.1.12 priority 100 advert_int 1 authentication { auth_type PASS auth_pass password_123 } track_script { Monitor_Atlas } virtual_ipaddress { 192.168.1.230 } }2.监控atlas脚本
#cat/usr/local/scripts/monitor_atlas.sh
#!/bin/bash if [ $(ps -ef |grep 'mysql-proxy' |grep -v 'grep' |wc -l) -eq "0" ];then /usr/local/mysql-proxy/bin/mysql-proxyd test start sleep 5 if [ $(ps -ef |grep 'mysql-proxy' |grep -v 'grep' |wc -l) -eq "0" ];then killall -9 keepalived service network restart fi fi#chmod+x/usr/local/scripts/monitor_atlas.sh
五:配置81服务器保活
1:Keepalive主配置文件
#cat/usr/local/keepalived/etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs { router_id LVS_DEVEL } vrrp_script Monitor_Atlas { script "/usr/local/scripts/monitor_atlas.sh" interval 2 weight 2 } vrrp_instance VI_1{ state BACKUP interface eth0 virtual_router_id 51 mcast_src_ip 192.168.1.81 priority 90 advert_int 1 authentication { auth_type PASS auth_pass password_123 } track_script { Monitor_Atlas } virtual_ipaddress { 192.168.1.230 } }2.监控atlas脚本
#cat/usr/local/scripts/monitor_atlas.sh
#!/bin/bash if [ $(ps -ef |grep 'mysql-proxy' |grep -v 'grep' |wc -l) -eq "0" ];then /usr/local/mysql-proxy/bin/mysql-proxyd test start sleep 5 if [ $(ps -ef |grep 'mysql-proxy' |grep -v 'grep' |wc -l) -eq "0" ];then killall -9 keepalived service network restart fi fi#chmod+x/usr/local/scripts/monitor_atlas.sh
不及物动词启动keepalive服务并进行测试。
1:12服务器
#/usr/local/keepalive/sbin/keepalive-D-f/usr/local/keepalive/etc/keepalive/keepalive.conf
#tail-f/var/log/消息
2:81服务器
#/usr/local/keepalive/sbin/keepalive-D-f/usr/local/keepalive/etc/keepalive/keepalive.conf
#tail-f/var/log/消息
3:连接atlas测试
#/usr/local/MySQL/bin/MySQL-h192.168.1.230-P1234-uroot-P123456
mysql>从mysql.user中选择用户、主机、密码;
#/usr/local/MySQL/bin/MySQL-h192.168.1.230-P2345-uadmin-padmin
mysql>SELECT*FROM后端;
4.故障测试
12关闭服务器上的keepalive服务
81服务器的Keepalive会自动接管vip服务。
#tail-f/var/log/消息
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)