首页 > 代码库 > LVS + Keepalived 配置详解
LVS + Keepalived 配置详解
LVS+Keepalived 配置
我们通过LVS-DR-MASTER,LVS-DR-BACKUP作为LVS负载均衡调度器,并且两者之间通过keepalived来两者之间的HA。keepalived本身就是为了LVS为开发的,所以说我们通过keepalived来进行LVS的配置就显得十分的方便。而且keepalived是直接操作ip_vs不用通过ipvsadm,所以更加方便。
实验拓扑图
LVS节点1配置:
# yum install popt-devel openssl openssl-devel libnl-devel ipvsadm
# tar zxvf keepalived-1.2.7.tar.gz
# mkdir /usr/local/keepalived
# cd keepalived-1.2.7
# ./configure --prefix=/usr/local/keepalived/ --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/
# make && make install
# mkdir /etc/keepalived
# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
# vim /etc/sysctl.conf
net.ipv4.ip_forward = 1 #虽然DR模式不需要开启此功能,但Keepalived 需要开启。
# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
tengqing@centaline.com.cn
}
notification_email_from tengqing@centaline.com.cn
smtp_server mail.centaline.com.cn #设置SMTP Server地址;
smtp_connect_timeout 30
router_id LVS_Node1 #备用节点名字不能相同:LVS_Node2
}
vrrp_instance VI_1 {
state MASTER #备用节点可以改为:state BACKUP
interface eth0
virtual_router_id 51
priority 100 #同组优先级不能相同
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.6.2.195
}
}
virtual_server 10.6.2.195 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 10.6.2.192 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 10.6.2.191 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
然后把 keepalived.conf 配置文件复制到备用节点上即可。
LVS + Keepalived 配置详解