Linux集群--LVS-DR模式与构建

本文详细介绍了如何在Linux集群中使用LVS的DR(Direct Routing)模式,包括数据包路由、VIP配置、ARP解决冲突、负载调度器设置、Apache服务启动、VIP分配及路由添加,最后展示了调度结果和关键配置步骤。
摘要由CSDN通过智能技术生成

Linux集群–LVS-DR模式与构建
在这里插入图片描述
1.数据包从client端(公网),经过集群的路由器(图中省略)进入集群私网中,经过交换机,发送数据给D(负载均衡调度器);
2.数据包到达D后会修改DMAC(如RS1的DMAC),RS1中配置VIP为D的ip(图中10.10.10.100)后可接收包
3.此时集群内D与RS1均有数据包中的目标ip,存在IP冲突,解决办法见后文(配置ARP);
4.RS1响应客户端
5.下次根据调度算法重新分配服务器。

负载调度器配置:

# 关闭网卡守护进程
[root@localhost ~]# service NetworkManager stop
停止 NetworkManager 守护进程:                             [确定]
[root@localhost ~]# chkconfig NetworkManager off  # 开机不自启


# 开启网卡子接口
[root@localhost network-scripts]# cp ifcfg-eth4 ifcfg-eth4:0
[root@localhost network-scripts]# cat ifcfg-eth4:0
DEVICE=eth4:0
ONBOOT=yes
BOOTPROTO=static
IPADDR=10.10.10.100  # 浮动ip
NETMASK=255.255.255.0
[root@localhost network-scripts]# service network restart

# 关闭广播功能(可省略)
[root@localhost network-scripts]# vim /etc/sysctl.conf 
[root@localhost network-scripts]# sysctl -p
# 仅显示添加的内容
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.eth4.send_redirects = 0

# 安装ipvsadm
[root@localhost network-scripts]# yum -y install ipvsadm
[root@localhost network-scripts]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

多台服务器同时配置如下:

# 关闭网卡守护进程
[root@localhost ~]# service NetworkManager stop
停止 NetworkManager 守护进程:                             [确定]
[root@localhost ~]# chkconfig NetworkManager off  # 开机不自启

# 启动Apache
[root@localhost ~]# service httpd start

# 添加VIP
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-lo ifcfg-lo:0
[root@localhost network-scripts]# cat ifcfg-lo:0
# 设置如下
DEVICE=lo:0
IPADDR=10.10.10.100
NETMASK=255.255.255.255
NETWORK=127.0.0.0
BROADCAST=127.255.255.255
ONBOOT=yes
NAME=loopback

[root@localhost network-scripts]# vim /etc/sysctl.conf 
[root@localhost network-scripts]# sysctl -p 
# 仅显示添加的内容
net.ipv4.conf.all.arp_ignore = 1  
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2

# 添加路由
[root@localhost network-scripts]# route add -host 10.10.10.100 dev lo:0
[root@localhost network-scripts]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.10.10.100    0.0.0.0         255.255.255.255 UH    0      0        0 lo
10.10.10.0      0.0.0.0         255.255.255.0   U     0      0        0 eth2
169.254.0.0     0.0.0.0         255.255.0.0     U     1003   0        0 eth2
# 开机自启
[root@localhost network-scripts]# echo "route add -host 10.10.10.100 dev lo:0" >> /etc/rc.local
# 添加规则(调度器)
#-A添加集群 -a添加节点 -t tcp -s 算法 rr 轮询 -r realserver -g DR模式
[root@localhost network-scripts]# ipvsadm -A -t 10.10.10.100:80 -s rr
[root@localhost network-scripts]# ipvsadm -a -t 10.10.10.100:80 -r 10.10.10.12 -g
[root@localhost network-scripts]# ipvsadm -a -t 10.10.10.100:80 -r 10.10.10.13 -g
[root@localhost network-scripts]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  10.10.10.100:80 rr
  -> 10.10.10.12:80               Route   1      0          0         
  -> 10.10.10.13:80               Route   1      0          0  

多次访问10.10.10.100:80(apache)后查看调度结果

[root@localhost network-scripts]# ipvsadm -Ln --stats
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port               Conns   InPkts  OutPkts  InBytes OutBytes
  -> RemoteAddress:Port
TCP  10.10.10.100:80                    10       51        0     7617        0
  -> 10.10.10.12:80                      5       25        0     3490        0
  -> 10.10.10.13:80                      5       26        0     4127        0

*本文图片来自尚硅谷课件

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维小菜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值