基于 openEuler 构建 LVS-NAT 群集

1、环境准备

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

|-------------|-------------------------------------------|--------------|
| 主机名 | IP | 角色 |
| openEuler-1 | 192.168.121.11(公网)、192.168.121.131.11(内网) | LVS |
| openEuler-2 | 192.168.131.12 | Real Server1 |
| openEuler-3 | 192.168.131.13 | Real Server2 |
| Rocky8 | 192.168.121.51 | Client |

2、Web服务器配置

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

复制代码
[root@openEuler-2 ~]# echo "web test page!(ip:`hostname -I`)" > /usr/share/nginx/html/index.html

[root@openEuler-2 ~]# systemctl restart nginx

[root@openEuler-2 ~]# curl localhost
this is test page!(ip:192.168.131.12 )

# 第二台RS配置同上

注意:RS的网关是lvs的DIP(内网地址)。

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@openEuler-1 ~]# ipvsadm -At 192.168.121.11:80 -s rr
[root@openEuler-1 ~]# ipvsadm -at 192.168.121.11:80 -r 192.168.131.12:80 -m
[root@openEuler-1 ~]# ipvsadm -at 192.168.121.11:80 -r 192.168.131.13: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.11:80 rr
  -> 192.168.131.12:80            Masq    1      0          0
  -> 192.168.131.13:80            Masq    1      0          0

6、测试

在Client上:

复制代码
[root@localhost ~]# for ((i=1;i<10;i++))
> do
> curl 192.168.121.11
> done
web test page!(ip:192.168.131.13 )
web test page!(ip:192.168.131.12 )
web test page!(ip:192.168.131.13 )
web test page!(ip:192.168.131.12 )
web test page!(ip:192.168.131.13 )
web test page!(ip:192.168.131.12 )
web test page!(ip:192.168.131.13 )
web test page!(ip:192.168.131.12 )
web test page!(ip:192.168.131.13 )
相关推荐
眠修1 小时前
Kuberrnetes 服务发布
linux·运维·服务器
寻月隐君3 小时前
Rust 异步编程实践:从 Tokio 基础到阻塞任务处理模式
后端·rust·github
bingGO549913 小时前
github 集成CICD自动化部署
github
超龄超能程序猿3 小时前
Bitvisse SSH Client 安装配置文档
运维·ssh·github
即将头秃的程序媛4 小时前
centos 7.9安装tomcat,并实现开机自启
linux·运维·centos
fangeqin4 小时前
ubuntu源码安装python3.13遇到Could not build the ssl module!解决方法
linux·python·ubuntu·openssl
爱奥尼欧6 小时前
【Linux 系统】基础IO——Linux中对文件的理解
linux·服务器·microsoft
超喜欢下雨天6 小时前
服务器安装 ros2时遇到底层库依赖冲突的问题
linux·运维·服务器·ros2
Natsume17107 小时前
嵌入式开发:GPIO、UART、SPI、I2C 驱动开发详解与实战案例
c语言·驱动开发·stm32·嵌入式硬件·mcu·架构·github
tan77º7 小时前
【Linux网络编程】网络基础
linux·服务器·网络