目录
一.实验环境
一台客户端、一台路由器、一台调度器、两台真实服务器
VMVare网络设置NAT模式子网IP为172.25.254.0,仅主机模式子网IP为192.168.0.0
1.路由器
VMVare设置eth0网卡为NAT模式,eth1为仅主机模式
XML
[root@router ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
[connection]
id=eth0
type=ethernet
interface-namw=eth0
[ipv4]
address1=172.25.254.100/24,172.25.254.2
method=manual
dns=114.114.114.114;
[root@router ~]# cat /etc/NetworkManager/system-connections/eth1.nmconnection
[connection]
id=eth1
type=ethernet
interface-namw=eth1
[ipv4]
address1=192.168.0.100/24
method=manual
2.调度器
VMVare设置eth1网卡为仅主机模式
XML
[root@LVS ~]# cat /etc/NetworkManager/system-connections/eth1.nmconnection
[connection]
id=eth1
type=ethernet
interface-namw=eth1
[ipv4]
address1=192.168.0.50/24,192.168.0.100
method=manual
3.真实服务器
VMVare设置eth0网卡为仅主机模式
XML
[root@webserver1 ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
[connection]
id=eth0
type=ethernet
interface-namw=eth0
[ipv4]
address1=192.168.0.10/24,192.168.0.100
method=manual
XML
[root@webserver2 ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
[connection]
id=eth0
type=ethernet
interface-namw=eth0
[ipv4]
address1=192.168.0.20/24,192.168.0.100
method=manual
4.客户端
VMVare设置eth0网卡为仅主机模式
XML
[root@client ~]# curl 192.168.0.200
webserver2 - 192.168.0.20
[root@client ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
[connection]
id=eth0
type=ethernet
interface-namw=eth0
[ipv4]
address1=172.25.254.200/24,172.25.254.100
method=manual
二.实验配置
1.路由器中打开内核路由器功能
XML
[root@router ~]# echo "net.ipv4.ip_forward=1" > /etc/sysctl.conf
XML
[root@router ~]# sysctl -a | grep ip_forward
net.ipv4.ip_forward = 1
net.ipv4.ip_forward_update_priority = 1
net.ipv4.ip_forward_use_pmtu = 0
2.RS主机中使vip不对外响应
XML
[root@webserver1 ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@webserver1 ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[root@webserver1 ~]# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@webserver1 ~]# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
XML
[root@webserver2 ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@webserver2 ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[root@webserver2 ~]# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@webserver2 ~]# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
3.在LVS主机和RS主机添加vip(临时添加,关机重启后需要重新添加)
XML
[root@LVS ~]# ip a a 192.168.0.200/32 dev lo
XML
[root@webserver1 ~]# ip a a 192.168.0.200/32 dev lo
XML
[root@webserver2 ~]# ip a a 192.168.0.200/32 dev lo
4.在VS中添加调度策略
XML
[root@LVS ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
[root@LVS ~]# ipvsadm -A -t 192.168.0.200:80 -s wrr
[root@LVS ~]# ipvsadm -a -t 192.168.0.200:80 -r 192.168.0.10:80 -g -w 1
[root@LVS ~]# ipvsadm -a -t 192.168.0.200:80 -r 192.168.0.20:80 -g -w 2
[root@LVS ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.0.200:80 wrr
-> 192.168.0.10:80 Route 1 0 0
-> 192.168.0.20:80
三.测试
XML
[root@client ~]# for i in {1..10}
> do
> curl 192.168.0.200
> done
webserver2 - 192.168.0.20
webserver1 - 192.168.0.10
webserver2 - 192.168.0.20
webserver2 - 192.168.0.20
webserver1 - 192.168.0.10
webserver2 - 192.168.0.20
webserver2 - 192.168.0.20
webserver1 - 192.168.0.10
webserver2 - 192.168.0.20
webserver2 - 192.168.0.20