环境准备
| 编号 | 主机 | IP | 软件 | 系统 |
|---|---|---|---|---|
| 1 | lb01 | 192.168.72.100 | haproxy | redhat 9.7 |
| 2 | web1 | 192.168.72.10 | nginx | redhat 9.7 |
| 3 | web2 | 192.168.72.20 | nginx | redhat 9.7 |
1.1 搭建 Web1
初始化虚拟机(设置 IP、主机名,关闭防火墙和 SELinux)。
[root@node1 ~]# hostnamectl set-hostname web1 && bash
[root@web1 ~]# systemctl disable firewalld.service
[root@web1 ~]# setenforce 0
[root@web1 ~]# sed -i "s/SELINUX=enforcing/SELINUX=permissive/" /etc/selinux/config
安装 Nginx。
[root@web1 ~]# dnf install nginx -y
修改欢迎页。
[root@web1 ~]# echo "$(hostname) $(hostname -I)" > /usr/share/nginx/html/index.html
[root@web1 ~]# echo "health" > /usr/share/nginx/html/test.html
启动 Nginx 并测试。
[root@web1 ~]# systemctl start nginx
[root@web1 ~]# curl localhost
web1 192.168.72.10
[root@web1 ~]# curl 192.168.72.10
web1 192.168.72.10
1.2 搭建 Web2
初始化虚拟机。
[root@node1 ~]# hostnamectl set-hostname web2 && bash
[root@web2 ~]# systemctl disable firewalld.service
[root@web2 ~]# setenforce 0
[root@web2 ~]# sed -i "s/SELINUX=enforcing/SELINUX=permissive/" /etc/selinux/config
安装 Nginx。
[root@web2 ~]# dnf install nginx -y
修改欢迎页,创建健康检测页面。
[root@web2 ~]# echo "$(hostname) $(hostname -I)" > /usr/share/nginx/html/index.html
[root@web2 ~]# > /usr/share/nginx/html/test.html

