基于 openEuler 构建 LVS-NAT 集群和ldirectord监控RS

1、环境准备

准备好下面四台台服务器:

|-------------|----------------------------------------|--------------|
| 主机名 | IP | 角色 |
| open-Euler1 | 192.168.121.150(公网)、192.168.16.150(内网) | LVS |
| openEuler-2 | 192.168.121.151 | Real Server1 |
| openEuler-3 | 192.168.121.152 | Real Server2 |
| Rocky8 | 192.168.121.160 | Client |

2、Web服务器配置

在两台RS上安装并配置nginx服务:

bash 复制代码
open-Euler2
[root@open-Euler2 ~]# echo "This is test page `hostname -I`" > /var/www/html/index.html
[root@open-Euler2 ~]# systemctl restart httpd
[root@open-Euler2 ~]# curl 192.168.16.151
This is test page 192.168.16.151 


open-Euler3
[root@open-Euler3 ~]# echo "This is test page `hostname -I`" > /var/www/html/index.html
[root@open-Euler3 ~]# systemctl restart httpd
[root@open-Euler3 ~]# curl 192.168.16.152
This is test page 192.168.16.152 

3、LVS开启路由转发

在lvs上:

bash 复制代码
临时开启:
1、echo1>/proc/sys/net/ipv4/ip_forward
2、sysctl -w net.ipv4.ip_forward=1
永久开启:
修改文件 /etc/sysctl.conf
net.ipv4.ip forward=1
使生效:sysctl -p

4、LVS配置

在lvs上:

bash 复制代码
[root@opem-Euler1 yum.repos.d]# yum install ipvsadm #下载ipvsadm管理工具
[root@localhost yum.repos.d]# ipvsadm -At 192.168.121.150:80 -s rr
[root@localhost yum.repos.d]# ipvsadm -at 192.168.121.150:80 -r 192.168.16.151:80 -m
[root@localhost yum.repos.d]# ipvsadm -at 192.168.121.150:80 -r 192.168.16.152:80 -m
[root@openEuler-1 ~]# 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.121.150:80 rr
  -> 192.168.16.151:80            Masq    1      0          0
  -> 192.168.16.152:80            Masq    1      0          0

5、LVS-NAT 集群测试

在Client上:

bash 复制代码
[root@Rocky8 ~]# for ((i=0;i<=9;i++)); do curl 192.168.121.150:80; done
This is test page 192.168.16.152 
This is test page 192.168.16.151 
This is test page 192.168.16.152 
This is test page 192.168.16.151 
This is test page 192.168.16.152 
This is test page 192.168.16.151 
This is test page 192.168.16.152 
This is test page 192.168.16.151 
This is test page 192.168.16.152 
This is test page 192.168.16.151 

6.ldirectord工具

1.简介

ldirectord是专门为LVS监控而编写的,用来监控lvs架构中服务器池(server pool) 的服务器状态。 ldirectord 运行在 IPVS 节点上, ldirectord作为一个守护进程启动后会对服务器池中的每个真实服务器 发送请求进行监控,如果 服务器没有响应 lldirectord 的请求,那么ldirectord 认为该服务器不可用, ldirectord 会运行 ipvsadm 对 IPVS表中该服务器进行删除,如果等下次再次检测有相应则通过ipvsadm 进行添加

ldirectord:监控和控制LVS守护进程,可管理LVS规则

2.工具下载地址

http://rpm.pbone.net/index.php3/stat/4/idpl/23860919/dir/centos_6/com/ldirectord-3.9.5- 3.1.x86_64.rpm.html

3.配置

创建 /etc/ha.d/ldirectord.cf 文件在文件里面添加以下内容:

bash 复制代码
# 健康检查超时时间(秒)
checktimeout = 3
# 健康检查间隔时间(秒)
checkinterval = 1
# 是否在配置文件更改时自动重新加载
autoreload = yes
# ldirectord日志文件路径
logfile = "/var/log/ldirectord.log"
# 是否在健康检查失败时将节点设置为静默状态
quiescent = no

# 虚拟服务的IP地址和端口
virtual = 192.168.121.150:80
# 第一个真实服务器的IP地址、端口和转发模式(masq表示NAT)
real = 192.168.16.151:80 masq
# 第二个真实服务器的IP地址、端口和转发模式(masq表示NAT)
real = 192.168.16.152:80 masq
# 所有真实服务器都失败时的备用服务器
fallback = 127.0.0.1:80
# 服务类型(HTTP)
service = http
# 调度算法(轮询)
scheduler = rr
# 会话持久性超时时间
#persistent = 600
# 控制持久性的网络掩码
#netmask = 255.255.255.255
# 使用的协议(TCP)
protocol = tcp
# 健康检查类型(协商)
checktype = negotiate
# 健康检查的端口
checkport = 80

注:这个配置文件里的内容跟之前ipvsadm配置的内容重合了,我们可以用该命令删掉之前的ipvsadm配置

ipvsadm -C

4.重启服务

bash 复制代码
systemctl status ldirectord.service

这里重新生成了虚拟服务器配置

5.测试

相关推荐
dessler25 分钟前
代理服务器-LVS的DR模式
linux·运维·云计算
梦星辰.1 小时前
VSCode CUDA C++进行Linux远程开发
linux·c++·vscode
远方16092 小时前
0x-2-Oracle Linux 9上安装JDK配置环境变量
java·linux·oracle
cui_win2 小时前
每日一令:Linux 极简通关指南 - 汇总
linux·运维·服务器
知星小度S2 小时前
Linux权限探秘:驾驭权限模型,筑牢系统安全
linux·运维·服务器
黄交大彭于晏2 小时前
发送文件脚本源码版本
java·linux·windows
搞Linux的杰仔3 小时前
Ubuntu20.04基础配置安装——系统安装(一)
linux·嵌入式开发
Kaede65 小时前
如何应对Linux云服务器磁盘空间不足的情况
linux·运维·服务器
Kookoos8 小时前
Dynamics 365 Finance + Power Automate 自动化凭证审核
运维·自动化·dynamics 365·power automate
apocelipes11 小时前
Linux c 运行时获取动态库所在路径
linux·c语言·linux编程