haproxy+httpd网站架构,实现负载均衡实验笔记

前提准备:

  1. 两台httpd,一台haproxy,NFS部署在任意一台httpd上
  2. http1:192.168.180.110
  3. http2:192.168.180.120,NFS
  4. haproxy:192.168.180.100

http(两台httpd的操作是一样的):

  1. 安装httpd
bash 复制代码
yum install -y httpd

2.分别编写网页

bash 复制代码
echo "server1 192.168.180.110" > /var/www/html/index.html
echo "server2 192.168.180.120" > /var/www/html/index.html
  1. 开启httpd
bash 复制代码
systemctl start httpd
  1. 关闭防火墙
bash 复制代码
systemctl stop firewalld
setenforce 0

haproxy:

  1. 安装haproxy(通过源码包安装)
bash 复制代码
yum install -y gcc gcc-c++ make lrzsz
tar zxf haproxy-2.9.9.tar.gz
cd haproxy-2.9.9
make TARGET=linux-glibc && make install
  1. 移动主配置文件
bash 复制代码
mkdir /etc/haproxy
cp addons/ot/test/sa/haproxy.cfg /etc/haproxy/
  1. 修改主配置文件
bash 复制代码
vim /etc/haproxy/haproxy.cfg
将端口改为8080

注释

添加内容
frontend http_front
        bind *:80
                 default_backend servers-backend

backend servers-backend
    mode http
    server inst1 192.168.180.110:80 check inter 80 fall 3
    server inst2 192.168.180.120:80 check inter 80 fall 3 backup
  1. 创建自启动脚本
bash 复制代码
cp ~/haproxy-2.9.9/examples/haproxy.init /etc/init.d/haproxy
ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy
chmod +x /etc/init.d/haproxy
chkconfig --add /etc/init.d/haproxy
/etc/init.d/haproxy start
  1. 关闭防火墙
bash 复制代码
systemctl stop firewalld
setenforce 0

NFS-192.168.180.120:

  1. 在httpd上均安装
bash 复制代码
yum install -y nfs-utils rpcbind
  1. 创建共享目录
bash 复制代码
mkdir -p /opt/wwwroot
vim /etc/exports
/opt/wwwroot    192.168.180.0/24(rw,sync,no_root_squash)
  1. 分别启动
bash 复制代码
systemctl start nfs
systemctl start rpcbind
  1. 查看NFS共享了什么目录
bash 复制代码
showmount -e 192.168.180.120
  1. http均挂载NFS共享目录
bash 复制代码
mount 192.168.180.120:/opt/wwwroot /var/www/html/
  1. 创建测试页面
bash 复制代码
echo "http-NFS" > /opt/wwwroot/index.html
  1. 访问测试
相关推荐
西门老铁14 分钟前
AI 时代高效画图的方案——AIGC+PlantUML
架构
这token有力气14 分钟前
3000行全塞一个 index.html?四刀瘦身手术,不装 Vite 也能模块化
架构
刘立军21 分钟前
领域驱动设计:给 AI 划定上下文边界,告别“大泥球”代码
架构·ai编程·领域驱动设计
用户6919026813391 小时前
用浏览器 WebGPU跑DPSK大模型(1) - 模型的下载和前端下载进度的显示
javascript·react.js·架构
zhangrelay1 小时前
ROS 2 Lyrical 第4章 URDF机器人建模与Gazebo Garden仿真
linux·笔记·学习·ubuntu·机器人·ros2
xianyuCcCcCCCcc1 小时前
Nginx 深度解析:从基础架构到反向代理与负载均衡实战全解
linux·运维·nginx·bash·负载均衡
xiaoshuai10242 小时前
编译管不着的跨层 bug:用 4 道脚本闸守住 API/SQL/权限/迁移
架构
疯狂打码的少年2 小时前
【数据结构】串的模式匹配:KMP算法(重点)
数据结构·笔记·算法
一米阳光86612 小时前
软考(中级)软件设计师核心笔记(8)数据结构——线性结构、数组、矩阵
数据结构·笔记·职场发展·软考·软件设计师·中级职称
Dr.kangder2 小时前
嵌入式面试总结(八)——大小端
嵌入式硬件·面试·职场和发展·架构·嵌入式