LVS小试(RHEL5.4)
程序员文章站
2022-05-31 11:05:23
...
[b][size=medium][color=darkblue]1.LVS/NAT[/color][/size][/b]
原理:
配置LVS/NAT模式时外网IP不要和LoadBalance(LB)的IP同一网段(使用VMWare时两个网卡不要设置同一网段,可以一个是NAT一个是HOST)
配置LVS:
LVS的网卡信息大约如下:
配置RS,其实RS的配置就只需要设置网关:
RS_1:
RS_2:
[b][size=medium][color=darkblue]2.LVS/DR[/color][/size][/b]
原理:
LVS端的网卡需要有一个IP地址段与RS同一网段
配置LVS:
配置RS_1:
配置RS_2:
[b][size=medium][color=darkblue]3.LVS/TUN[/color][/size][/b]
原理:
RS服务器需要与外网直接通信
配置LVS:
配置RS_1:
配置RS_2:
原理:
客户端—>LVS外网IP(VIP)—>RS服务器(处理请求后通过网关返回结果)—>LVS的LB地址—>客户端
配置LVS/NAT模式时外网IP不要和LoadBalance(LB)的IP同一网段(使用VMWare时两个网卡不要设置同一网段,可以一个是NAT一个是HOST)
LVS外网IP:192.168.142.131
LVS_LB的IP:192.168.254.128
RS_1:192.168.254.129 GW 192.168.254.128
RS_2:192.168.254.130 GW 192.168.254.128
配置LVS:
iptables -F
echo "1">/proc/sys/net/ipv4/ip_forward
ipvsadm -C
ipvsadm -A -t 192.168.142.131:80 -s rr
ipvsadm -a -t 192.168.142.131:80 -r 192.168.254.129 -m -w 1
ipvsadm -a -t 192.168.142.131:80 -r 192.168.254.130 -m -w 1
LVS的网卡信息大约如下:
eth0 Link encap:Ethernet HWaddr 00:0C:29:76:38:6B
inet addr:192.168.142.131 Bcast:192.168.142.255 Mask:255.255.255.0
......
eth1 Link encap:Ethernet HWaddr 00:0C:29:76:38:75
inet addr:192.168.254.128 Bcast:192.168.254.255 Mask:255.255.255.0
......
配置RS,其实RS的配置就只需要设置网关:
RS_1:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
HWADDR=00:0c:29:3d:fe:c5
IPADDR=192.168.254.129
NETMASK=255.255.255.0
GATEWAY=192.168.254.128
service network restart
cd /var/www/html/
echo "129">index.html
apachectl start
iptables -F
RS_2:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
HWADDR=00:0c:29:3d:fe:c5
IPADDR=192.168.254.130
NETMASK=255.255.255.0
GATEWAY=192.168.254.128
service network restart
cd /var/www/html/
echo "130">index.html
apachectl start
iptables -F
[b][size=medium][color=darkblue]2.LVS/DR[/color][/size][/b]
原理:
客户端—>LVS的VIP—>RS服务器(处理请求后直接返回结果给客户端)—>客户端
LVS端的网卡需要有一个IP地址段与RS同一网段
LVS的IP:192.168.254.128
LVS的VIP:192.168.254.100
RS_1的IP:192.168.254.129
RS_1的VIP(lo:0):192.168.254.100
RS_2的IP:192.168.254.130
RS_2的VIP(lo:0):192.168.254.100
配置LVS:
vi /etc/sysctl.conf
# Controls IP packet forwarding
net.ipv4.ip_forward = 1
net.ipv4.conf.all.send_redirects = 1
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.eth1.send_redirects = 1
sysctl -p
ifconfig eth1:0 192.168.254.100 netmask 255.255.255.255 broadcast 192.168.254.100 up
route add -host 192.168.254.100 dev eth1:0
ipvsadm -C
ipvsadm -A -t 192.168.254.100:80 -s rr
ipvsadm -a -t 192.168.254.100:80 -r 192.168.254.129 -g -w 1
ipvsadm -a -t 192.168.254.100:80 -r 192.168.254.130 -g -w 1
iptables -F
配置RS_1:
vi /etc/sysctl.conf
# Controls IP packet forwarding
net.ipv4.ip_forward = 0
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
ifconfig lo:0 192.168.254.100 netmask 255.255.255.255 broadcast 192.168.254.100 up
route add -host 192.168.254.100 dev lo:0
cd /var/www/html/
echo "129">index.html
apachectl start
iptables -F
配置RS_2:
vi /etc/sysctl.conf
# Controls IP packet forwarding
net.ipv4.ip_forward = 0
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
ifconfig lo:0 192.168.254.100 netmask 255.255.255.255 broadcast 192.168.254.100 up
route add -host 192.168.254.100 dev lo:0
cd /var/www/html/
echo "130">index.html
apachectl start
iptables -F
[b][size=medium][color=darkblue]3.LVS/TUN[/color][/size][/b]
原理:
客户端—>LVS的VIP(通过IP Tunneling)—>RS服务器(处理请求后直接返回结果给客户端)—>客户端
RS服务器需要与外网直接通信
LVS的IP:192.168.254.128
LVS的VIP:192.168.254.100
RS_1的IP:192.168.254.129
RS_1的TUN IP(tunl0):192.168.254.100
RS_2的IP:192.168.254.129
RS_2的TUN IP(tunl0):192.168.254.100
配置LVS:
iptables -F
echo "0">/proc/sys/net/ipv4/ip_forward
ifconfig eth1:0 192.168.254.100 netmask 255.255.255.255 broadcast 192.168.254.100 up
route add -host 192.168.254.100 dev eth1:0
ipvsadm -C
ipvsadm -A -t 192.168.254.100:80 -s rr
ipvsadm -a -t 192.168.254.100:80 -r 192.168.254.129 -i -w 1
ipvsadm -a -t 192.168.254.100:80 -r 192.168.254.130 -i -w 1
配置RS_1:
iptables -F
ifconfig tunl0 192.168.254.100 netmask 255.255.255.255 broadcast 192.168.254.100 up
route add -host 192.168.254.100 dev tunl0
cd /var/www/html/
echo "129">index.html
apachectl start
配置RS_2:
iptables -F
ifconfig tunl0 192.168.254.100 netmask 255.255.255.255 broadcast 192.168.254.100 up
route add -host 192.168.254.100 dev tunl0
cd /var/www/html/
echo "130">index.html
apachectl start
上一篇: JSON