LVS的nat模式

目录

一.实验环境

1.调度器(VS)

2.真实服务器(RS)

3.客户端

二.实验配置

1.VS中打开内核路由器功能

2.RS装上http服务

3.VS安装LVS软件

4.在RS上输入测试内容

5.在VS进行测试

6.在VS中添加调度策略

三.客户端测试


一.实验环境

一台客户机、一台调度器、两台真实服务器

VMVare网络设置NAT模式子网IP为172.25.254.0,仅主机模式子网IP为192.168.0.0

1.调度器(VS)

VMVare设置eth0网卡为NAT模式,eth1为仅主机模式

[root@LVS ~]# 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@LVS ~]# 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.真实服务器(RS)

VMVare设置eth0网卡为仅主机模式

[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
[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

3.客户端

VMVare设置eth0网卡为NAT模式

[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.2
method=manual
dns=114.114.114.114;

二.实验配置

1.VS中打开内核路由器功能

[root@LVS boot]# echo "net.ipv4.ip_forward=1" > /etc/sysctl.conf

[root@LVS boot]# sysctl -p
net.ipv4.ip_forward = 1

2.RS装上http服务

[root@LVS ~]# yum install httpd -y

3.VS安装LVS软件

[root@LVS boot]# dnf install ipvsadm -y

4.在RS上输入测试内容

[root@webserver1 ~]# echo webserver1 - 192.168.0.10 > /var/www/html/index.html
[root@webserver1 ~]# systemctl enable --now httpd
[root@webserver2 ~]# echo webserver2 - 192.168.0.20 > /var/www/html/index.html
[root@webserver2 ~]# systemctl enable --now httpd

5.在VS进行测试

[root@LVS boot]# curl 192.168.0.10
webserver1 - 192.168.0.10
[root@LVS boot]# curl 192.168.0.20
webserver2 - 192.168.0.20

6.在VS中添加调度策略

[root@LVS boot]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

[root@LVS boot]# ipvsadm -A -t 172.25.254.100:80 -s rr
[root@LVS boot]# ipvsadm -a -t 172.25.254.100:80 -r 192.168.0.10:80 -m
[root@LVS boot]# ipvsadm -a -t 172.25.254.100:80 -r 192.168.0.20:80 -m

[root@LVS boot]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  172.25.254.100:80 rr
  -> 192.168.0.10:80              Masq    1      0          0         
  -> 192.168.0.20:80              Masq    1      0          0   

三.客户端测试

[root@client ~]# for i in {1..10}
> do
> curl 172.25.254.100
> done
webserver2 - 192.168.0.20
webserver1 - 192.168.0.10
webserver2 - 192.168.0.20
webserver1 - 192.168.0.10
webserver2 - 192.168.0.20
webserver1 - 192.168.0.10
webserver2 - 192.168.0.20
webserver1 - 192.168.0.10
webserver2 - 192.168.0.20
webserver1 - 192.168.0.10
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值