码迷,mamicode.com
首页 > 其他好文 > 详细

keepalived实现高可用

时间:2016-11-09 22:34:21      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:tmp   sys   backup   else   oca   改变   实现   ++   notify   

1.安装依赖包

yum install -y gcc gcc-c++
yum install popt-devel openssl-devel -y

2.安装keepalived

./configure --prefix=/usr/local/

3.为了方便管理和配置,将以下文件复制

cp /usr/local/etc/rc.d/init.d/keepalived /etc/init.d/keepalived

cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/keepalived

cp /usr/local/sbin/keepalived /usr/sbin/keepalived

cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/

4.配置keepalived

node1 ip 192.168.245.122

vim /etc/keepalived/keepalived.conf


global_defs {
   router_id yang-2.com
}

vrrp_script host_check {
    script "/bin/chkhttpd.sh"
    interval 6
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 80
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass jixinga123
    }
    virtual_ipaddress {
        192.168.245.100/24
    }


track_script {
        host_check
    }
   notify_master /bin/master.sh
   notify_backup /bin/backup.sh
}

 

node2 ip 192.168.245.123

global_defs {
   router_id yang-3.com
}

vrrp_script host_check {
    script "/bin/chkhttpd.sh"
    interval 2
}
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass jixinga123
    }

    virtual_ipaddress {
        192.168.245.100/24
    }


track_script {
        host_check
    }
  notify_master /bin/master.sh
  notify_backup /bin/backup.sh
}

配置完成后启动keepalived测试即可

备注1./bin/chkhttpd.sh 内容

#!/bin/bash
grep 123 /tmp/ceshi &>/dev/null

if [ $? -ne 0 ]
then
        exit 1
else
        exit 0
fi

备注2./tmp/ceshi文件内容

123

备注3./bin/master.sh 内容

echo master > /etc/keepalived/status

备注4./bin/backup.sh内容

echo backup > /etc/keepalived/status

疑问:我也是刚接触keepalived,这是我自己做的小实验,如果我两个节点的配置文件state 一个是master,一个是backup,

state是master的主机不会执行下面的backup.sh的小脚本,它的status文件里面一直都是master,不会改变,请高手留言解答,谢谢。

 

keepalived实现高可用

标签:tmp   sys   backup   else   oca   改变   实现   ++   notify   

原文地址:http://www.cnblogs.com/yf-yy1134/p/6048750.html

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