Keepalived+Mysql 高可用方案
Keepalived+Mysql 高可用方案
VIP:192.168.59.100
Real Mysql-1:192.168.59.230
Real Mysql-2:192.168.59.231
实现原理: 在每台Real Mysql上安装Keepalived,设定同样的VIP,Real_server设为各自本机的mysql, 自建一个脚本用于在检测到本机Mysql 挂了以后杀死keepalived服务, 一旦keepalived服务被杀死, 外部访问VIP时将自动由另一台SERVER接受, keepalived的VIP访问原理是,哪台机器先启动keepalived,客户就连哪一台,
安装: 略 Keepalived可从CentOS系统安装包中获得
配置:
Real Mysql-1:
建立一个脚本用于在keepalived检测到mysql挂了的时候调用该脚本把keepalived杀死
vi /usr/local/script/keepalived_shutdown.sh
#!/bin/bash
pkill keepalived
当然,在这个文件你也可以加入邮件通知等功能,这里就不列举了.
配置keepalived.conf
cd /etc/keeplived/
先备份一下这个文件
cp keepalived.conf keepalived.conf.bak
vi keepalived.conf
! Configuration File for keepalived global_defs { notification_email { [email protected] [email protected] [email protected] } notification_email_from [email protected] smtp_server 192.168.200.1 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_instance VI_MYSQL { state BACKUP ## 主备库都是BACKUP,防止主库重启后,抢夺VIP资源 interface eth0 ## HA地址网卡 virtual_router_id 55 priority 100 ## 优先级,主库比备库高 nopreempt ## 非抢夺,在主库上配置,表示不抢夺VIP advert_int 1 ## 主备心跳检查间隔 authentication { auth_type PASS auth_pass 123456 } virtual_ipaddress { ## VIP,主备库一样 192.168.59.100 } } virtual_server 192.168.59.100 3306 { delay_loop 2 lb_algo wrr lb_kind DR net_mask 255.255.255.0 persistence_timeout 20 protocol TCP real_server 192.168.59.230 3306 { weight 1 notify_down "/usr/local/script/keepalived_shutdown.sh" ## 检测到realserver服务不可用时的动作 TCP_CHECK { connect_timeout 3 connect_port 3306 } } }
重启keepalived
service keepalived restart
再配另一台, 配置和上面一样,只需改一下keepalived.conf里面real_server的IP为192.168.59.231就行了
现在你可以在两台机器中做测试了,比如停了mysql看keepalive有没有被杀死,杀死后客户端有没有连到另一台SERVER上.
已有 0 人发表留言,猛击->> 这里<<-参与讨论
ITeye推荐