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

前提准备:

  1. 两台nginx,一台haproxy
  2. nginx1:192.168.180.120
  3. nginx2:192.168.180.130,NFS
  4. haproxy:192.168.180.110

nginx(两台nginx的操作是一样的):

  1. 安装nginx
bash 复制代码
#先安装这个
yum install -y epel-release
yum install -y nginx

2.分别编写网页

bash 复制代码
echo "server1 192.168.180.120" >/usr/share/nginx/html/index.html
echo "server2 192.168.180.130" >/usr/share/nginx/html/index.html
  1. 开启nginx
bash 复制代码
systemctl start nginx
  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.120:80 check inter 80 fall 3
    server inst2 192.168.180.130: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.130:

  1. 在nginx上均安装
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.130
  1. nginx均挂载NFS共享目录
bash 复制代码
mount 192.168.180.130:/opt/wwwroot /usr/share/nginx/html/
  1. 创建测试页面
bash 复制代码
echo "nginx-NFS" > /usr/share/nginx/html/index.html
  1. 访问测试
相关推荐
职业码农NO.115 分钟前
AI 技术栈完整解析,从 GPU 到应用的五层架构
人工智能·架构·系统架构·aigc·agent
云小逸24 分钟前
【windows系统编程】第一章 Windows 系统核心架构与基础概念
windows·架构
川西胖墩墩34 分钟前
团队协作泳道图制作工具 PC中文免费
大数据·论文阅读·人工智能·架构·流程图
码间拾光・菲林斯40 分钟前
PostgreSQL 微服务架构开发实战:数据一致性、多租户设计与框架集成
微服务·postgresql·架构
Python_Study202542 分钟前
企业级数据采集系统选型指南:从技术挑战到架构实践
架构
it_czz1 小时前
告警分析系统可视化方案全面对比
架构
Anarkh_Lee2 小时前
别再手写 conf 了!NgxFlow:基于 React Flow 的 Nginx 可视化与调试神器
前端·nginx·数据可视化
Run Out Of Brain2 小时前
解决nginx代理配置下wordpress的 /wp-admin/返回 302 重定向到登录页问题
运维·nginx
wenzhangli72 小时前
告别手撸架构图!AI+Ooder实现漂亮架构+动态交互+全栈可视化实战指南
人工智能·架构·交互
容智信息4 小时前
Hyper Agent:企业级Agentic架构怎么实现?
人工智能·信息可视化·自然语言处理·架构·自动驾驶·智慧城市