摘要
本文以集群和分布式这两个计算机领域中的重要概念入手,引入 LVS 在服务器集群系统中的职能及应用。包括 LVS 的概念简介、工作模式(lvs-nat、lvs-dr、lvs-tun、lvs-fullnat)、调度算法、部署命令介绍以及基于 RedHat9 虚拟机的 NAT 模式部署实战演示。
目录
1.服务器的集群与分布式介绍
1.1 系统性能扩展方式
- Scale UP:向上扩展、增强。
- Scale Out:向外扩展,增加设备,调度分配问题,Cluster。
1.2 集群
- 概念
- 特点
高可用(High Availiablity):集群中的节点可以相互备份,当一个节点发生故障时,其他节点可以迅速接管其工作,从而减少服务中断的时间。
高性能计算(High-performance computing):集群可以利用多个节点的资源来并行处理复杂任务,提高计算效率。
负载均衡(LoadBalancing):集群通过将工作负载分配到多个节点上来平衡系统的负载,提高整体性能。
- 应用场景
数据库集群:如MySQL Cluster,用于提高数据库系统的性能和可靠性。
计算集群:如HPC集群,用于高性能计算任务,如基因分析、化学分析等。
负载均衡集群:如Apache HTTP Server,通过将请求分发到多个服务器来提高网站的响应速度和可用性。
1.3 分布式
- 概念
分布式系统是一种将计算任务和数据分散到多个计算节点上的系统,这些节点可以分布在不同的位置,甚至是不同的地理区域。
- 特点
松散耦合:分布式系统中的节点可以独立运行,并通过网络通信来协调工作。
扩展性和容错性:系统可以通过增加更多的节点来横向扩展处理能力,同时提供容错功能,节点故障不会导致整个系统崩溃。
- 应用场景
分布式数据库:如Apache Cassandra、MongoDB,用于处理大规模数据存储和查询。
分布式文件系统:如Hadoop HDFS、Google FileSystem,用于管理和处理大量数据。
微服务架构:将应用程序分解为多个服务,实现灵活的分布式部署和管理。
1.4 集群和分布式的区别
集群和分布式是计算机系统领域中的两个重要概念,它们在设计和实现现代计算架构时经常被提到。虽然它们有重叠之处,但也有显著的区别。
2. LVS 简介
2.1 LVS 的概念
LVS(LinuxVirtualServer)属于计算机网络和分布式系统领域。它是一种集群技术,最初由章文嵩博士在1998年5月组织成立,是中国国内最早出现的自由软件项目之一。LVS旨在提供一个高性能、高可用的服务器集群系统,通过使用集群技术和Linux操作系统来实现。
2.2 LVS 集群体系结构图
2.3 LVS 名词概念
- VS: Virtual Server,负责调度
- RS:RealServer,负责真正提供服务
- CIP:Client IP
- VIP: Virtual serve IP VS外网的IP
- DIP: Director IP VS内网的IP
- RIP: Real server IP
2.4 LVS 的主要特点
- 高并发连接
LVS基于内核网络层面工作,具有强大的承载能力和并发处理能力,单台LVS负载均衡器可以支持上万并发连接。
- 稳定性强
LVS工作在网络4层之上,仅作分发之用,这使得它在负载均衡软件中性能最强,稳定性最好,对内存和CPU资源消耗极低。
- 成本低廉
与硬件负载均衡器相比,LVS只需一台服务器和就能免费部署使用,性价比极高。
- 配置简单
LVS配置非常简单,仅需几行命令即可完成配置,也可写成脚本进行管理。
- 支持多种算法
LVS支持多种调度算法,可以根据业务场景灵活调配进行使用。
- 支持多种工作模型
LVS可以根据业务场景,使用不同的工作模式来解决生产环境请求处理问题。
- 应用范围广
因为LVS工作在4层,所以它几乎可以对所有应用做负载均衡,包括http、数据库、DNS、ftp服务等。
尽管LVS有上述优点,但它也存在一些缺点,例如工作在4层,不支持7层规则修改,机制过于庞大,不适合小规模应用等。此外,LVS主要应用于Linux平台,虽然可以通过配置使其他操作系统(如Windows)成为集群中的真实服务器(RS),但目前没有专门用于Windows的LVS版本。
3. LVS 工作模式
- lvs-nat: 修改请求报文的目标 IP ,多目标 IP 的 DNAT。
- lvs-dr: 操纵封装新的 MAC 地址。
- lvs-tun: 在原请求 IP 报文之外新加一个 IP 首部。
- lvs-fullnat: 修改请求报文的源和目标 IP 。
3.1 NAT 模式
- 简介
LVS的NAT模式是Linux虚拟服务器(LVS)负载均衡技术中的一种重要模式,它通过地址转换来实现负载均衡。以下是关于LVS的NAT模式的详细介绍:
工作原理:
在NAT模式下,LVS作为前端负载均衡器,位于客户端和后端服务器之间。当客户端发送请求到LVS时,LVS会将请求报文中的目标IP地址和端口修改为LVS内部的IP地址和端口,然后将请求转发到后端的服务器。当服务器响应时,LVS会将响应报文中的源IP地址和端口修改为客户端的IP地址和端口,再将响应返回给客户端。
优点:
安全性高:由于服务器节点使用私有IP地址,与LVS位于同一物理网络,形成了类似防火墙的私有网络结构,提高了安全性。
负载均衡:通过修改请求和响应的IP地址和端口,LVS可以实现负载均衡,将客户端的请求分发到不同的后端服务器。
支持端口映射:LVS支持端口映射,可以修改请求报文的目标端口,实现更灵活的负载均衡策略。
缺点:
性能瓶颈:由于所有的请求和响应都需要经过LVS,LVS可能会成为性能瓶颈,特别是在高负载场景下。
扩展性有限:当服务器节点数量过多时,LVS的性能问题可能会更加突出,因为它需要处理大量的数据包。
应用场景:
适用于中小型集群,提供较高的安全性和负载均衡能力。
配置和管理:
需要在LVS服务器上配置IP地址转换规则,以及在后端服务器上配置默认网关指向LVS服务
- nat 模式数据逻辑
- 客户端发送访问请求,请求数据包中含有请求来源(cip),访问目标地址(VIP)访问目标端口(9000port)。
- VS服务器接收到访问请求做DNAT把请求数据包中的目的地由VIP换成RS的RIP和相应端口。
- RS1相应请求,发送响应数据包,包中的相应保温为数据来源(RIP1)响应目标(CIP)相应端口 (9000port)。
- VS服务器接收到响应数据包,改变包中的数据来源(RIP1-->VIP),响应目标端口(9000-->80)。
- VS服务器把修改过报文的响应数据包回传给客户端。
- lvs的NAT模式接收和返回客户端数据包时都要经过lvs的调度机,所以lvs的调度机容易阻塞。
- nat 模式数据传输过程
客户请求到达vip后进入PREROUTING,在没有ipvs的时候因该进入本机INPUT,当IPVS存在后访问请求在通 过PREROUTING后被ipvs结果并作nat转发 。因为ipvs的作用点是在PREROUTING和INPUT链之间,所以如果在prerouting中设定规则会干扰ipvs的工 作。所以在做lvs时要把iptables的火墙策略全清理掉。
- 特点
- 本质是多目标IP的DNAT,通过将请求报文中的目标地址和目标端口修改为某跳出的RS的RIP和 PORT实现转发。
- RIP和DIP应在同一个IP网络,且应使用私网地址。
- RS的网关要指向DIP。
- 请求报文和响应报文都必须经由Director转发,Director易于成为系统瓶颈。
- 支持端口映射,可修改请求报文的目标PORT。
- VS必须是Linux系统,RS可以是任意OS系统。
3.2 DR 模式
- 简介
- DR 模式数据逻辑
-
DR 模式数据传输过程
- 客户端发送数据帧给vs调度主机帧中内容为客户端IP+客户端的MAC+VIP+VIP的MAC 。
- VS调度主机接收到数据帧后把帧中的VIP的MAC该为RS1的MAC,此时帧中的数据为客户端IP+客户端 的MAC+VIP+RS1的MAC 。
- RS1得到2中的数据包做出响应回传数据包,数据包中的内容为VIP+RS1的MAC+客户端IP+客户端IP的 MAC 。
- 特点
- Director和各RS都配置有VIP
- 确保前端路由器将目标IP为VIP的请求报文发往Director
- 在前端网关做静态绑定VIP和Director的MAC地址
- RS的RIP可以使用私网地址,也可以是公网地址;RIP与DIP在同一IP网络;
- RIP的网关不能指向DIP,以确保响应报文不会经由Director
- RS和Director要在同一个物理网络
- 请求报文要经由Director,但响应报文不经由Director,而由RS直接发往Client
- 不支持端口映射(端口不能修败)
- RS可使用大多数OS系统
- 在RS上使用arptables工具
arptables -A IN -d $VIP -j DROParptables -A OUT -s $VIP -j mangle --mangle-ip-s $RIP
- 在RS上修改内核参数以限制arp通告及应答级别
/proc/sys/net/ipv4/conf/all/arp_ignore/proc/sys/net/ipv4/conf/all/arp_announce
3.3 TUN 模式
- 简介
- TUN 模式数据传输过程
- 客户端发送请求数据包,包内有源IP+vip+dport
- 到达vs调度器后对客户端发送过来的数据包重新封装添加IP报文头,新添加的IP报文头中包含 TUNSRCIP(DIP)+TUNDESTIP(RSIP1)并发送到RS1
- RS收到VS调度器发送过来的数据包做出响应,生成的响应报文中包含SRCIP(VIP)+DSTIP(CIP) +port,响应数据包通过网络直接回传给client
- 特点
- DIP、VIP、RIP 都应该是公网地址。
- RS的网关一般不能指向DIP。
- 请求报文要经由Director,但响应不能经由Director。
- 不支持端口映射。
- RS的OS须支持隧道功能。
3.4 FULLNAT 模式
- 简介
- 特点
- VIP是公网地址,RIP和DIP是私网地址,且通常不在同一IP网络;因此,RIP的网关一般不会指向DIP。
- RS收到的请求报文源地址是DIP,因此,只需响应给DIP,但Director还要将其发往Client 。
- 请求和响应报文都经由Director 。
- 支持端口映射。
- 此类型kernel默认不支持。
3.5 LVS 工作模式总结
- lvs-nat与lvs-fullnat:请求和响应报文都经由Director
- lvs-nat:RIP的网关要指向DIP
- lvs-fullnat:RIP和DIP未必在同一IP网络,但要能通信
- lvs-dr与lvs-tun:请求报文要经由Director,但响应报文由RS直接发往Client
- lvs-dr:通过封装新的MAC首部实现,通过MAC网络转发
- lvs-tun:通过在原IP报文外封装新IP头实现转发,支持远距离通信
4. LVS 的调度算法
4.1 调度算法的分类
- ipvs scheduler:根据其调度时是否考虑各RS当前的负载状态被分为两种:静态方法和动态方法。
- 静态方法:仅根据算法本身进行调度,不考虑RS的负载情况。
- 动态方法:主要根据每RS当前的负载状态及调度算法进行调度Overhead=value较小的RS将被调度。
4.2 静态调度算法
- RR:roundrobin 轮询 RS分别被调度,当RS配置有差别时不推荐。
- WRR:Weighted RR,加权轮询根据RS的配置进行加权调度,性能差的RS被调度的次数少。
- SH:Source Hashing,实现session sticky,源IP地址hash;将来自于同一个IP地址的请求始终发往第一次挑中的RS,从而实现会话绑定。
- DH:Destination Hashing;目标地址哈希,第一次轮询调度至RS,后续将发往同一个目标地址的请求始终转发至第一次挑中的RS,典型使用场景是正向代理缓存场景中的负载均衡,如:宽带运营商。
4.3 动态调度算法
- LC:least connections(最少链接发) 。适用于长连接应用Overhead(负载值)=activeconns(活动链接数) x 256+inactiveconns(非活 动链接数)。
- WLC:Weighted LC(权重最少链接) 。默认调度方法Overhead=(activeconns x 256+inactiveconns)/weight 。
- SED:Shortest Expection Delay。初始连接高权重优先Overhead=(activeconns+1+inactiveconns) x 256/weight 。但是,当node1的权重为1,node2的权重为10,经过运算前几次的调度都会被node2承接
- NQ:Never Queue,第一轮均匀分配,后续SED
- LBLC:Locality-Based LC,动态的DH算法,使用场景:根据负载状态实现正向代理
- LBLCR:LBLC with Replication,带复制功能的LBLC,解决LBLC负载不均衡问题,从负载重的复制到负载轻的RS 。
4.4 新增调度算法
- FO(Weighted Fai Over)调度算法
- OVF(Overflow-connection)调度算法
- 未过载(未设置IP_VS_DEST_F OVERLOAD标志)。
- 真实服务器当前的活动连接数量小于其权重值。
- 其权重值不为零。
5. LVS 部署命令介绍
5.1 软件相关信息
- 程序包:ipvsadm
- Unit File: ipvsadm.service
- 主程序:/usr/sbin/ipvsadm
- 规则保存工具:/usr/sbin/ipvsadm-save
- 规则重载工具:/usr/sbin/ipvsadm-restore
- 配置文件:/etc/sysconfig/ipvsadm-config
- ipvs调度规则文件:/etc/sysconfig/ipvsadm
5.2 ipvsadm命令
- 集群服务管理
基础格式:
ipvsadm -A|E -t|u|f service-address [-s scheduler] [-p [timeout]]
基本参数:
-A #添加
-E #修改
-t #tcp服务
-u #udp服务
-s #指定调度算法,默认为WLC
-p #设置持久连接超时,持久连接可以理解为在同一个时间段同一个来源的请求调度到同一Realserver
-f #firewall mask 火墙标记,是一个数字
案例演示:
增加
[root@lvs ~]# ipvsadm -A -t 172.25.254.100:80 -s rr
修改
[root@lvs ~]# ipvsadm -E -t 172.25.154.100:80 -s wrr
数据流
用来统计访问量。
[root@lvs ~]# ipvsadm -Ln --rate IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port CPS InPPS OutPPS InBPS OutBPS -> RemoteAddress:Port TCP 172.25.254.100:80 0 0 0 0 0 -> 192.168.0.10:80 0 0 0 0 0 -> 192.168.0.20:80 0 0 0 0 0#CPS 总链接的个数 #InPPS 进来的链接的个数 #OutPPS 出去的链接的个数 #InBPS 进来的所有数据的总量 #Out 出去的总量
删除
删除单个策略
[root@lvs ~]# ipvsadm -D -t 172.25.254.100:80一次性删除所有策略
[root@lvs ~]# ipvsadm -C
- 集群服务的RS管理
基础格式:
ipvsadm -a|e -t|u|f service-address -r realserver-address [-g|i|m] [-w weight]
基本参数:
-a #添加realserver
-e #更改realserver
-t #tcp协议
-u #udp协议
-f #火墙 标签
-r #realserver地址
-g #直连路由模式
-i #ipip隧道模式
-m #nat模式
-w #设定权重
-Z #清空计数器
-C #清空lvs策略
-L #查看lvs策略
-n #不做解析
--rate :输出速率信息
案例演示:
权重
[root@lvs ~]# ipvsadm -a -t 172.25.254.100:80 -r 192.168.0.10 -m -w 2 [root@lvs ~]# ipvsadm -a -t 172.25.254.100:80 -r 192.168.0.20 -m -w 1 权重生效 [root@lvs ~]# ipvsadm -E -t 172.25.254.100:80 -s wrr数据
查看数据流
[root@lvs ~]# ipvsadm -Ln --rate清除数据流
[root@lvs ~]# ipvsadm -Z[root@lvs ~]# ipvsadm -Ln --rate IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port CPS InPPS OutPPS InBPS OutBPS -> RemoteAddress:Port TCP 172.25.254.100:80 0 0 0 0 0 -> 192.168.0.10:80 0 0 0 0 0 -> 192.168.0.20:80 0 0 0 0 0
- 策略的保存
方法一
[root@lvs ~]# ipvsadm-save > /etc/sysconfig/ipvsadm加参数 -n 表示不做本地解析的保存,速度比较快。
[root@lvs ~]# ipvsadm-save -n > /etc/sysconfig/ipvsadm查看是否保存成功
[root@lvs ~]# cat /etc/sysconfig/ipvsadm -A -t 172.25.254.100:80 -s rr -a -t 172.25.254.100:80 -r 192.168.0.10:80 -m -w 1 -a -t 172.25.254.100:80 -r 192.168.0.20:80 -m -w 1
方法二
[root@lvs ~]# systemctl stop ipvsadm.service [root@lvs ~]# cat /etc/sysconfig/ipvsadm -A -t 172.25.254.100:80 -s rr -a -t 172.25.254.100:80 -r 192.168.0.10:80 -m -w 1 -a -t 172.25.254.100:80 -r 192.168.0.20:80 -m -w 1 [root@lvs ~]# systemctl start ipvsadm.service [root@lvs ~]# cat /etc/sysconfig/ipvsadm -A -t 172.25.254.100:80 -s rr -a -t 172.25.254.100:80 -r 192.168.0.10:80 -m -w 1 -a -t 172.25.254.100:80 -r 192.168.0.20:80 -m -w 1
- 策略的恢复
[root@lvs ~]# ipvsadm -C
[root@lvs ~]# ipvsadm-restore < /etc/sysconfig/ipvsadm
[root@lvs ~]# cat /etc/sysconfig/ipvsadm
-A -t 172.25.254.100:80 -s rr
-a -t 172.25.254.100:80 -r 192.168.0.10:80 -m -w 1
-a -t 172.25.254.100:80 -r 192.168.0.20:80 -m -w 1
6. LVS 部署 NAT 模式集群案例
6.1 实验环境介绍
本实验用到三台基于 RedHat9 系统的虚拟机。lvs 有两个网卡,分别是 nat 和仅主机。webserver1 和 webserver2 的网卡是仅主机。
6.2 lvs 部署
grubby --update-kernel ALL --args net.ifnames=0 reboot
[root@lvs ~]# cp /etc/NetworkManager/system-connections/ens160.nmconnection /etc/NetworkManager/system-connections/eth1.nmconnection [root@lvs ~]# vim /etc/NetworkManager/system-connections/eth1.nmconnection [connection] id=eth1 type=ethernet interface-name=eth1 [ipv4] address1=192.168.0.100/24 method=manual [root@lvs ~]# nmcli connection reload [root@lvs ~]# nmcli connection up eth1
[root@lvs ~]# cp /etc/NetworkManager/system-connections/ens160.nmconnection /etc/NetworkManager/system-connections/eth0.nmconnection [root@lvs ~]# vim /etc/NetworkManager/system-connections/eth0.nmconnection [connection] id=eth0 type=ethernet interface-name=eth0 [ipv4] address1=172.25.254.100/24,172.25.254.2 method=manual dns=114.114.114.114; [root@lvs ~]# nmcli connection reload [root@lvs ~]# nmcli connection up eth0 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/48) [root@lvs ~]#
[root@lvs ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.25.254.100 netmask 255.255.255.0 broadcast 172.25.254.255 inet6 fe80::e2ae:ae3f:cef2:aa0f prefixlen 64 scopeid 0x20<link> ether 00:0c:29:cc:33:e9 txqueuelen 1000 (Ethernet) RX packets 1940 bytes 207648 (202.7 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1545 bytes 207475 (202.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.25.254.100 netmask 255.255.255.0 broadcast 172.25.254.255 inet6 fe80::6e87:82da:8b78:8183 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:cc:33:f3 txqueuelen 1000 (Ethernet) RX packets 30 bytes 2880 (2.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 347 bytes 52159 (50.9 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 637 bytes 102216 (99.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 637 bytes 102216 (99.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@lvs ~]# cd /etc/NetworkManager/system-connections/ [root@lvs system-connections]# ll total 12 -rw-------. 1 root root 258 Aug 6 11:40 ens160.nmconnection -rw-------. 1 root root 138 Aug 6 13:00 eth0.nmconnection -rw-------. 1 root root 105 Aug 6 12:49 eth1.nmconnection
[root@lvs ~]# sysctl -a | grep ip_forward net.ipv4.ip_forward = 0 net.ipv4.ip_forward_update_priority = 1 net.ipv4.ip_forward_use_pmtu = 0 [root@lvs ~]# vim /etc/sysctl.conf # sysctl settings are defined through files in # /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/. # # Vendors settings live in /usr/lib/sysctl.d/. # To override a whole file, create a new file with the same in # /etc/sysctl.d/ and put new settings there. To override # only specific settings, add a file with a lexically later # name in /etc/sysctl.d/ and put new settings there. # # For more information, see sysctl.conf(5) and sysctl.d(5). net.ipv4.ip_forward=1 [root@lvs ~]# sysctl -p net.ipv4.ip_forward = 1
6.3 webserver1 部署
网卡设置仅主机
grubby --update-kernel ALL --args net.ifnames=0 reboot
[root@localhost ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 ether 00:0c:29:80:1b:d1 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 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 78 bytes 6797 (6.6 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 78 bytes 6797 (6.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# cp /etc/NetworkManager/system-connections/ens160.nmconnection /etc/NetworkManager/system-connections/eth0.nmconnection [root@localhost ~]# vim /etc/NetworkManager/system-connections/eth0.nmconnection [connection] id=eth0 type=ethernet interface-name=eth0 [ipv4] address1=192.168.0.10/24,192.168.0.100 method=manual [root@localhost ~]# nmcli connection reload [root@localhost ~]# nmcli connection up eth0 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3) [root@localhost ~]# nmcli connection show NAME UUID TYPE DEVICE eth0 7ba00b1d-8cdd-30da-91ad-bb83ed4f7474 ethernet eth0 lo 004aa9d5-d989-4408-ae53-6038a46f58e0 loopback lo ens160 4d5ba5ea-7760-3d52-a1f9-b5d402de2b09 ethernet -- [root@localhost ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.0.100 0.0.0.0 UG 100 0 0 eth0 192.168.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
[root@webserver1 ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.10 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::bb77:b655:beb2:2738 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:9c:75:73 txqueuelen 1000 (Ethernet) RX packets 219 bytes 29500 (28.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 530 bytes 90543 (88.4 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 1012 bytes 131838 (128.7 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1012 bytes 131838 (128.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# mount /dev/sr0 /mnt/ mount: /mnt: WARNING: source write-protected, mounted read-only. [root@localhost ~]# dnf install httpd -y
[root@localhost ~]# hostnamectl set-hostname webserver1.timinglee.org [root@localhost ~]# exit logout [redhat@localhost ~]$ su - Password: [root@webserver1 ~]#
[root@webserver1 ~]# echo webserver1 - 192.168.0.10 > /var/www/html/index.html [root@webserver1 ~]# systemctl enable --now httpd Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
6.4 webserver2 部署
[root@localhost ~]# hostnamectl set-hostname webserver2.timinglee.org [root@localhost ~]# exit logout [redhat@localhost ~]$ su - Password: [root@webserver2 ~]#
[root@webserver2 ~]# grubby --update-kernel ALL --args net.ifnames=0 [root@webserver2 ~]# reboot
[root@webserver2 ~]# cp /etc/NetworkManager/system-connections/ens160.nmconnection /etc/NetworkManager/system-connections/eth0.nmconnection [root@webserver2 ~]# vim /etc/NetworkManager/system-connections/eth0.nmconnection [connection] id=eth0 type=ethernet interface-name=eth0 [ipv4] address1=192.168.0.20/24,192.168.0.100 method=manual
[root@webserver2 ~]# nmcli connection reload [root@webserver2 ~]# nmcli connection up eth0
[root@webserver2 ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.20 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::c159:24f4:5f63:ec62 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:26:43:69 txqueuelen 1000 (Ethernet) RX packets 707 bytes 63412 (61.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 875 bytes 104812 (102.3 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 1001 bytes 139007 (135.7 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1001 bytes 139007 (135.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@webserver2 ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.0.100 0.0.0.0 UG 100 0 0 eth0 192.168.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
[root@webserver2 ~]# dnf install httpd -y [root@webserver2 ~]# echo webserver2 - 192.168.0.20 > /var/www/html/index.html [root@webserver2 ~]# systemctl enable --now httpd Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
6.5 LVS检测
环境检测
[root@lvs ~]# curl 192.168.0.10 webserver1 - 192.168.0.10 [root@lvs ~]# curl 192.168.0.20 webserver2 - 192.168.0.20
在 lvs 中安装 lvs 软件
[root@lvs ~]# dnf search lvs Updating Subscription Management repositories. Unable to read consumer identity This system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register. Last metadata expiration check: 1:47:52 ago on Tue 06 Aug 2024 02:54:56 PM CST. ========================== Summary Matched: lvs ========================== keepalived.x86_64 : High Availability monitor built upon LVS, VRRP and : service pollers [root@lvs ~]# dnf install ipvsadm -y
软件主配置文件
[root@lvs ~]# cat /etc/sysconfig/ipvsadm-config
配置策略文件
[root@lvs ~]# ipvsadm -A -t 172.25.254.100:80 -s rr Service already exists
参数注解
-A | 增加虚拟 server |
-t | 指定增加的调度是 tcp 服务 |
172.25.254.100:80 | 客户访问这个IP地址的80端口时开始调度 |
-s | 指定调度的算法 |
rr | 轮循调度,静态算法 |
[root@lvs ~]# ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 172.25.254.100:80 rr
服务有了以后写后端要调动的10、20主机
[root@lvs ~]# ipvsadm -a -t 172.25.254.100:80 -r 192.168.0.10:80 -m
-r 添加 real server -m 现在使用的lvs的模式为nat
测试。测试前要保证10、20主机httpd服务开启。访问的是最终的服务器10。
[root@lvs ~]# curl 172.25.254.100 webserver1 - 192.168.0.10
指定20服务器
[root@lvs ~]# ipvsadm -a -t 172.25.254.100:80 -r 192.168.0.20:80 -m
[root@lvs ~]# ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 172.25.254.100:80 rr -> 192.168.0.10:80 Masq 1 0 0 -> 192.168.0.20:80 Masq 1 0 0
172.25.254.100:80 rr LVS 的 vip。访问 vip 时 lvs 提供轮循调度,最终调度到10、20主机。10一次,20一次。
访问测试
[root@lvs ~]# for i in {1..10} > do > curl 172.25.254.100 > done webserver2 - 192.168.0.20 webserver1 - 192.168.0.10 webserver2 - 192.168.0.20 webserver1 - 192.168.0.10 webserver2 - 192.168.0.20 webserver1 - 192.168.0.10 webserver2 - 192.168.0.20 webserver1 - 192.168.0.10 webserver2 - 192.168.0.20
webserver1做本地解析
[root@webserver1 ~]# vim /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 172.25.254.100 lvs.timinglee.org 192.168.0.20 webserver2.timinglee.org
webserver2做本地解析
[root@webserver2 ~]# vim /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 172.25.254.100 lvs.timinglee.org 192.168.0.10 webserver1.timinglee.org
保存策略文件
[root@lvs ~]# ipvsadm-save > /etc/sysconfig/ipvsadm
7. LVS 部署 DR 模式集群案例
7.1 实验环境介绍
承接以上 NAT 模式,此时 lvs 不需要 nat 网卡,因为现在通信不是用 DIP而是用VIP。lvs 知道后面两台 realserver 的 MAC 地址,能用自己的 VIP 访问后面两台的 VIP。
realserver 上也有 VIP ,但是对外相应的IP是自己的真实IP。
7.2 router 部署
新虚拟机,网络适配器添加两个网卡,一个 NAT ,一个仅主机。
配置主机名
配置eth0
配置eth1
重启网卡
连接 xshell
[root@router ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection [connection] id=eth0 type=ethernet interface-name=eth0 [ipv4] method=manual address1=172.25.254.100/24 [root@router ~]# cat /etc/NetworkManager/system-connections/eth1.nmconnection [connection] id=eth1 type=ethernet interface-name=eth1 [ipv4] address1=192.168.0.100/24 method=manual
打开内核路由
[root@router ~]# sysctl -a | grep ip_forward net.ipv4.ip_forward = 0 net.ipv4.ip_forward_update_priority = 1 net.ipv4.ip_forward_use_pmtu = 0
[root@router ~]# vim /etc/sysctl.conf # sysctl settings are defined through files in # /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/. # # Vendors settings live in /usr/lib/sysctl.d/. # To override a whole file, create a new file with the same in # /etc/sysctl.d/ and put new settings there. To override # only specific settings, add a file with a lexically later # name in /etc/sysctl.d/ and put new settings there. # # For more information, see sysctl.conf(5) and sysctl.d(5). net.ipv4.ip_forward = 1
[root@router ~]# sysctl -p net.ipv4.ip_forward = 1
关闭防火墙
[root@router ~]# systemctl stop firewalld.service [root@router ~]# setenforce 0
7.3 lvs 部署
[root@lvs ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.25.254.100 netmask 255.255.255.0 broadcast 172.25.254.255 inet6 fe80::c159:24f4:5f63:ec62 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:cc:33:e9 txqueuelen 1000 (Ethernet) RX packets 5229 bytes 591035 (577.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 3557 bytes 293525 (286.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.100 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::c20f:eb78:b7dd:f9e6 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:cc:33:f3 txqueuelen 1000 (Ethernet) RX packets 1580 bytes 301265 (294.2 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 615 bytes 73291 (71.5 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 1228 bytes 244344 (238.6 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1228 bytes 244344 (238.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@lvs ~]# nmcli connection show NAME UUID TYPE DEVICE eth0 7ba00b1d-8cdd-30da-91ad-bb83ed4f7474 ethernet eth0 eth1 5eb4da26-5d1d-30a5-8747-80181ed055fa ethernet eth1 lo c0c6a419-4a2f-432d-a2a6-9dc24c354b9c loopback lo ens160 e2188ec9-64fb-3682-8219-aa9bc8cda9bc ethernet --
[root@lvs ~]# nmcli connection delete eth0 Connection 'eth0' (7ba00b1d-8cdd-30da-91ad-bb83ed4f7474) successfully deleted. [root@lvs ~]# nmcli connection delete eth1 [root@lvs ~]# nmcli connection delete eth1 Connection 'eth1' (5eb4da26-5d1d-30a5-8747-80181ed055fa) successfully deleted.
两个网卡都删除后去虚拟机的终端做。
配置 IP 和网关
IP 配置成功,连接 xshell。
[root@lvs ~]# cat /etc/NetworkManager/system-connections/eth1.nmconnection [connection] id=eth1 type=ethernet interface-name=eth1 [ipv4] address1=192.168.0.50/24,192.168.0.100 method=manual
[root@lvs ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.0.100 0.0.0.0 UG 100 0 0 eth1 192.168.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth1
用环回接口配置 vip 。
[root@lvs ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet6 fe80::9ac2:c9bc:95d3:844c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:cc:33:e9 txqueuelen 1000 (Ethernet) RX packets 11 bytes 704 (704.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 49 bytes 7758 (7.5 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.50 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::c20f:eb78:b7dd:f9e6 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:cc:33:f3 txqueuelen 1000 (Ethernet) RX packets 51 bytes 7736 (7.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 2404 bytes 324019 (316.4 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 112 bytes 9632 (9.4 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 112 bytes 9632 (9.4 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@lvs ~]# ip a a 192.168.0.200/32 dev lo
[root@lvs ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet 192.168.0.200/32 scope global lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:0c:29:cc:33:e9 brd ff:ff:ff:ff:ff:ff altname enp3s0 altname ens160 inet6 fe80::9ac2:c9bc:95d3:844c/64 scope link noprefixroute valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:0c:29:cc:33:f3 brd ff:ff:ff:ff:ff:ff altname enp19s0 altname ens224 inet 192.168.0.50/24 brd 192.168.0.255 scope global noprefixroute eth1 valid_lft forever preferred_lft forever inet6 fe80::c20f:eb78:b7dd:f9e6/64 scope link noprefixroute valid_lft forever preferred_lft forever
写路由策略
[root@lvs ~]# ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn
[root@lvs ~]# ipvsadm -A -t 192.168.0.200:80 -s wrr [root@lvs ~]# ipvsadm -a -t 192.168.0.200:80 -r 192.168.0.10:80 -g -w 1 [root@lvs ~]# ipvsadm -a -t 192.168.0.200:80 -r 192.168.0.20:80 -g -w 2
[root@lvs ~]# 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.0.200:80 wrr -> 192.168.0.10:80 Route 1 0 0 -> 192.168.0.20:80 Route 2 0 0
[root@lvs ~]# ipvsadm-save > /etc/sysconfig/ipvsadm
关闭防火墙
[root@lvs ~]# systemctl stop firewalld.service [root@lvs ~]# setenforce 0
7.4 webserver1 部署
禁用 arp 响应。使 vip 不对外响应。
[root@webserver1 ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore [root@webserver1 ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce [root@webserver1 ~]# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce [root@webserver1 ~]# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
企业里应该把 arp 禁用写到主配置文件里,此实验环境不用。
[root@webserver1 ~]# sysctl -a | grep arp_ignore net.ipv4.conf.all.arp_ignore = 1 net.ipv4.conf.default.arp_ignore = 0 net.ipv4.conf.eth0.arp_ignore = 0 net.ipv4.conf.lo.arp_ignore = 1 [root@webserver1 ~]# vim /etc/sysctl.conf 末尾添加net.ipv4.conf.all.arp_ignore = 1 [root@webserver1 ~]# sysctl -p
调整网关
[root@webserver1 ~]# vim /etc/NetworkManager/system-connections/eth0.nmconnection [connection] id=eth0 type=ethernet interface-name=eth0 [ipv4] address1=192.168.0.10/24,192.168.0.100 method=manual
[root@webserver1 ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.0.100 0.0.0.0 UG 100 0 0 eth0 192.168.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
[root@webserver1 ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.10 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::c159:24f4:5f63:ec62 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:9c:75:73 txqueuelen 1000 (Ethernet) RX packets 65 bytes 9362 (9.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 2294 bytes 317432 (309.9 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 112 bytes 9632 (9.4 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 112 bytes 9632 (9.4 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
用环回接口配置 vip 。
[root@webserver1 ~]# ip a a 192.168.0.200/32 dev lo [root@webserver1 ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet 192.168.0.200/32 scope global lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:0c:29:9c:75:73 brd ff:ff:ff:ff:ff:ff altname enp3s0 altname ens160 inet 192.168.0.10/24 brd 192.168.0.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet6 fe80::c159:24f4:5f63:ec62/64 scope link noprefixroute valid_lft forever preferred_lft forever
关闭防火墙
[root@webserver1 ~]# systemctl stop firewalld.service [root@webserver1 ~]# setenforce 0
检查 httpd 服务是否开启
[root@webserver1 ~]# systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; preset: disabled) Active: active (running) since Wed 2024-08-07 09:23:06 CST; 4min 0s ago Docs: man:httpd.service(8) Main PID: 1985 (httpd) Status: "Total requests: 6; Idle/Busy workers 100/0;Requests/sec: 0.0251; Bytes served/sec: 9 B/sec" Tasks: 177 (limit: 10886) Memory: 47.3M CPU: 554ms CGroup: /system.slice/httpd.service ├─1985 /usr/sbin/httpd -DFOREGROUND ├─1988 /usr/sbin/httpd -DFOREGROUND ├─1989 /usr/sbin/httpd -DFOREGROUND ├─1990 /usr/sbin/httpd -DFOREGROUND └─1997 /usr/sbin/httpd -DFOREGROUND Aug 07 09:23:06 webserver1.timinglee.org systemd[1]: Starting The Apache HTTP Server... Aug 07 09:23:06 webserver1.timinglee.org httpd[1985]: Server configured, listening on: port 80 Aug 07 09:23:06 webserver1.timinglee.org systemd[1]: Started The Apache HTTP Server.
7.5 webserver2 部署
禁用 arp 响应。使 vip 不对外响应。
[root@webserver2 ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore [root@webserver2 ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce [root@webserver2 ~]# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce [root@webserver2 ~]# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
注意指定网关为 router 的仅主机IP(内网接口)。
[root@webserver2 ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection [connection] id=eth0 type=ethernet interface-name=eth0 [ipv4] address1=192.168.0.20/24,192.168.0.100 method=manual
[root@webserver2 ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.0.100 0.0.0.0 UG 100 0 0 eth0 192.168.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
用环回接口配置 vip 。
[root@webserver2 ~]# ip a a 192.168.0.200/32 dev lo [root@webserver2 ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet 192.168.0.200/32 scope global lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:0c:29:26:43:69 brd ff:ff:ff:ff:ff:ff altname enp3s0 altname ens160 inet 192.168.0.20/24 brd 192.168.0.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet6 fe80::bb77:b655:beb2:2738/64 scope link noprefixroute valid_lft forever preferred_lft forever
关闭防火墙
[root@webserver2 ~]# systemctl stop firewalld.service [root@webserver2 ~]# setenforce 0
检查 httpd 服务是否开启。
[root@webserver2 ~]# systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; preset: disabled) Active: active (running) since Wed 2024-08-07 02:05:19 CST; 7h ago Docs: man:httpd.service(8) Main PID: 995 (httpd) Status: "Total requests: 34; Idle/Busy workers 100/0;Requests/sec: 0.00128; Bytes served/sec: 0 B/sec" Tasks: 177 (limit: 10885) Memory: 44.8M CPU: 4.731s CGroup: /system.slice/httpd.service ├─ 995 /usr/sbin/httpd -DFOREGROUND ├─1012 /usr/sbin/httpd -DFOREGROUND ├─1014 /usr/sbin/httpd -DFOREGROUND ├─1015 /usr/sbin/httpd -DFOREGROUND └─1017 /usr/sbin/httpd -DFOREGROUND Aug 07 02:05:19 webserver2 systemd[1]: Starting The Apache HTTP Server... Aug 07 02:05:19 webserver2 httpd[995]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using ::1. Set the 'Serve> Aug 07 02:05:19 webserver2 httpd[995]: Server configured, listening on: port 80 Aug 07 02:05:19 webserver2 systemd[1]: Started The Apache HTTP Server. lines 1-20/20 (END)
7.6 client 部署并测试
只有一个 nat 网卡。
改主机名
配置IP和网卡
连接 xshell 。
[root@client ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection [connection] id=eth0 type=ethernet interface-name=eth0 [ipv4] method=manual address1=172.25.254.200/24,172.25.254.100
查看路由
[root@client ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 172.25.254.100 0.0.0.0 UG 100 0 0 eth0 172.25.254.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
关闭防火墙
[root@client ~]# systemctl stop firewalld.service [root@client ~]# setenforce 0
测试
[root@client ~]# ping 192.168.0.200 PING 192.168.0.200 (192.168.0.200) 56(84) bytes of data. 64 bytes from 192.168.0.200: icmp_seq=1 ttl=63 time=0.684 ms 64 bytes from 192.168.0.200: icmp_seq=2 ttl=63 time=0.564 ms ^C --- 192.168.0.200 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1026ms rtt min/avg/max/mdev = 0.564/0.624/0.684/0.060 ms
[root@client ~]# ping 192.168.0.100 PING 192.168.0.100 (192.168.0.100) 56(84) bytes of data. 64 bytes from 192.168.0.100: icmp_seq=1 ttl=64 time=0.358 ms 64 bytes from 192.168.0.100: icmp_seq=2 ttl=64 time=0.569 ms 64 bytes from 192.168.0.100: icmp_seq=3 ttl=64 time=0.608 ms ^C --- 192.168.0.100 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2035ms rtt min/avg/max/mdev = 0.358/0.511/0.608/0.109 ms
[root@client ~]# for i in {1..10} > do > curl 192.168.0.200 > done webserver1 - 192.168.0.10 webserver2 - 192.168.0.20 webserver2 - 192.168.0.20 webserver1 - 192.168.0.10 webserver2 - 192.168.0.20 webserver2 - 192.168.0.20 webserver1 - 192.168.0.10 webserver2 - 192.168.0.20 webserver2 - 192.168.0.20 webserver1 - 192.168.0.10