LVS DR模式单网段案例

在这里插入图片描述

准备五台虚拟机
提前在RS1.2上安装上httpd
在LVS上安装ipvsadm

1、客户端 eth0 :仅主机 192.168.10.6/24 GW:192.168.10.200

2、router (路由器)
ech0:NAT 10.0.0.200/24
eth1:仅主机 192.168.10.200/24
开启路由转发 IP_FORWARD

3、:LVS
echo :NAT:DIP:10.0.0.8/24 GW:10.0.0.200

4 5 RS:
RS1: ech0:NAT:10.0.0.7/24 GW:10.0.0.200
RS2:ech0: NAT:10.0.0.17/24 GW:10.0.0.200

关闭所有主机的iptables和selinux

在客户端操作

#配置网卡 在router上开起端口转发
[root@igcllq ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE=eth0
NAME=eth0
IPADDR=192.168.10.6
PREFIX=24
GATEWAY=192.168.10.200
BOOTPROTS=static

[root@igcllq ~]# ping 10.0.0.7
PING 10.0.0.7 (10.0.0.7) 56(84) bytes of data.
64 bytes from 10.0.0.7: icmp_seq=1 ttl=63 time=3.88 ms

root@igcllq ~]# ping 10.0.0.17
PING 10.0.0.17 (10.0.0.17) 56(84) bytes of data.
64 bytes from 10.0.0.17: icmp_seq=1 ttl=63 time=0.934 ms

在router上操作

关闭ip-forward
echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf
sysctl -p

配置网卡
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
name=eth0
IPADDR=10.0.0.200
PREFIX=24
BOOTPROTS=static
ONBOOT=yes
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
name=eth1
IPADDR=192.168.10.200
PREFIX=24
BOOTPROTS=static
ONBOOT=yes

配置rs1.2

rs1配置网卡
[root@rs1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
name=eth0
IPADDR=10.0.0.7
PREFIX=24
GATEWAY=10.0.0.200
BOOTPROTS=static
ONBOOT=yes

查看路由
[root@rs1 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.0.200      0.0.0.0         UG    100    0        0 eth0
10.0.0.0        0.0.0.0         255.255.255.0   U     100    0        0 eth0

安装httpd
[root@rs1 ~]#yum -y install httpd 
[root@rs1 ~]#systemctl enable --now httpd 
[root@rs1 ~]#hostname -I > /var/www/html/index.html
[root@rs1 ~]# ping 192.168.10.6 -c1
PING 192.168.10.6 (192.168.10.6) 56(84) bytes of data.
64 bytes from 192.168.10.6: icmp_seq=1 ttl=63 time=1.46 ms

rs2配置网卡
[root@rs1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
name=eth0
IPADDR=10.0.0.17
PREFIX=24
GATEWAY=10.0.0.200
BOOTPROTS=static
ONBOOT=yes

查看路由
[root@rs2 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.0.200      0.0.0.0         UG    100    0        0 eth0
10.0.0.0        0.0.0.0         255.255.255.0   U     100    0        0 eth0
安装httpd
[root@rs2 ~]#yum -y install httpd 
[root@rs2 ~]#systemctl enable --now httpd 
[root@rs2 ~]#hostname -I > /var/www/html/index.html
[root@rs2 ~]# ping 192.168.10.6 -c1
PING 192.168.10.6 (192.168.10.6) 56(84) bytes of data.
64 bytes from 192.168.10.6: icmp_seq=1 ttl=63 time=1.46 ms

LVS配置

网络配置
[root@lvs ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE=eth0
name=eth0
IPADDR=10.0.0.8
PREFIX=24
GATEWAY=10.0.0.200
BOOTPROTS=static

[root@lvs ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.0.200      0.0.0.0         UG    100    0        0 eth0
10.0.0.0        0.0.0.0         255.255.255.0   U     100    0        0 eth0

[root@lvs ~]# ping 192.168.10.6
PING 192.168.10.6 (192.168.10.6) 56(84) bytes of data.
64 bytes from 192.168.10.6: icmp_seq=1 ttl=63 time=1.29 ms

后端RS的IPVS配置(相当于在rs1.2和LVS上开了一个单独的小通道)

RS1的IPVS配置

echo 1 >   /proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 >   /proc/sys/net/ipv4/conf/all/arp_announce
echo 1 >   /proc/sys/net/ipv4/conf/lo/arp_ignore 
echo 2 >   /proc/sys/net/ipv4/conf/lo/arp_announce 
ifconfig lo:1 10.0.0.100/32
ip a
#RS2的IPVS配置 
echo 1 >   /proc/sys/net/ipv4/conf/all/arp_ignore 
echo 1 >   /proc/sys/net/ipv4/conf/lo/arp_ignore 
echo 2 >   /proc/sys/net/ipv4/conf/all/arp_announce 
echo 2 >   /proc/sys/net/ipv4/conf/lo/arp_announce 
ifconfig lo:1 10.0.0.100/32 
ip a

在LVS上添加VIP

ifconfig lo:1 10.0.0.100/32 
ip a

在LVS上实现LVS 规则

yum -y install ipvsadm
ipvsadm -A -t 10.0.0.100:80 -s rr
ipvsadm -a -t 10.0.0.100:80 -r 10.0.0.7:80 -g
ipvsadm -a -t 10.0.0.100:80 -r 10.0.0.17:80 -g
ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  10.0.0.100:80 rr
  -> 10.0.0.7:80                  Route   1      0          0         
  -> 10.0.0.17:80                 Route   1      0          0     

测试访问(在客户端测试)

[root@igcllq ~]# curl 10.0.0.100
rs2
[root@igcllq ~]# curl 10.0.0.100
rs1
[root@igcllq ~]# curl 10.0.0.100
rs2
[root@igcllq ~]# curl 10.0.0.100
rs1
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值