环境准备

三台虚拟机:

  • Director Server
    VIP:192.168.123.123 桥接模式
    DIP:192.168.0.1 vmnet2
  • Real Server-1
    RIP1:192.168.0.10 vmnet2
  • Real Server-2
    RIP2:192.168.0.20 vmnet2

LVS-NAT.jpg

LVS-NAT拓扑结构
## 地址配置 **Director Server** 打开核心转发:
~]# echo "1" > /proc/sys/ipv4/ip_forward

配置地址:

VIP: 192.168.123.123
DIP:
    ~]# ip addr add 192.168.0.1/24 ens37    #设置vmnet2网卡地址

Real Server-1
配置地址

~]# nmtui
    ip:192.168.0.10/24
    gateway:192.168.0.1

Real Server-2

~]# nmtui
    ip:192.168.0.20/24
    gateway:192.168.0.1

打开测试httpd服务

安装httpd
Real Server-1

~]# yum install httpd -y

编辑测试页:

~]# vim /var/www/html/index.txt
编辑以下内容,方便测试
Real Server-1

Real Server-1

~]# yum install httpd -y

编辑测试页:

~]# vim /var/www/html/index.txt
编辑以下内容,方便测试
Real Server-2

ipvsadm规则定义

~]# ipvsadm -A -t 192.168.123.123:80 -s rr
  # 添加集群,调度算法为轮询
~]# ipvsadm -a -t 192.168.123.123:80 -r 192.168.0.10 -m
~]# ipvsadm -a -t 192.168.123.123:80 -r 192.168.0.20 -m
  #添加服务器,-m指定为nat模型

测试

#!/bin/bash
#
for i in {1..20};do
    curl http://192.168.123.123
done

根据返回信息,确定是否轮询。


END
Last modification:October 7th, 2019 at 08:56 pm
If you think my article is useful to you, please feel free to appreciate