2021-06-06

本文档详细介绍了在一个单网段环境中,如何配置LVS(Linux Virtual Server)Direct Routing模式,包括客户端、路由器、LVS节点及两台后端RS(Real Server)的网络设置。通过启用IP_FORWARD,设置IPVS规则,实现了负载均衡,客户端可以通过VIP(虚拟IP)访问RS1和RS2,达到服务高可用的目的。
摘要由CSDN通过智能技术生成

LVS-DR模式单网段案例


在这里插入图片描述

环境:
一台:客户端 eth0:仅主机 192.168.10.11/24 GW:192.168.10.100

一台:ROUTER
eth0 :NAT 10.0.0.81/24
eth1: 仅主机 192.168.10.100/24
启用 IP_FORWARD

一台:LVS
eth0: NAT: DIP:10.0.0.8/24 GW:10.0.0.81 VIP:10.0.0.10/32

两台RS:
RS1:eth0:NAT:10.0.0.71/24 GW:10.0.0.81 VIP:10.0.0.10/32
RS2:eth0:NAT:10.0.0.72/24 GW:10.0.0.81 VIP:10.0.0.10/32

**

LVS的网络配置

**
client 主机环境

root@client:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.10.100  0.0.0.0         UG    0      0        0 eth0
192.168.10.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0

route的网络配置

[root@router ~]# echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf
[root@router ~]# cat /etc/sys
sysconfig/          sysctl.d/           system-release      
sysctl.conf         systemd/            system-release-cpe  
[root@router ~]# cat /etc/sysctl.conf 
。。。。。。
net.ipv4.ip_forward=1
[root@router ~]# sysctl -p
net.ipv4.ip_forward = 1
[root@router ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=10.0.0.81
PREFIX=24
[root@router ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
NAME=eth1
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.10.100
PREFIX=24

RS1/2的网络配置一样

[root@rs1 ~]#yum -y install httpd
[root@rs1 ~]#systemctl enable --now httpd
[root@rs1 ~]#cat /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=10.0.0.7
PREFIX=24
GATEWAY=10.0.0.81
ONBOOT=yes

LVS的网络配置

[root@lvs ~]#yum -y install ipvsadm
(先下载再改配置)
[root@lvs ~]#ip route
default via 10.0.0.81 dev eth0 proto static metric 100 
10.0.0.0/24 dev eth0 proto kernel scope link src 10.0.0.82 metric 100

后端RS的IPVS配置
LVS主机的配置
#RS1/2的IPVS配置

[root@rs1 ~]#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore 
[root@rs1 ~]#echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce 
[root@rs1 ~]#echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore 
[root@rs1 ~]#echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce 
[root@rs1 ~]#ifconfig lo:1 10.0.0.10/32
[root@rs1 ~]#ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet 10.0.0.10/0 scope global lo:1
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:60:f8:02 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.71/24 brd 10.0.0.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe60:f802/64 scope link 
       valid_lft forever preferred_lft forever

LVS主机的配置

 [root@lvs ~]#ifconfig lo:1 10.0.0.10/32
[root@lvs ~]#ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet 10.0.0.10/0 scope global lo:1
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:9f:f0:4a brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.82/24 brd 10.0.0.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe9f:f04a/64 scope link 
       valid_lft forever preferred_lft forever

加规则
[root@lvs ~]#ipvsadm -A -t 10.0.0.10:80 -s rr
[root@lvs ~]#ipvsadm -a -t 10.0.0.10:80 -r 10.0.0.71 -g
[root@lvs ~]#ipvsadm -a -t 10.0.0.10:80 -r 10.0.0.72 -g

root@client:~# curl 10.0.0.10
Second back end
root@client:~# curl 10.0.0.10
The first back end
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值