LVS-DR 负载均衡集群搭建

1.LVS-DR 负载均衡集群概述

1.1 原理

客户端向目标vip发出请求,lvs接收 ,LVS根据负载均衡算法选择一台活跃的的节点,将此节点的ip所在网卡的mac地址作为目标mac地址,发送到局域网里

节点在局域网中收到这个帧,拆开后发现目标IP(VIP)与本地匹配,于是处理这个报文.随后重新封装报文,发送到局域网.此时IP包的目标ip是客户端,源ip是自己的vip地址。

在这里插入图片描述

2… LVS-DR 负载均衡集群搭建实验

实验环境
一台调度器: VM1:192.168.100:41
二台WEB服务器集群池:192.168.100.42、192.168.100.43
一台NFS共享服务器:192.168.100.44

2.1 在调度器配置:192.168.100.21

【1】配置虚拟IP地址(VIP)

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens33:0
[root@localhost network-scripts]# vi ifcfg-ens33:0
NAME=ens33:0
DEVICE=ens33:0
ONBOOT=yes
IPADDR=192.168.100.10
NETMASK=255.255.255.255

[root@localhost network-scripts]# ifup ifcfg-ens33:0  ##启动ens33.0网口
[root@localhost network-scripts]# ifconfig

【2】调整/proc响应参数

对于 DR 群集模式来说,由于 LVS 负载调度器和各节点需要共用 VIP 地址,应该关闭 Linux 内核的重定向参数响应服务器不是一台路由器,那么它不会发送重定向,所以可以关闭该功能

[root@localhost network-scripts]# vi /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@localhost 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

【3】配置负载分配策略

[root@localhost /]# ipvsadm -v
[root@localhost ~]# modprobe ip_vs
[root@localhost ~]# cat /proc/net/ip_vs
[root@localhost ~]#yum -y install ipvsadm
[root@localhost ~]#ipvsadm -A -t 192.168.100.10:80 -s rr
[root@localhost ~]#ipvsadm -a -t 192.168.100.10:80 -r 192.168.100.42:80 -g -w 1
[root@localhost ~]#ipvsadm -a -t 192.168.100.10:80 -r 192.168.100.43:80 -g -w 1

[root@localhost network-scripts]# ipvsadm-save
[root@localhost network-scripts]# systemctl enable ipvsadm

2.2 配置存储服务器:192.168.100.44

rpm -q nfs-utils    ###如果没装,yum -y install nfs-utils
rpm -q rpcbind      ###如果没装,yum -y install rpcbind
[root@localhost ~]# systemctl start nfs
[root@localhost ~]# systemctl start rpcbind

[root@localhost ~]# vi /etc/exports
/opt/51xit 192.168.100.0/24 (rw,sync)
/opt/52xit 192.168.100.0/24 (rw,sync)

[root@localhost ~]# systemctl restart nfs
[root@localhost ~]# systemctl restart rpcbind
[root@localhost ~]# systemctl enable nfs
[root@localhost ~]# systemctl enable rpcbind
[root@localhost ~]# mkdir /opt/51xit /opt/52xit
[root@localhost ~]# echo "this is 51xit" >/opt/51xit/index.html
[root@localhost ~]# echo "this is 52xit" >/opt/52xit/index.html

2.3 配置节点服务器:192.168.100.42

【1】配置虚拟IP地址

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-lo ifcfg-lo:0
[root@localhost network-scripts]# vi ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.100.10
NETMASK=255.255.255.255
ONBOOT=yes


[root@localhost network-scripts]# ifup lo:0
[root@localhost network-scripts]# ifconfig

[root@localhost network-scripts]# vi /etc/rc.local 
/sbin/route add -host 192.168.100.10 dev lo:0

[root@localhost network-scripts]# route add -host 192.168.100.10 dev lo:0

【2】调整/proc响应参数

[root@localhost network-scripts]# vi /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@localhost network-scripts]# sysctl -p

【3】安装httpd 挂载测试页

[root@localhost ~]# showmount -e 192.168.100.44     ####如果还没发布,请到存储服务器发布下,exportfs -rv
Export list for 192.168.100.44:
/opt/51xit  (everyone)
/opt/52xit (everyone)

[root@localhost ~]# yum -y install httpd
[root@localhost ~]# mount 192.168.100.44:/opt/51xit /var/www/html/
[root@localhost ~]# vi /etc/fstab 
192.168.100.44:/opt/51xit/ /var/www/html/        nfs     rw,tcp,intr     0 1        ###开机自动挂载,注意格式对齐

[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd

###登录192.168.100.42测试网站是否正常####

2.4 配置节点服务器:192.168.100.43

【1】配置虚拟IP地址

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-lo ifcfg-lo:0
[root@localhost network-scripts]# vi ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.100.10
NETMASK=255.255.255.255
ONBOOT=yes


[root@localhost network-scripts]# ifup lo:0
[root@localhost network-scripts]# ifconfig

[root@localhost network-scripts]# vi /etc/rc.local 
/sbin/route add -host 192.168.100.10 dev lo:0

[root@localhost network-scripts]# route add -host 192.168.100.10 dev lo:0

【2】调整/proc响应参数

[root@localhost network-scripts]# vi /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@localhost network-scripts]# sysctl -p

【3】安装httpd 挂载测试页

[root@localhost ~]# showmount -e 192.168.100.44     ####如果还没发布,请到存储服务器发布下,exportfs -rv
Export list for 192.168.100.44:
/opt/accp  (everyone)
/opt/bdqn (everyone)

[root@localhost ~]# yum -y install httpd
[root@localhost ~]# mount 192.168.100.44:/opt/52xit /var/www/html/
[root@localhost ~]# vi /etc/fstab 
192.168.100.44:/opt/52xit/ /var/www/html/        nfs     rw,tcp,intr     0 1        ###开机自动挂载,注意格式对齐

[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd

登录192.168.100.43测试网站是否正常

2.5 测试网站

登录192.168.100.10测试一下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值