群集技术———LVS(Linux Virtual Server,Linux虚拟服务器)负载均衡

企业群集应用概述

群集的含义

  • Cluster,集群、群集
  • 由多台主机构成,但对外只表现为一个整体

面临问题

  • 互联网应用中,随着站点对硬件性能、响应速度、服务稳定性、数据可靠性等要求越来越高,单台服务器力不从心。

解决方法

  • 使用价格昂贵的小型机、大型机
  • 使用普通服务器构建服务群集

企业群集分类

根据群集所针对的目标差异,可分为三种类型

  • 负载均衡群集
  • 高可用群集
  • 高性能运算群集

负载均衡群集(Load Balance Cluster)

  • 提高应用系统的响应能力、尽可能处理更多的访问请求、减少延迟为目标,获得高并发、高负载(LB)的整体性能
  • LB的负载分配依赖于主节点的分流算法

高可用群集(High Availability Cluster)

  • 提高应用系统的可靠性、尽可能地减少中断时间为目标,确保服务的连续性,达到高可用(HA)的容错效果。
  • HA的工作方式包括双工和主从两种模式

高性能运算群集(High Performance Computer Cluster)

  • 提高应用系统的CPU运算速度、扩展硬件资源和分析能力为目标,获得相当于大型、超级计算机的高性能运算(HPC)能力。
  • 高性能依赖于“分布式运算”、“并行计算”,通过专用硬件和软件将多个服务器的CPU、内存等资源整合在一起,实现只有大型、超级计算机才具备的计算能力。

负载均衡的结构

  • 第一层,负载调度器(Load Balancer或Director)
  • 第二层,服务器池(Server Pool)
  • 第三层,共享存储(Share Storage)

群集的负载调度技术有三种工作模式

  • 地址转换
  • IP隧道
  • 直接路由

关于LVS虚拟服务器

LVS的负载调度算法

  • 轮询轮询 (Round Robin)

    • 将收到的访问请求按照顺序轮流分配给群集中的各节点(真实服务器),均等地对待每一台服务器,而不管服务器实际的连接数和系统负载。
  • 加权轮询 (Weighted Round Robin)

    • 根据调度器设置的权重值来分发请求,权重值高的节点优先获得任务,分配的请求数越多。
    • 保证性能强的服务器承担更多的访问流量。
  • 最少连接 (Least Connections)

    • 根据真实服务器已建立的连接数进行分配,将收到的访问请求优先分配给连接数最少的节点。
  • 加权最少连接 (Weighted Least Connections)

    • 在服务器节点的性能差异较大时,可以为真实服务器自动调整权重。
    • 性能较高的节点将承担更大比例的活动连接负载。

案例:LVS-NAT部署实战

环境

  • LVS调度器作为Web服务器池的网关,LVS两块网卡,分别连接内外网,使用轮询 (rr) 调度算法。

IP地址规划

名称IP网关
调度器对外公网:20.0.0.21 (NAT)/
调度器私有网络:192.168.100.21 (VM1)/
WE1私有网络:192.168.100.22(VM1)192.168.100.21
WE2私有网络:192.168.100.23 (VM1 )192.168.100.21
存储服务器192.168.100.24(VM1)192.168.100.21(可配可不配)
真机20.0.0.1(VM8)20.0.0.21

调度器配置 (192.168.100.21)

[root@localhost ~]# yum -y install ipvsadm
[root@localhost ~]# modprobe ip_vs 				##加载ip_vs模块
[root@localhost ~]# cat /proc/net/ip_vs 				##查看ip_vs模块是否加载成功

[root@localhost ~]# ipvsadm -A -t 20.0.0.21:80 -s rr 			##创建虚拟服务器
[root@localhost ~]# ipvsadm -a -t 20.0.0.21:80 -r 192.168.100.22:80 -m		##添加服务器节点
[root@localhost ~]# ipvsadm -a -t 20.0.0.21:80 -r 192.168.100.23:80 -m
[root@localhost ~]# ipvsadm -ln				##查看节点状态

[root@localhost ~]# ipvsadm-save > /opt/ipvsadm			##保存负载分配策略
[root@localhost ~]# cat /opt/ipvsadm					##确认保存结果

[root@localhost ~]# vi /etc/sysctl.conf 				##开启调度服务器路由转发功能
net.ipv4.ip_forward = 1
[root@localhost ~]# sysctl -p 						##让内核参数立即生效

存储服务器配置(192.168.100.24)

[root@localhost ~]# rpm -q nfs-utils   ##最小化安装需要yum -y install nfs-utils
[root@localhost ~]# rpm -q rpcbind     ##最小化安装需要yum -y install rpcbind
[root@localhost ~]# systemctl enable nfs
[root@localhost ~]# systemctl enable rpcbind

[root@localhost ~]# mkdir /opt/51xit /opt/52xit    ##创建两个目录
[root@localhost ~]# echo "this is www.51xit.top" >/opt/51xit/index.html
[root@localhost ~]# echo "this is www.52xit.top" >/opt/52xit/index.html

[root@localhost opt]# vi /etc/exports      ##配置NFS服务器的相关信息
/opt/51xit 192.168.100.0/24(rw,sync)
/opt/52xit 192.168.100.0/24(rw,sync)

[root@localhost opt]# systemctl restart nfs rpcbind    ##重启
[root@localhost opt]# systemctl enable nfs rpcbind    ##开机自启


[root@localhost opt]# showmount -e     ##查询NFS服务器的相关信息(仅显示被客户挂载的目录名)
Export list for localhost.localdomain:
/opt/52xit 192.168.100.0/24
/opt/51xit 192.168.100.0/24

WE1配置(192.168.100.22)

[root@localhost ~]# showmount -e 192.168.100.24
Export list for 192.168.100.24:
/opt/52xit 192.168.100.0/24
/opt/51xit 192.168.100.0/24

[root@localhost ~]# yum -y install httpd
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd

[root@localhost ~]# mount 192.168.100.24:/opt/51xit /var/www/html/			##临时挂载
[root@localhost ~]# vi /etc/fstab 				##永久挂载
192.168.100.24:/opt/51xit /var/www/html nfs defaults,_netdev 0 0 
[root@localhost ~]# init 6				##最好重启检测下

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

WE2配置 (192.168.100.23)

[root@localhost ~]# showmount -e 192.168.100.24
Export list for 192.168.100.24:
/opt/52xit 192.168.100.0/24
/opt/51xit 192.168.100.0/24

[root@localhost ~]# yum -y install httpd
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd

[root@localhost ~]# mount 192.168.100.24:/opt/52xit /var/www/html/  		 ##临时挂载
[root@localhost ~]# vi /etc/fstab      	  ##永久挂载
192.168.100.24:/opt/52xit /var/www/html nfs defaults,_netdev 0 0 
[root@localhost ~]# init 6      	  ##重启测试

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

附加:

添加一个新网卡(ens37):

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens37			#复制ens33到ens37

[root@localhost ~]# nmcli connection  		##查看UUID信息

[root@localhost ~]# route -n   ##查看路由条目 把地址以数字的形式显示

注释:
每一个UUID只能一个网卡使用!!

【可能遇到的问题】

[root@localhost ~]# showmount -e 192.168.100.24
clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)
[root@localhost ~]# showmount -e
Export list for localhost.localdomain:

【解决方案】

(1)检查防火墙和核心防护

[root@localhost ~]# systemctl status firewalld
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0

(2)检查共享列表有没有设置

[root@localhost ~]# cat /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
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值