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. 访问测试
相关推荐
heart_fly_in_sky2 小时前
Mali GPU架构深度解析:Bifrost架构与优化策略(Lesson 4)
架构
2501_933329553 小时前
企业级AI舆情中台架构实践:Infoseek系统如何实现亿级数据实时监测与智能处置?
人工智能·架构
Mr.朱鹏3 小时前
Nginx路由转发案例实战
java·运维·spring boot·nginx·spring·intellij-idea·jetty
奈斯ing8 小时前
【Oracle篇】基于OGG 21c全程图形化实现9TB数据从Oracle 11g到19c的不停机迁移(上):微服务架构详解与微服务部署,及同步问题总览(第一篇,总共三篇)
微服务·oracle·架构
Hernon8 小时前
微服务架构设计 - 架构取舍决策CAP
微服务·云原生·架构
LINgZone28 小时前
领域驱动设计(DDD)在架构中的应用
架构
潆润千川科技8 小时前
架构演进思考:中老年社交应用如何通过数据治理与业务解耦实现稳健增
架构·聊天小程序
潆润千川科技8 小时前
适老社交应用后端架构思考:在安全、性能与简单之间的平衡艺术
安全·架构
NGINX开源社区11 小时前
借助 Okta 和 NGINX Ingress Controller 实现 K8s OpenID Connect 身份验证
运维·nginx·kubernetes
vx-bot55566611 小时前
企业微信接口在微服务协同架构中的事件桥接与状态同步模式
微服务·架构·企业微信