关于LVS负载均衡群集的案例简介
admin
2023-02-24 20:20:04
0

下文给大家带来关于LVS负载均衡群集的案例简介,希望能够给大家在实际运用中带来一定的帮助,负载均衡涉及的东西比较多,理论也不多,网上有很多书籍,今天我们就用在行业内累计的经验做一个解答。

一、案例简介

1、案例环境

关于LVS负载均衡群集的案例简介

2、实验结果

  • 使用NAT模式的群集技术,LVS负载调度器是所有节点访问Internet的网关云服务器,其192.168.200.10作为整个群集的VIP地址。

  • 使用轮询(rr)的调度算法。

  • web1和web2先搭建web服务,分别准备不同的网页文件,供客户端访问,以此来确定client访问LVS服务器的192.168.200.10,可以访问到两台web服务器。

  • 待client测试成功后,web1和web2便可以挂载NFS服务器提供的共享目录,以此来为client提供相同的网页文件。

二、开始搭建复制均衡群集

1、部署Web1服务器:

[root@centos01 ~]# yum -y install httpd  
[root@centos01 ~]# echo "www.benet.com" > 
/var/www/html/index.html   
[root@centos01 ~]# systemctl start httpd   
[root@centos01 ~]# systemctl enable httpd  
[root@centos01 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens32   
      
GATEWAY=192.168.100.40   
[root@centos01 ~]# systemctl restart network

2、部署Web2服务器:

[root@centos02 ~]# yum -y install httpd    
[root@centos02 ~]# echo "www.accp.com" > 
/var/www/html/index.html    
[root@centos02 ~]# systemctl start httpd    
[root@centos02 ~]# systemctl enable httpd 
[root@centos02 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens32    
          
GATEWAY=192.168.100.40   
[root@centos02 ~]# systemctl restart network 

3、部署网关/LVS服务器:

[root@centos04 ~]# cp /etc/sysconfig/network-scripts/ifcfg-ens32 
/etc/sysconfig/network-scripts/ifcfg-ens34  

[root@centos04 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens34   
        
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
NAME=ens34      
DEVICE=ens34   
ONBOOT=yes
IPADDR=192.168.200.10   
NATEMASK=255.255.255.0
[root@centos04 ~]# systemctl restart network 
[root@centos04 ~]# vim /etc/sysctl.conf   
net.ipv4.ip_forward = 1

[root@centos04 ~]# sysctl -p   
net.ipv4.ip_forward = 1
[root@centos04 ~]# modprobe ip_vs   
[root@centos04 ~]# yum -y install ipvsadm
[root@centos04 ~]# ipvsadm -C   
[root@centos04 ~]# ipvsadm -A -t 192.168.200.10:80 -s rr  
             
[root@centos04 ~]# ipvsadm -a -t 192.168.200.10:80 -r 
192.168.100.10:80 -m -w 1   
[root@centos04 ~]# ipvsadm -a -t 192.168.200.10:80 -r 
192.168.100.20:80 -m -w 1   
[root@centos04 ~]# ipvsadm-save   
-A -t centos04:http -s rr
-a -t centos04:http -r 192.168.100.10:http -m -w 1
-a -t centos04:http -r 192.168.100.20:http -m -w 1
[root@centos04 ~]# ipvsadm-save > 
/etc/sysconfig/ipvsadm.bak
[root@centos04 ~]# cat /etc/sysconfig/ipvsadm.bak 
-A -t centos04:http -s rr
-a -t centos04:http -r 192.168.100.10:http -m -w 1
-a -t centos04:http -r 192.168.100.20:http -m -w 1

4、配置客户端

1)客户端配置IP地址
关于LVS负载均衡群集的案例简介

2)测试LVS负载均衡服务器是否工作正常(多次访问192.168.200.10,可以得到两个不同的页面):
关于LVS负载均衡群集的案例简介

关于LVS负载均衡群集的案例简介

5、配置NFS共享存储

[root@centos03 ~]# yum -y install nfs-utils rpcbind 
[root@centos03 ~]# systemctl enable nfs 
[root@centos03 ~]# systemctl enable rpcbind 
[root@centos03 ~]# mkdir -p /opt/wwwroot   
[root@centos03 ~]# echo "www.wangyi.com" > 
/opt/wwwroot/index.html   
[root@centos03 ~]# vim /etc/exports   
/opt/wwwroot    192.168.100.0/24(rw,sync,no_root_squash)  
[root@centos03 ~]# systemctl restart rpcbind  
[root@centos03 ~]# systemctl restart nfs   
[root@centos03 ~]# showmount -e   
Export list for centos03:
/opt/wwwroot 192.168.100.0/24
1)Web服务器1挂载共享目录
[root@centos01 ~]# yum -y install rpcbind nfs-utils
[root@centos01 ~]# systemctl enable rpcbind
                       
