LVS项目介绍 http://www.linuxvirtualserver.org/zh/lvs1.html
LVS集群的体系结构 http://www.linuxvirtualserver.org/zh/lvs2.html
LVS集群中的IP负载均衡技术 http://www.linuxvirtualserver.org/zh/lvs3.html
LVS集群的负载调度 http://www.linuxvirtualserver.org/zh/lvs4.html
LVS的四种工作模式
缩写及全拼:
NAT(Network Address Translation)
TUN(Tunneling)
DR(Direct Routing)
DR模式:直接路由模式
FULLNAT(Full Network Address Translation)
安装部署LVS:
yum install ipvsadm -y
ln -s /usr/src/kernels/2.6.32-573.el6.x86_64/ /usr/src/linux
[root@lb01 ~]# lsmod |grep ip_vs #查看内核模块
ip_vs_rr 1420 0
ip_vs 126534 2 ip_vs_rr
libcrc32c 1246 1 ip_vs
ipv6 335589 137 ip_vs
【负载均衡器上操作】:
[root@lb01 ~]# ipvsadm -C
[root@lb01 ~]# ipvsadm --set 30 5 60
[root@lb01 ~]# ipvsadm -A -t 10.0.0.3:80 -s wrr -p 20
[root@lb01 ~]# ipvsadm -a -t 10.0.0.3:80 -r 10.0.0.7:80 -g -w 1
[root@lb01 ~]# ipvsadm -a -t 10.0.0.3:80 -r 10.0.0.8:80 -g -w 1
[root@lb01 ~]# ipvsadm -L -n
ipvsadm -C <== -C clear the whole table 清除所有表
ipvsadm --set 30 5 60 <== --set tcp tcpfin udp set connection timeout values
ipvsadm -A -t 10.0.0.3:80 -s wrr --add-service -A add virtual service with options
#ipvsadm -A -t 10.0.0.3:80 -s wrr -p 20 ### -s 调度 -p 会话保持
ipvsadm -a -t 10.0.0.3:80 -r 10.0.0.7:80 -g -w 1
ipvsadm -a -t 10.0.0.3:80 -r 10.0.0.5:80 -g -w 1
# ipvsadm -a|e -t|u|f service-address -r server-address [options]
【客户端操作】:
ip addr add 10.0.0.3/32 dev lo label lo:3
route add -host 10.0.0.3 dev lo
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
修改keepalived配置文件:
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.3/24 dev eth0 label eth0:3
}
}
vrrp_instance VI_2 {
state BACKUP
interface eth0
virtual_router_id 52
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1112
}
virtual_ipaddress {
10.0.0.4/24 dev eth0 label eth0:4
}
}
#ipvsadm -A -t 10.0.0.3:80 -s wrr -p 20
virtual_server 10.0.0.3 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
#ipvsadm -a -t 10.0.0.3:80 -r 10.0.0.7:80 -g -w 1
real_server 10.0.0.7 80 {
weight 1
TCP_CHECK {
connect_timeout 8
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
#ipvsadm -a -t 10.0.0.3:80 -r 10.0.0.8:80 -g -w 1
real_server 10.0.0.8 80 {
weight 1
TCP_CHECK {
connect_timeout 8
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}