部署 LVS-DR 群集

本章内容:
  • -了解LVS-DR群集的工作原理
  • -会构建LVS-DR负载均衡群集
2.1 LVS-DR 集群
LVS-DR Linux Virtual Server Director Server )工作模式,是生产环境中最常用的一
种工作模式。
2.1.1 LVS-DR 工作原理
LVS-DR 模式, Director Server 作为群集的访问入口,不作为网关使用,节点 Director
Server Real Server 需要在同一个网络中,返回给客户端的数据不需要经过 Director
Server 。为了响应对整个群集的访问, Director Server Real Server 都需要配置 VIP 地址,
工作原理如图 2.1 所示。
2.1 DR 模式工作原理
2.1.2 .数据包流向分析
以下为数据包流向分析步骤。
1. 客户端发送请求到 Director Server, 请求的数据报文(源 IP CIP, 目标 IP VIP
到达内核空间。
2. Director Server Real Server 在同一个网络中,数据通过二层数据链路层来传输。
3. 内核空间判断数据包的目标 IP 是本机 VIP ,此时 IPVS 比对数据包请求的服务是否
是集群服务,是集群服务就重新封装数据包。修改源 MAC 地址为 Director Server MAC
地址,修改目标 MAC 地址为 Real Server MAC 地址,源 IP 地址与目标 IP 地址没有改
变,然后将数据包发送给 Real Server
4. 到达 Real Server 的请求报文的 MAC 地址是自身的 MAC 地址,就接收此报文。数
据包重新封装报文 ( IP 地址为 VIP ,目标 IP CIP) ,将响应报文通过 lo 接口传送给物理
网卡然后向外发出。
5. Real Server 直接将响应报文传送到客户端。
2.1.3 LVS-DR 模式特点
下面是 LVS-DR 模式的特点:
Director Server Real Server 必须在同一个物理网络中。
Real Server 可以使用私有地址,也可以使用公网地址。如果使用公网地址,可以通过
互联网对 RIP 进行直接访问。
所有的请求报文经由 Director Server ,但回复响应报文不能经过 Director Server
Real Server 的网关不允许指向 Director Server IP ,即 不允许数据包经过 Director S
erver
Real Server 上的 lo 接口配置 VIP IP 地址。
2.2 案例:直接路由模式( LVS-DR
2.2.1 .准备案例环境
DR 模式的群集中, LVS 负载调度器作为群集的访问入口,但不作为网关使用;服
务器池中的所有节点都各自接入 Internet ,发送给客户机的 Web 响应数据包不需要经过
LVS 负载调度器,如图 2.2 所示。
这种方式入站、出站访问数据被分别处理,因此 LVS 负载调度器和所有的节点服务器
都需要配置 VIP 地址,以便响应对整个群集的访问。考虑到数据存储的安全性,共享存储
设备会放在内部的专用网络中。
2.2.2 .配置负载调度器
下面是 配置负载调度器的具体步骤。
1. 配置虚拟 IP 地址( VIP
采用虚接口的方式( ens33 0 ),为网卡 ens33 绑定 VIP 地址,以便响应群集访问。
[root@zw ~]# cd /etc/sysconfig/network-scripts/
[root@zw network-scripts]# cp ifcfg-ens33 ifcfg-ens33:0
[root@zw network-scripts]# vim ifcfg-ens33:0
NAME=ens33:0
DEVICE=ens33:0
ONBOOT=yes
IPADDR=192.168.248.100
NETMASK=255.255.255.255
[root@zw network-scripts]# ifup ifcfg-ens33:0
[root@zw network-scripts]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.248.78  netmask 255.255.255.0  broadcast 192.168.248.255
        inet6 fe80::3a56:a61b:f0f3:fd09  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:d9:07:16  txqueuelen 1000  (Ethernet)
        RX packets 1342  bytes 143729 (140.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1055  bytes 126013 (123.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.248.100  netmask 255.255.255.255  broadcast 192.168.248.100
        ether 00:0c:29:d9:07:16  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:24:31:78  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@zw network-scripts]# 
2. 调整/proc响应参数
  • 对于 DR 群集模式来说,由于 LVS 负载调度器和各节点需要共用 VIP 地址,应该关闭 Linux 内核重定向参数响应
  • 服务器不是一台路由器,那么它不会发送重定向,所以可以关闭该功能
[root@zw network-scripts]# vim /etc/sysctl.conf 

net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0

[root@zw network-scripts]# sysctl -p
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
[root@zw network-scripts]#
3. 配置负载分配策略
[root@zw ~]# modprobe ip_vs
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port Forward Weight ActiveConn InActConn
[root@zw ~]# yum -y install ipvsadm
[root@zw ~]# ipvsadm -v
ipvsadm v1.27 2008/5/15 (compiled with popt and IPVS v1.2.1)
[root@zw ~]# [root@zw ~]# ipvsadm -C
[root@zw ~]# ipvsadm -a -t 192.168.248.78:80 -r 192.168.248.88:80 -g -w 1
[root@zw ~]# ipvsadm-save > /etc/sysconfig/ipvsadm
[root@zw ~]# cat /etc/sysconfig/ipvsadm
-A -t www.test.com:http -s rr
-a -t www.test.com:http -r 192.168.248.88:http -g -w 1
[root@zw ~]# systemctl start ipvsadm.service
[root@zw ~]# systemctl enable ipvsadm.service
4. 配置存储服务器192.168.248.215
[root@uuu ~]# yum -y install nfs-utils rpcbind
[root@uuu ~]# mkdir -p /opt/wwwroot
[root@uuu ~]# vim /etc/exports
/opt/wwwroot 192.168.248.0/24(rw,sync,no_root_squash)
[root@uuu ~]# systemctl restart rpcbind
[root@uuu ~]# systemctl restart nfs
5. 配置节点服务器192.168.8.88
[root@uuu ~]# yum -y install httpd
[root@uuu ~]# cd /etc/sysconfig/network-scripts/
[root@uuu network-scripts]# cp ifcfg-lo ifcfg-lo:0
[root@uuu network-scripts]# vim ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.248.78
NETMASK=255.255.255.255
ONBOOT=yes
[root@uuu ~]# yum install -y httpd
[root@uuu ~]# cd /etc/sysconfig/network-scripts/
[root@uuu network-scripts]# cp ifcfg-lo ifcfg-lo:0
[root@uuu network-scripts]# vim ifcfg-lo:0
[root@uuu network-scripts]# ifup lo:0
[root@uuu network-scripts]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.248.88  netmask 255.255.255.0  broadcast 192.168.248.255
        inet6 fe80::fa3a:33a0:cd48:1429  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:89:c9:b0  txqueuelen 1000  (Ethernet)
        RX packets 2581  bytes 1205845 (1.1 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1446  bytes 184056 (179.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo:0: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 192.168.248.78  netmask 255.255.255.255
        loop  txqueuelen 1000  (Local Loopback)

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:30:60:00  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@uuu network-scripts]# 
[root@uuu network-scripts]# vim /etc/sysctl.conf
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@uuu 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@uuu network-scripts]# 
[root@uuu ~]# showmount -e 192.168.248.215
Export list for 192.168.248.215:
/opt/wwwroot 192.168.248.0/24
[root@uuu ~]# mount 192.168.248.215:/opt/wwwroot /var/www/html
[root@uuu ~]# vim /etc/fstab 
192.168.248.215:/opt/wwwroot           /var/www/html/     nfs   defaults,_netdev 0 0
[root@uuu ~]# systemctl start httpd.service 
[root@uuu ~]# systemctl enable httpd.service


然后就可以测试了

  • 21
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值