Centos6.4 keepalived 安装配置
系统版本:centos6.4 64bit
软件版本:keepalived-1.2.2.tar.gz
注意:
1.防火强
Iptables –F
Service iptables stop
2.Selinux
Setenforce 0
3.依赖包安装
yum install make gcc c++ openssl-devel popt-devel
一、keepalived安装
tar zxvf keepalived-1.2.2.tar.gz
cd keepalived-1.2.2
./configure –prefix=/usr/local/keepalived
Make && make install
二、配置文件修改
Master 配置:
!Configuration File for keepalived
global_defs{
router_id TEST
}
vrrp_scriptcheck_httpd {
script "/root/check_httpd.sh"
interval 2
weight 2
}
vrrp_instanceVI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
# nopreempt
advert_int 1
mcast_src_ip 192.168.30.131
authentication {
auth_type PASS
auth_pass 8888
}
track_script {
check_httpd
}
virtual_ipaddress {
192.168.30.110
}
}
Backup 配置文件
!Configuration File for keepalived
global_defs{
router_id TEST
}
vrrp_scriptcheck_httpd {
script "/root/check_httpd.sh"
interval 2
weight 2
}
vrrp_instanceVI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 88
advert_int 1
mcast_src_ip 192.168.30.132
authentication {
auth_type PASS
auth_pass 8888
}
track_script {
check_httpd
}
virtual_ipaddress {
192.168.30.110
}
}
Check_httpd.sh 脚本
#!/bin/bash
PID=`psaux | grep apache | grep -v grep | wc -l`
echo $PID
if [ $PID-eq 0 ]
then
killall keepalived
fi
exit 0
三、测试
Master 和backup 都启动httpd服务
1、master和backup都启动keepalived 日志输出分别为
master :
Oct 18 00:24:32 centos Keepalived: StartingKeepalived v1.2.2 (10/17,2013)
Oct 18 00:24:32 centos Keepalived: StartingVRRP child process, pid=7030
Oct 18 00:24:32 centos Keepalived_vrrp:Registering Kernel netlink reflector
Oct 18 00:24:32 centos Keepalived_vrrp:Registering Kernel netlink command channel
Oct 18 00:24:32 centos Keepalived_vrrp:Registering gratutious ARP shared channel
Oct 18 00:24:33 centos Keepalived_vrrp:Opening file '/etc/keepalived/keepalived.conf'.
Oct 18 00:24:33 centos Keepalived_vrrp:Configuration is using : 63606 Bytes
Oct 18 00:24:33 centos Keepalived_vrrp:Using LinkWatch kernel netlink reflector...
Oct 18 00:24:33 centos Keepalived_vrrp: VRRPsockpool: [ifindex(2), proto(112), fd(10,11)]
Oct 18 00:24:33 centos Keepalived_vrrp:VRRP_Script(check_httpd) succeeded
Oct 18 00:24:34 centos Keepalived_vrrp:VRRP_Instance(VI_1) Transition to MASTER STATE
Oct 18 00:24:35 centos Keepalived_vrrp:VRRP_Instance(VI_1) Entering MASTER STATE
Oct 18 00:24:35 centos Keepalived_vrrp:VRRP_Instance(VI_1) setting protocol VIPs.
Oct 18 00:24:35 centos Keepalived_vrrp:VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.30.110
Oct 18 00:24:40 centosKeepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for192.168.30.110
Backup :
Oct 18 00:24:38 centos Keepalived: StartingKeepalived v1.2.2 (10/17,2013)
Oct 18 00:24:38 centos Keepalived: StartingVRRP child process, pid=1382
Oct 18 00:24:38 centos Keepalived_vrrp:Registering Kernel netlink reflector
Oct 18 00:24:38 centos Keepalived_vrrp:Registering Kernel netlink command channel
Oct 18 00:24:38 centos Keepalived_vrrp:Registering gratutious ARP shared channel
Oct 18 00:24:38 centos Keepalived_vrrp:Opening file '/etc/keepalived/keepalived.conf'.
Oct 18 00:24:38 centos Keepalived_vrrp:Configuration is using : 63604 Bytes
Oct 18 00:24:38 centos Keepalived_vrrp:Using LinkWatch kernel netlink reflector...
Oct 18 00:24:38 centos Keepalived_vrrp:VRRP_Instance(VI_1) Entering BACKUP STATE
Oct 18 00:24:38 centos Keepalived_vrrp: VRRPsockpool: [ifindex(3), proto(112), fd(10,11)]
Oct 18 00:24:38 centosKeepalived_vrrp: VRRP_Script(check_httpd) succeeded
2、master 模仿 httpd故障然后 master 和 backup日志如下
master :
Oct 18 00:27:43 centos Keepalived:Terminating on signal
Oct 18 00:27:43 centos Keepalived: StoppingKeepalived v1.2.2 (10/17,2013)
Oct 18 00:27:43 centos Keepalived_vrrp:Terminating VRRP child process on signal
Oct 18 00:27:43 centosKeepalived_vrrp: VRRP_Instance(VI_1) removing protocol VIPs.
backup :
Oct 18 00:27:47 centos Keepalived_vrrp:VRRP_Instance(VI_1) Transition to MASTER STATE
Oct 18 00:27:48 centos Keepalived_vrrp:VRRP_Instance(VI_1) Entering MASTER STATE
Oct 18 00:27:48 centos Keepalived_vrrp:VRRP_Instance(VI_1) setting protocol VIPs.
Oct 18 00:27:48 centos Keepalived_vrrp:VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.30.110
Oct 18 00:27:53 centosKeepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for192.168.30.110
注:
该文档为自己做测试撰写,欢迎拍砖。
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com