运维——LVS部署-DR模式(wlc模式为例)

实验环境:客户端IP地址为192.168.4.10(CIP是客户端的IP地址)
LVS调度器VIP地址为192.168.4.15 (VIP是对客户端提供服务的IP地址)
LVS调度器DIP地址设置为192.168.4.5 (DIP是调度器与后端服务器通信的IP地址)
真实Web服务器地址分别为192.168.4.100、192.168.4.200 (RIP是后端服务器的真实IP地址)
**实验目的:**使用加权最少链接算法,web1的权重为1,web2的权重为2
实验拓扑图
在这里插入图片描述
在这里插入图片描述

                                                                      *拓扑图可以用华为eNSP软件设计*

1、 设置Proxy代理服务器的VIP和DIP

注意:为了防止冲突,VIP必须要配置在网卡的虚拟接口
 [[email protected] ~]# nmcli connection modify eth0 ipv4.method manual ipv4.addresses 192.168.4.100/24 connection.autoconnect yes #设置ip地址,此处是一行
 [[email protected] ~]# nmcli connection up eth0
 [[email protected] ~]# cp /etc/sysconfig/network-scripts/ifcfg-eth0{,:0} #复制一张虚拟网卡
 [[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0:0 #修改以下参数
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
NAME=eth0:0
DEVICE=eth0:0
ONBOOT=yes
IPADDR=192.168.4.15
PREFIX=24
IPV4_FAILURE_FATAL=no
IPV6INIT=no
#复制出来的虚拟网卡,uuid必须删除
[[email protected] ~]# systemctl restart network #重启网卡

2、 设置web1服务器网络参数

 [[email protected] ~]# nmcli connection modify eth0 ipv4.method manual ipv4.addresses 192.168.4.100/24 connection.autoconnect yes #设置ip地址,此处是一行
 [[email protected] ~]# nmcli connection up eth0 #启动网卡
 [[email protected] ~]# cp /etc/sysconfig/network-scripts/ifcfg-lo{,:0} #复制虚拟网卡
 [[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-lo:0 #修改以下参数,使ifcfg-lo:0虚拟网卡成为主机型网卡
DEVICE=lo:0
IPADDR=192.168.4.15 #ip地址
NETMASK=255.255.255.255 #子网掩码
NETWORK=192.168.4.15 #网络地址

#If you’re having problems with gated making 127.0.0.0/8 a martian, # you can #change this to something else (255.255.255.255, for example)

BROADCAST=192.168.4.15 #广播地址
ONBOOT=yes
NAME=lo:0
 sysctl.conf文件写入这下面四行的主要目的就是访问192.168.4.15的数据包,只有调度器会响应,其他主机都不做任何响应,防止地址冲突的问题。
 [[email protected] ~]# vim /etc/sysctl.conf
#手动写入如下4行内容
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_announce = 2
#当有arp广播问谁是192.168.4.15时,本机忽略该ARP广播,不做任何回应
#本机不要向外宣告自己的lo回环地址是192.168.4.15
 [[email protected] ~]# sysctl –p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_announce = 2
 [[email protected] ~]systemctl restart network

3、设置Web2服务器网络参数 (步骤和web1一致)

 [[email protected] ~]# nmcli connection modify eth0 ipv4.method manual ipv4.addresses
192.168.4.200/24 connection.autoconnect yes
 [[email protected] ~]# nmcli connection up eth0 #启动网卡
 [[email protected] ~]# cp /etc/sysconfig/network-scripts/ifcfg-lo{,:0} #复制虚拟网卡
 [[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-lo:0 #修改以下参数,使ifcfg-lo:
0虚拟网卡成为主机型网卡
DEVICE=lo:0
IPADDR=192.168.4.15 #ip地址
NETMASK=255.255.255.255 #子网掩码
NETWORK=192.168.4.15 #网络地址

#If you’re having problems with gated making 127.0.0.0/8 a martian, # you can #change this to something else (255.255.255.255, for example)

BROADCAST=192.168.4.15 #广播地址
ONBOOT=yes
NAME=lo:0
 sysctl.conf文件写入这下面四行的主要目的就是访问192.168.4.15的数据包,只有调度器会响应,
其他主机都不做任何响应,防止地址冲突的问题。
 [[email protected] ~]# vim /etc/sysctl.conf
#手动写入如下4行内容
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_announce = 2
#当有arp广播问谁是192.168.4.15时,本机忽略该ARP广播,不做任何回应
#本机不要向外宣告自己的lo回环地址是192.168.4.15
 [[email protected] ~]# sysctl –p #刷新参数
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_announce = 2
 [[email protected] ~]systemctl restart network #重启网卡

3、配置web服务器

 [[email protected] ~]# yum -y install httpd
 [[email protected] ~]# echo “I am web server N1” > /var/www/html/index.html
 [[email protected] ~]#systemctl restart httpd
 [[email protected] ~]# yum -y install httpd
 [[email protected] ~]# echo “I am web server N22222” > /var/www/html/index.html #为区别网站内容
写的不一致,实际生产环境网站内容肯定一致
 [[email protected] ~]#systemctl restart httpd

4、proxy调度器安装软件并部署LVS-DR模式调度器

 [[email protected] ~]# yum -y install ipvsadm #安装ipvsadm调度器软件
 [[email protected] ~]# ipvsadm -A –t 192.168.4.15:80 -s wlc #添加wlc模式集群
 [[email protected] ~]# ipvsadm -a -t 192.168.4.15:80 -r 192.168.4.100 -g -w 1
 [[email protected] ~]# ipvsadm -a -t 192.168.4.15:80 -r 192.168.4.200 -g -w 2
##添加服务器中加入节点,并指定权重为web1权重为1、web2权重为2(权重根据不同服务器的负载能力自行调整),负载均衡方式为VS/DR
 [[email protected] ~]# ipvsadm –Ln #查看配置结果如下
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.4.15:80 wlc
-> 192.168.4.100:80 Route 1 0 0
-> 192.168.4.200:80 Route 2 0 0

 [[email protected] ~]# ipvsadm-save -n > /etc/sysconfig/ipvsadm #保存规则

5、客户端测试

     客户端使用curl命令反复连接http://192.168.4.15,得到以下结果,测试成功
      [[email protected] ~]# curl http://192.168.4.15

I an web server N2222222
[[email protected] ~]# curl http://192.168.4.15
I an web server N2222222
[[email protected] ~]# curl http://192.168.4.15
I an web server N1
[[email protected] ~]# curl http://192.168.4.15
I an web server N2222222
[[email protected] ~]# curl http://192.168.4.15
I an web server N2222222
[[email protected] ~]# curl http://192.168.4.15
I an web server N1
[[email protected] ~]# curl http://192.168.4.15
I an web server N2222222
[[email protected] ~]# curl http://192.168.4.15
I an web server N2222222
[[email protected] ~]# curl http://192.168.4.15
I an web server N1

6、其他说明

       默认LVS不带健康检查功能,需要自己手动编写动态检测脚本,实现该功能:(参考脚本如下,仅供参考,也可直接用keepalive做调度集群)

 [[email protected] ~]# vim check.sh
#!/bin/bash
VIP=192.168.4.15:80
RIP1=192.168.4.100
RIP2=192.168.4.200
while :
do
for IP in $RIP1 RIP2docurlshttp://RIP2 do curl -s http://IP &>/dev/vnull
if [ $? -eq 0 ];then
ipvsadm -Ln |grep -q $IP || ipvsadm -a -t $VIP -r $IP
else
ipvsadm -Ln |grep -q $IP && ipvsadm -d -t $VIP -r $IP
fi
done
sleep 1
done
 [[email protected] ~]# chmod 777 check.sh #设置权限
 [[email protected] ~]#./check.sh #执行脚本

版权声明:本文为RD_zzq原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/RD_zzq/article/details/102810011