Keepalived+lvs-DR
Client eth0:192.168.0.100/24
Director master eth0 192.168.0.110/24
Director backup eth0: 192.168.0.111/24
VIP eth0:1 192.168.0.130/32
Real Server A eth0 192.168.0.115/24
Real Server B eth0:192.168.0.109/24
在Directormaster上安装配置Keepalived
# tar xf keepalived-1.2.1.tar.gz
# cd keepalived-1.2.1
# ./configure --prefix=/--mandir=/usr/local/share/man/
# make
# make install
# cd /etc/keepalived/
# vim keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email{
root@localhost
}
notification_email_fromkeepalived@localhost
smtp_server127.0.0.1
smtp_connect_timeout30
router_idDirector1
}
vrrp_instance VI_1 {
stateMASTER
interfaceeth0
virtual_router_id51
priority150
advert_int1
authentication{
auth_typePASS
auth_pass1111
}
virtual_ipaddress{
192.168.0.130/32dev eth0:0
}
}
virtual_server 192.168.0.130 80 { #LVS 配置
delay_loop3
lb_algorr #LVS调度算法
lb_kindDR #LVS集群模式
nat_mask255.255.255.255
protocolTCP
real_server192.168.0.109 80 {
weight1
TCP_CHECK{
connect_timeout3
}
}
real_server192.168.0.115 80 {
weight1
TCP_CHECK{
connect_timeout3
}
}
}
# scp keepalived.conf 192.168.0.111:/etc/keepalived/
拷贝后,修改配置文件
stateBACKUP
priority100
两个Director上启动服务:
# service keepalived start
关闭防火墙和selinux
#service iptables stop
#service ip6tables stop
#setenforce 0
修改内核有关ARP解析和路由转发的
# echo 1 >/proc/sys/net/ipv4/conf/lo/arp_ignore
# echo 2 >/proc/sys/net/ipv4/conf/lo/arp_announce
# echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore
# echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce
# echo 1 > /proc/sys/net/ipv4/ip_forward
vip
# ifconfigeth0:0 192.168.0.130 netmask 255.255.255.255 broadcast 192.168.0.130 up
# route add-host 192.168.0.130 dev eth0:0
使用ipvsadm命令设置RS
# ipvsadm -C
# ipvsadm -A -t192.168.0.130:80 -s rr
# ipvsadm -a -t192.168.0.130:80 -r 192.168.0.109:80 -g
# ipvsadm -a -t192.168.0.130:80 -r 192.168.0.115:80 -g
# serviceipvsadm save #保存相关设置
ipvsadm: SavingIPVS table to /etc/sysconfig/ipvsadm: [确定]
# serviceipvsadm restart #重启服务,自动加载以上保存的设置
Director backup 配置和Director master的一样只有一个地方不一样
# vim /etc/keepalived/keepalived.conf
拷贝后,修改配置文件
stateBACKUP
priority100
Real Server A 和 Real Server B
关闭防火墙和selinux
#serviceiptables stop
#serviceip6tables stop
#setenforce 0
关闭内核的ARP解析功能
# echo 1 >/proc/sys/net/ipv4/conf/lo/arp_ignore
# echo 2 >/proc/sys/net/ipv4/conf/lo/arp_announce
# echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore
# echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce
配置虚拟IP
# ifconfig lo:0192.168.0.130 netmask 255.255.255.255 broadcast 192.168.0.130 up #VIP
# route add-host 192.168.0.130 dev lo:0 #加一条主机路由表项
配置index.html
2个server配置的一样
如何测试
1.先用client 访问虚拟IP 看看不停地刷新能否看到 2个server的页面说明可以调度
2.把master 关机看看keepalived 管不管用看下日志你会发现有新日志产生这时候再用client再去访问虚拟IP 应该还是可以看到2个server的页面
3.再把其中的一个server 关机然后继续用client 去访问虚拟IP 你会发现页面不在变化只看到剩下的一个server的页面了