Rumah >pangkalan data >tutorial mysql >Mysql中间件代理Atlas

Mysql中间件代理Atlas

WBOY
WBOYasal
2016-06-07 14:53:071354semak imbas

本文接上文介绍 atlas 的安装配置,以及借助 keepalive 软件实现 altas 的 ha ,避免由于 atlas 故障,导致数据库服务中断的情况出现: 一:环境介绍 Atlas 主: 192.168.1.12/24 Atlas 从: 192.168.1.81/24 Atlasvip:192.168.1.230/24 Atlaswrite: master

本文接上文介绍atlas的安装配置,以及借助keepalive软件实现altasha,避免由于atlas故障,导致数据库服务中断的情况出现:

 

一:环境介绍

Atlas 主:192.168.1.12/24

Atlas 从:192.168.1.81/24

Atlas vip:  192.168.1.230/24

 

Atlas write:

master192.168.1.225/24

Slave1192.168.1.226/24

Slave2192.168.1.227/24

管理节点:192.168.1.12/24

Mha vip:  192.168.1.231/24

 

Atlas  read:

Slave2192.168.1.227/24

Slave3192.168.1.228/24 

 

二:安装atlas12服务器及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=

# grep -v '^#' /usr/local/mysql-proxy/conf/test.cnf  |grep -v '^$'

[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-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 

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 -h 192.168.1.12 -P 1234 -u root -p123456

wKioL1RQnraRQElvAAVhsfdIFeE913.jpg

# /usr/local/mysql/bin/mysql -h 192.168.1.12 -P 2345 -uadmin -padmin

wKiom1RQnn3DMFxSAAZhA29duaA866.jpg

三:安装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

1keepalive主配置文件

# 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服务器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 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/keepalived/sbin/keepalived -D -f /usr/local/keepalived/etc/keepalived/keepalived.conf 

# tail -f /var/log/messages

wKiom1RQnzTDRG2aAAo4YBIJ5v0036.jpg

wKioL1RQn5WQTUJxAAWMEqUK7C0455.jpg

2: 81服务器

# /usr/local/keepalived/sbin/keepalived -D -f /usr/local/keepalived/etc/keepalived/keepalived.conf 

# tail -f /var/log/messages

wKioL1RQn7CBa77yAAvAmEp_8JM346.jpg

3:连接atlas测试

# /usr/local/mysql/bin/mysql -h 192.168.1.230 -P 1234 -uroot -p123456

mysql> select user,host,password from mysql.user;

wKioL1RQn83jpdR-AAnzAXLp0Hs421.jpg

# /usr/local/mysql/bin/mysql -h 192.168.1.230 -P 2345 -uadmin -padmin

mysql>  SELECT * FROM backends;

wKiom1RQn47T6dMTAAZN75tM-YU288.jpg

4:故障测试

12服务器上关闭keepalive服务

wKiom1RQn7KxMkbVAAD6QyPbNY4942.jpg

81服务器的keepalive会自动接管vip服务

# tail -f /var/log/messages

wKiom1RQn8igfc58AATHfv8ywW8481.jpg

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn