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

Lvs+Keepalived+Mysql

时间:2017-12-22 12:26:12      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:smt   back   pass   delay   mysql   mys   inter   启动服务   install   

环境

[root@node1 ~]# cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core) 
[root@node1 ~]# uname -a 
Linux node1 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

主机

   IP         NAME      Describe
10.0.0.10     node1       主负载
10.0.0.11     node2       备负载
10.0.0.12     node3        节点
10.0.0.13     node4        节点
10.0.0.14     node5        节点
10.0.0.20 VIP

安装

[root@node1 ~]# yum install -y ipvsadm keepalived
[root@node2 ~]# yum install -y ipvsadm keepalived

主负载配置

[root@node1 ~]# vim /etc/keepalived/keepalived.conf 

修改配置文件

! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
   vrrp_skip_check_adv_addr
   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state MASTER
    interface eno16777736
    virtual_router_id 51
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.0.20/24 dev eno16777736 label eno16777736:0
    }
}

virtual_server 10.0.0.20 3306 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 50
    protocol TCP

    real_server 10.0.0.12 3306 {
        weight 1
         MISC_CHECK {
         misc_path "/etc/keepalived/check.sh 10.0.0.12"
         misc_dynamic
         }
    }
    real_server 10.0.0.13 3306 {
        weight 1
         MISC_CHECK {
         misc_path "/etc/keepalived/check.sh 10.0.0.13"
         misc_dynamic
         }
    }
    real_server 10.0.0.14 3306 {
        weight 1
         MISC_CHECK {
         misc_path "/etc/keepalived/check.sh 10.0.0.14"
         misc_dynamic
         }
    }
}

备负载配置

[root@node2 ~]# vim /etc/keepalived/keepalived.conf 

修改配置文件

! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL_BACKUP
   vrrp_skip_check_adv_addr
   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state BACKUP
    interface eno16777736
    virtual_router_id 51
    priority 50
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.0.20/24 dev eno16777736 label eno16777736:0
    }
}

virtual_server 10.0.0.20 3306 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 50
protocol TCP

    real_server 10.0.0.12 3306 {
        weight 1
         MISC_CHECK {
         misc_path "/etc/keepalived/check.sh 10.0.0.12"
         misc_dynamic
         }
    }

    real_server 10.0.0.13 3306 {
        weight 1
         MISC_CHECK {
         misc_path "/etc/keepalived/check.sh 10.0.0.13"
         misc_dynamic
         }
    }
    real_server 10.0.0.14 3306 {
        weight 1
         MISC_CHECK {
         misc_path "/etc/keepalived/check.sh 10.0.0.14"
         misc_dynamic
         }
    }
}

自定义脚本做健康检查(node1和node2配置)

[root@node1 ~]# vim /etc/keepalived/check.sh

插入以下配置

#!/bin/bash

mysql -uwsrep -pnx111111 -h$1 -e "select 1;" &>/dev/null
ret=$?
if [ $ret -eq 0 ];then
    exit 0
else
    exit 1
fi

启动服务

[root@node1 ~]# systemctl start keepalived
[root@node2 ~]# systemctl start keepalived

测试

关闭主负载keepalived,查看VIP是否漂移到备负载

[root@node1 ~]# systemctl stop keepalived

启动主负载keepalived,查看VIP是否漂移回来

[root@node1 ~]# systemctl start keepalived

 

Lvs+Keepalived+Mysql

标签:smt   back   pass   delay   mysql   mys   inter   启动服务   install   

原文地址:http://www.cnblogs.com/wanglan/p/8085178.html

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