一、实验环境
系统:CentOS7.6
主机:5台 (虚拟机)
客户端1台:172.16.236.134/24 (NAT网卡),网关指向 172.16.236.185/24(路由服务器)
路由服务器1台:172.16.236.185/24 (NAT),192.168.214.17/16 (仅主机),附加绑定IP (10.0.0.200/8)
LVS服务器1台:VIP (10.0.0.100/32,绑定在lo网卡上),DIP (192.168.214.27/16,仅主机),网关指向 192.168.214.17/16(路由服务器)
RS1服务器1台:VIP (10.0.0.100/32,绑定在lo网卡上),RIP (192.168.214.37/16,仅主机),网关指向 192.168.214.17/16(路由服务器)
RS2服务器1台:VIP (10.0.0.100/32,绑定在lo网卡上),RIP (192.168.214.47/16,仅主机),网关指向 192.168.214.17/16(路由服务器)
软件包:ipvsadm,httpd,mod_ssl(光盘yum源)
二、相关实验
1、实现LVS跨网段DR模型
(1) 按网络规划,配置好各主机的IP
客户端服务器:eth0:172.16.236.134/24,网关 172.16.236.185
路由器服务器:eth0:172.16.236.185/24,eth1:192.168.214.17/16,网关不需配
LVS服务器:eth0:192.168.214.27/16,网关 192.168.214.17
RS1服务器:eth0:192.168.214.37/16,网关 192.168.214.17
RS2服务器:eth0:192.168.214.47/16,网关 192.168.214.17
(2) 在路由服务器上开启网络转发功能
[root@centos7-17 ~]# vim /etc/sysctl.conf net.ipv4.ip_forward=1 [root@centos7-17 ~]# sysctl -p net.ipv4.ip_forward = 1
(3) 在LVS服务器上安装ipvsadm包
[root@centos7-27 ~]# yum install -y ipvsadm
(4) 在LVS服务器上配置LVS,此处用脚本实现,脚本如下
[root@centos7-27 ~]# vim lvs_dr_vs.sh #!/bin/bash vip='10.0.0.100' #VIP iface='lo:1' #VIP绑定接口 mask='255.255.255.255' #VIP子网掩码 port='80' #端口 rs1='192.168.214.37' #RS1服务器IP rs2='192.168.214.47' #RS2服务器IP scheduler='wrr' #调度算法 type='-g' #LVS类型,-m为nat模式,-g为dr模式,-i为tun模式 case $1 in start) ifconfig $iface $vip netmask $mask #broadcast $vip up iptables -F ipvsadm -A -t ${vip}:${port} -s $scheduler ipvsadm -a -t ${vip}:${port} -r ${rs1} $type -w 1 ipvsadm -a -t ${vip}:${port} -r ${rs2} $type -w 1 ;; stop) ipvsadm -C ifconfig $iface down ;; *) echo "Usage $(basename $0) start|stop" exit 1 ;; esac
#!/bin/bash vip='10.0.0.100' iface='lo:1' mask='255.255.255.255' port='80' rs1='192.168.214.37' rs2='192.168.214.47' scheduler='wrr' type='-g' case $1 in start) ifconfig $iface $vip netmask $mask #broadcast $vip up iptables -F ipvsadm -A -t ${vip}:${port} -s $scheduler ipvsadm -a -t ${vip}:${port} -r ${rs1} $type -w 1 ipvsadm -a -t ${vip}:${port} -r ${rs2} $type -w 1 ;; stop) ipvsadm -C ifconfig $iface down ;; *) echo "Usage $(basename $0) start|stop" exit 1 ;; esac