[root@centos01 ~]# systemctl start rpcbind 
[root@centos01 ~]# showmount -e 192.168.100.30  
                           
Export list for 192.168.100.30:
/opt/wwwroot 192.168.100.0/24
[root@centos01 ~]# mount 192.168.100.30:/opt/wwwroot 
/var/www/html/   
[root@centos01 ~]# df -hT /var/www/html/ 
文件系统                    类型  容量  已用  可用 已用% 挂载点
192.168.100.30:/opt/wwwroot nfs4   76G  3.7G   73G    5% /var/www/html
[root@centos01 ~]# vim /etc/fstab   
192.168.100.30:/opt/wwwroot     /var/www/html                     nfs     defaults,_netdev 0 0
2)Web服务器2挂载共享目录
[root@centos02 ~]# yum -y install rpcbind nfs-utils 
[root@centos02 ~]# systemctl enable rpcbind  
                                     
[root@centos02 ~]# systemctl start rpcbind    
[root@centos02 ~]# showmount -e 192.168.100.30   
                             
Export list for 192.168.100.30:
/opt/wwwroot 192.168.100.0/24
[root@centos02 ~]# mount 192.168.100.30:/opt/wwwroot 
/var/www/html/     
[root@centos02 ~]# df -hT /var/www/html/ 
文件系统                    类型  容量  已用  可用 已用% 挂载点
192.168.100.30:/opt/wwwroot nfs4   76G  3.7G   73G    5% /var/www/html
[root@centos02 ~]# vim /etc/fstab   
192.168.100.30:/opt/wwwroot     /var/www/html                     nfs     defaults,_netdev 0 0

6、客户端访问

关于LVS负载均衡群集的案例简介
至此,不管怎样刷新访问,都将是看到同一个网页。最终的LVS负载均衡效果也就实现了。

当LVS服务器重启后,LVS规则将会丢失,这就用到了备份,需要注意的是,备份时的主机名和恢复时的主机名必须一致,并且需要注意网卡优先的问题,否则在恢复后,会发现VIP(群集的虚拟IP)变成了LVS服务器的另一个IP地址

[root@centos04 ~]# ipvsadm -ln  
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

[root@centos04 ~]# ipvsadm-restore < 
/etc/sysconfig/ipvsadm.bak    
[root@centos04 ~]# 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.100.40:80 rr
  -> 192.168.100.10:80            Masq    1      0          0         
  -> 192.168.100.20:80            Masq    1      0          0   

看了以上关于关于LVS负载均衡群集的案例简介,如果大家还有什么地方需要了解的可以在行业资讯里查找自己感兴趣的或者找我们的专业技术工程师解答的,技术工程师在行业内拥有十几年的经验了。

 

相关内容

热门资讯

伊朗确认前往美国参加世界杯:将... 当地时间5月6日,伊朗国家足球队主教练在接受采访时表示,伊朗国家足球队将于美加墨世界杯开始前14天抵...
雷达、机库、营房、燃料库、飞机... 据《华盛顿邮报》5月6日报道,通过卫星影像分析发现,自2月28日战事爆发以来,伊朗空袭已在中东美军军...
从买买买到租租租,“租用一代”... “五一”假期还在路上,年轻人已经“租”起来了。 “租三天,不到300块钱。”五一放假前一周,清清已给...
【品牌】摩托罗拉大折叠屏新机定... 此前联想预热将于5月19日19点举行联想天禧AI一体多端全场景新品超能之夜活动,届时将带来多款新品,...
常州欣隽益取得接线端子用快速冲... 国家知识产权局信息显示,常州欣隽益科技有限公司取得一项名为“接线端子用快速冲切装置”的专利,授权公告...
美媒:特朗普在结束伊朗战争问题... 据“国会山”网站5月6日报道,周二晚间,美国总统特朗普突然宣布终止旨在打破伊朗对霍尔木兹海峡掌控的军...
和创硅材料取得熔融石英制品擦洗... 国家知识产权局信息显示,东海县和创硅材料有限公司取得一项名为“一种熔融石英制品的擦洗脱泥装置”的专利...
美商务部长再就爱泼斯坦案接受国... 5月6日,美国商务部长卢特尼克“自愿”就其与爱泼斯坦的关系接受美国国会众议院监督与政府改革委员会的问...
“五一”小长假黄金零售市场新变... 【大河财立方 记者 孙凯杰】 “五一”小长假,黄金价格出现一波短暂调整,线下黄金零售市场热度如何?5...
以军3周来首次袭击黎巴嫩首都 据以色列总理内塔尼亚胡和国防部长卡茨当地时间5月6日晚发表的联合声明,以军当天对黎巴嫩首都贝鲁特南郊...