设为首页 加入收藏

TOP

linux LVS的DR模式实现(一)
2023-07-23 13:39:21 】 浏览:49
Tags:linux LVS

架构图:
image

环境:

一台:客户端 eth0:仅主机 192.168.10.6/24 GW:192.168.10.200

一台:ROUTER
eth0 :NAT  10.0.0.200/24
eth1: 仅主机 192.168.10.200/24
启用 IP_FORWARD

一台:LVS
eth0:NAT:DIP:10.0.0.8/24 GW:10.0.0.200

两台RS:
RS1:eth0:NAT:10.0.0.7/24   GW:10.0.0.200
RS2:eth0:NAT:10.0.0.17/24 GW:10.0.0.200

配置:
Router

[root@Router ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
TYPE=Ethernet
BOOTPROTO=none
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.200
PREFIX=24

[root@Router ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
TYPE=Ethernet
BOOTPROTO=none
NAME=eth1
DEVICE=eth1
ONBOOT=yes
IPADDR=192.168.10.200
PREFIX=24


#开启Router的ip_forward功能
[root@Router ~]# cat /etc/sysctl.d/99-sysctl.conf 
net.ipv4.ip_forward = 1

[root@Router ~]# sysctl -p
net.ipv4.ip_forward = 1

Client:

tom@Client:~$ cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
#auto eth0
#iface eth0 inet dhcp


auto eth0
iface eth0 inet static
address 192.168.10.6
netmask 255.255.255.0
gateway 192.168.10.200


tom@Client:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.10.200  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

LVS:

[root@LVS ~]# cat  /etc/sysconfig/network-scripts/ifcfg-ens160 
TYPE=Ethernet
BOOTPROTO=none
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.8
PREFIX=24
GATEWAY=10.0.0.200
DNS1=180.76.76.76


[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

#在LVS上添加VIP
ifconfig lo:1 10.0.0.100/32

#实现LVS 规则
[root@LVS ~]#dnf -y install ipvsadm
[root@LVS ~]#ipvsadm -A -t 10.0.0.100:80 -s rr
[root@LVS ~]#ipvsadm -a -t 10.0.0.100:80 -r 10.0.0.7:80 -g 
[root@LVS ~]#ipvsadm -a -t 10.0.0.100:80 -r 10.0.0.17:80 -g

[root@LVS ~]# 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 

RS1:

[root@RS1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
TYPE=Ethernet
BOOTPROTO=none
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.7
PREFIX=24
GATEWAY=10.0.0.200

[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

#设置RS1的VIP
[root@RS1 ~]# ifconfig lo:1 10.0.0.100/32

#RS1的IPVS配置
#关闭配置vip网卡的arp的两个内核参数 
#需要写入配置文件中才会重启生效
[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

#设置RS1的web服务
[root@RS1 ~]# yum -y install httpd
[root@RS1 ~]# systemctl enable --now httpd
[root@RS1 ~]# 10.0.0.17 rs1	 -I > /var/www/html/index.html
[root@RS1 ~]# curl 10.0.0.17
10.0.0.17 rs1

RS2:

[root@RS2 ~]# cat /et
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇记在CentOS7的httpd源码包安装的.. 下一篇Linux LVS-NAT模式的实现

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目