码迷,mamicode.com
首页 > 数据库 > 详细

keepalived+mysql 高可用集群

时间:2017-05-19 17:50:47      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:backup   src   back   http   keyword   type   mask   top   not   

mysql 为主主模式参考 https://my.oschina.net/sanmuyan/blog/877373

192.168.100.129 mysql 主节点/keepalived 主节点
192.168.100.130 mysql 备节点/keepalived 备节点
192.168.100.150 虚拟IP

主备节点

yum install keepalived -y
vim  /etc/keepalived/keepalived.conf
! Configuration File for keepalived

vrrp_instance VI_1 {
    state MASTER    #备节点设置为BACKUP
    interface eth0
    virtual_router_id 51 #主备保持一致
    priority 100 #备节点90
    advert_int 1
    nopreempt
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.100.150  #虚拟IP
    }
}

virtual_server 192.168.100.150 3306 { #虚拟IP
    delay_loop 6
    nat_mask 255.255.255.0
    persistence_timeout 50
    protocol TCP

    real_server 192.168.100.129 3306 { #真实IP 备节点为192.168.100.130
    weight 3
    notify_down /root/mysql.sh   #如果本地IP 3306端口宕掉 则执行该脚本(杀死keepalived进程)
    TCP_CHECK {
    connect_timeout 3   
    nb_get_retry 3       
    delay_before_retry 3 
  }
}
[root@localhost ~]# vim mysql.sh
#!/bin/bash
pkill keepalived

[root@localhost ~]# chmod +x mysql.sh 

实验

技术分享

 

说明keepalived已经开始工作

关闭主服务器  短暂的超时备服务器接管了虚拟IP

技术分享

 

keepalived进程正在运行

[root@localhost ~]# ps -el | grep keepalived
1 S     0  16274      1  0  80   0 - 27926 poll_s ?        00:00:00 keepalived
5 S     0  16275  16274  0  80   0 - 28487 poll_s ?        00:00:00 keepalived
5 S     0  16276  16274  0  80   0 - 28457 poll_s ?        00:00:00 keepalived
[root@localhost ~]# systemctl stop mysqld  关闭mysql服务

keepalived 进程已经被kill

技术分享

 

 

keepalived+mysql 高可用集群

标签:backup   src   back   http   keyword   type   mask   top   not   

原文地址:http://www.cnblogs.com/37yan/p/6879379.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!