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

 1、环境准备

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

主机名IP角色
open-Euler1192.168.121.150(公网)、192.168.16.150(内网)LVS
openEuler-2192.168.121.151Real Server1
openEuler-3192.168.121.152Real Server2
Rocky8192.168.121.160Client

2、Web服务器配置

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

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上:

临时开启:
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上:

[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上:

[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 文件在文件里面添加以下内容:

# 健康检查超时时间(秒)
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.重启服务

systemctl status ldirectord.service

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

5.测试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值