安装keepalived前需要安装的包
[root@dns2 /]# yum -y install ipvsadm
[root@dns2 /]# yum -y install kernel kernel-devel
[root@dns2 /]# reboot -n
[root@dns2 /]# uname -r
2.6.18-164.el5xen
[root@dns2 /]# uname -m
i686
[root@dns2 /]# ln -s /usr/src/kernels/2.6.18-164.el5xen-i686/ /usr/src/linux
安装keepalived
wget http://www.keepalived.org/software/keepalived-1.1.19.tar.gz
# tar zxvf 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.el5xen-i686/
# make&&make install
# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
# mkdir /etc/keepalived
# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
# vi /etc/keepalived/keepalived.conf
global_defs {
notification_email {
}
notification_email_from lb@proxy
smtp_server localhost
smtp_connect_timeout 30
router_id haproxy_wf
}
vrrp_instance VI_9 { #这里的VI_1最好重新命名,且跟备机一直,并确保同段网络内没有相同的命名
state MASTER #主为MASTER
interface eth0
virtual_router_id 59 #主备配置要一样,这个值是路由的配对,不能跟其他机器一样
priority 100 #优先级,主配置必须比备机上值大
advert_int 1
authentication {
auth_type PASS
auth_pass haproxy_wf #加密串,主和备上定义必须相同
}
virtual_ipaddress {
10.13.23 .83 #定义虚IP
}
}
以下为备机配置,注意几个值不同:
global_defs {
notification_email{
}
notification_email_from lb@proxy
smtp_server localhost
smtp_connect_timeout 30
router_id haproxy_wf
}
vrrp_instance VI_9 {
state BACKUP
interface eth0
virtual_router_id 59
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass haproxy_wf
}
virtual_ipaddress {
10.13.23 .83
}
}
# service keepalived start
#tail –f /var/log/message 监听日志,查看状态,测试负载均衡及高可用性是否有效。
参考文献:
http://zhumeng8337797.blog.163.com/blog/static/100768914201191762253640/
http://rfyimcool.blog.51cto.com/1030776/680666
http://www.hz-seo.cn/?p=9