一、LVS运行原理
LVS:Linux Virtual Server
,负载调度器,内核集成,章文嵩,阿里的四层
SLB(Server LoadBalance)
是基于LVS+keepalived
实现
LVS
官网
:
http://www.linuxvirtualserver.org/
LVS 相关术语
- VS: Virtual Server,负责调度
- RS:RealServer,负责真正提供服务
lvs集群体系结构:
lvs概念:
- VS:Virtual Server
- RS:Real Server
- CIP:Client IP
- VIP: Virtual serve IP VS外网的IP
- DIP: Director IP VS内网的IP
- RIP: Real server IP
- 访问流程:CIP <--> VIP == DIP <--> RIP
lvs
集群的类型
lvs-nat:
- 本质是多目标IP的DNAT,通过将请求报文中的目标地址和目标端口修改为某挑出的RS的RIP和
- PORT实现转发
- RIP和DIP应在同一个IP网络,且应使用私网地址;RS的网关要指向DIP
- 请求报文和响应报文都必须经由Director转发,Director易于成为系统瓶颈
- 支持端口映射,可修改请求报文的目标PORT
- VS必须是Linux系统,RS可以是任意OS系统
nat
模式数据逻辑

案例:

实施:
准备环境:
准备4台虚拟机(rhel9 )
网络编辑器:
lvs服务器
- 配置两块网卡(nat/仅主机)
- 虚拟机(rhel9)
- IP:nat-172.25.254.100/24 ,172.25.254.2 仅主机-192.168.0.100/24


lvs打开内核路由功能


生效:

为了看到效果,在两台不同的服务端里面我们设置的html里的内容访问不一样
webserver1服务器
- rhel9
- 仅主机
- IP:192.168.0.10/24 ,192.168.0.100
安装httpd并开机启动:并编写



webserver2服务器
- rhel9
- 仅主机
- IP:192.168.0.20/24 ,192.168.0.100

安装httpd并开机启动:并编写


测试环节
在lvs虚拟机上ping并且访问他的内容

在客户机(新机子/但是同一个网段里面)测试

访问流量:
客户把这个流量给了端口网关,然后通过算法到lvs的IP 在去访问这个分布式的ip的内容