keepalived(热备份)
Keepalived的作用是检测web服务器的状态,如果有一台web服务器死机,或工作出现故障,Keepalived将检测到,并将有故障的web服务器从系统中剔除,让没问题的服务器顶上,当web服务器工作正常后再接过去原来的服务
http://www.keepalived.org/software/keepalived-1.1.19.tar.gz
MASTER主机:
# tar zxf keepalived-1.1.19.tar.gz
# cd keepalived-1.1.19
# ./configure --prefix=/usr/local/keepalived --with-kernel-dir=/usr/src/kernels/2.6.18-164.el5-i686/
# make && make intall
# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
# mkdir /etc/keepalived
# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
# vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
yang@126.com (当IP发生迁移等事件的时候发送邮件到指定邮箱)
}
notification_email_from root@yang.com (邮件发送方)
smtp_server 127.0.0.1 (邮件外发服务器地址)
smtp_connect_timeout 30 (邮件超时时间为30秒)
router_id LVS_DEVEL (一个实例的标识)
}
vrrp_instance VI_1 {
State MASTER (设置服务器模式,注要大写)
interface eth0 (实例网卡,也就是提供服务的网卡)
virtual_router_id 51
priority 100 (设定权值为100 主备之间的权值差最好大于50 权值范围为0~255)
advert_int 1 (检查时间为1秒)
authentication { (认证方式为密码认证)
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.20 (192.168.1.20并不存在)
}
}
后面的内容不用改
:wq
启动keepalived
# service keepalived start
开机自启动
# chkconfig --add keepalived
# chkconfig --level 35 keepalived on
# ip a
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:01:11:2a brd ff:ff:ff:ff:ff:ff
inet 192.168.200.128/24 brd 192.168.200.255 scope global eth0
inet 192.168.1.20/32 scope global eth0
inet6 fe80::20c:29ff:fe01:112a/64 scope link
其它主机ping192.168.1.20是可以ping通的,访问页面也是可以的
BACKUP主机:
其步骤和MASTER主机步骤一样,只需把MASTER改成BACKUP 及 priority 100 改为50即可
验证:
在MASTER主机未宕之前,BACKUP主机ip a 是不会显示192.168.1.20的,访问192.168.1.20显示的是MASTER主机的页面
而在MASTER主机宕后,BACKUP主机ip a 就可以看到192.168.1.20了,再访问192.168.1.20显示的就是BACKUP主机的页面了
本文转自linux博客51CTO博客,原文链接http://blog.51cto.com/yangzhiming/871670如需转载请自行联系原作者
yangzhimingg