LVS 是 Linux Virtual Server 的简写,意即 Linux 虚拟服务器,是一个虚拟服务器集群系统。LVS 的实现模式常用的有三种,我们讲下第三种 Tunnel 模式,常用于跨机房分发。
网络地址
网络地址规划如表,router 需要开启转发功能 echo 1 > /proc/sys/net/ipv4/ip_forward
:
身份 | 端口 | 地址 | 网关 |
---|
client | | 192.168.18.250/24 | 192.168.18.254 |
router | eth0 | 192.168.18.254/24 | |
router | eth1 | 192.168.19.1/24 | |
lvs | eth0 | 192.168.19.254/24 | 192.168.19.1 |
lvs | tunl0 | 192.168.19.100/32 | |
rs1 | eth0 | 192.168.19.2/24 | 192.168.19.1 |
rs1 | tunl0 | 192.168.19.100/32 | |
rs2 | eth0 | 192.168.19.3/24 | 192.168.19.1 |
rs2 | tunl0 | 192.168.19.100/32 | |
数据走向
客户发起请求:
| 来源 | 目的 |
---|
MAC | client | lvs |
IP | 18.250 | 19.100 |
PORT | 33456 | 80 |
LVS 响应请求并再次封包分发请求给 RS:
| 来源 | 目的 |
---|
MAC | lvs | rs1 |
IP | 19.254 | 19.2 |
IP | 18.250 | 19.100 |
PORT | 33456 | 80 |
回应请求:
| 来源 | 目的 |
---|
IP | 18.250 | 19.100 |
PORT | 33456 | 80 |
操作步骤
1 2 3 4
| route add -host 192.168.19.100 dev tunl0 ipvsadm -A -t 192.168.19.100:80 -s rr ipvsadm -a -t 192.168.19.100:80 -r 192.168.19.2 -i ipvsadm -a -t 192.168.19.100:80 -r 192.168.19.3 -i
|
1 2 3 4 5
| route add -host 192.168.19.100 dev tunl0 echo 1 > /proc/sys/net/ipv4/conf/tunl0/arp_ignore echo 2 > /proc/sys/net/ipv4/conf/tunl0/arp_announce echo web1 > /var/www/html/index.html systemctl start httpd
|
1 2 3 4 5
| route add -host 192.168.19.100 dev tunl0 echo 1 > /proc/sys/net/ipv4/conf/tunl0/arp_ignore echo 2 > /proc/sys/net/ipv4/conf/tunl0/arp_announce echo web2 > /var/www/html/index.html systemctl start httpd
|
命令详解
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| route add -host 192.168.19.100 dev tunl0
ipvsadm -A -t 192.168.19.100:80 -s rr
ipvsadm -a -t 192.168.19.100:80 -r 192.168.19.2 -i
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
echo web1 > /var/www/html/index.html
systemctl start httpd
|
注意:如果 httpd 之前有启动,可使用 systemctl restart httpd
重启。
条评论