LVS+keepalived能很好的实现以上的要求,LVS提 供负载均衡,keepalived提供健康检查,故障转移,提高系统的可用性!采用这样的架构以后 很容易对现有系统进行扩展,只要在后端添加或者减少realserver,只要更改lvs的 配置文件,并能实现无缝配置变更
在真实机上配置:
方法一:
1,真实机配置回环地址:
/sbin/ifconfig lo:0 192.168.1.19 broadcast 192.168.1.63 netmask 255.255.255.255 up
/sbin/route add -host 192.168.1.19 dev lo:0
2,
/sbin/ifconfig lo:0 192.168.1.19 broadcast 192.168.1.63 netmask 255.255.255.255 up
/sbin/route add -host 192.168.1.19 dev lo:0
以上命令加入/etc/rc.local(开机启动项)
3,配置ARP欺骗:
/etc/sysctl.conf添加:
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
sysctl -p 立即生效。
方法二:
创建脚本: /etc/init.d/realserve,将方法一中的命令写到该脚本中
加入开机启动: chkconfig realserve
重启服务:
service realserver start
在LVS服务器上配置:
4,LVS配置文件添加VIP和realserver:
直播服务器需要添加 80 8080端口
点播服务器需要添加80端口
vi /etc/keepalived/keeplived.conf
添加VIP:192.168.1.29
virtual_ipaddress {
192.168.1.33
192.168.1.34
192.168.1.35
192.168.1.37
192.168.1.38
192.168.1.39
192.168.1.40
192.168.1.29
}
添加realserver:
virtual_server 192.168.1.29 8080 {
delay_loop 6
lb_algo lc
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.1.43 8080 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 8080
}
}
real_server 192.168.1.44 8080 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 8080
}
}
}
virtual_server 192.168.1.29 80 {
delay_loop 6
lb_algo lc
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.1.43 80 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.1.44 80 {
weight 100
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
echo 'options ip_vs conn_tab_bits=20'>/etc/modprobe.d/ipvsadm.conf
echo "ipvsadm --set 120 10 120" >> /etc/rc.local
5,重启keepalived
service keepalived restart