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. 访问测试
相关推荐
受之以蒙6 小时前
赋能 AI 与具身智能:Rust ndarray 构建安全高效的数据底座
人工智能·笔记·rust
绝无仅有6 小时前
某东互联网大厂的Redis面试知识点分析
后端·面试·架构
lijun_xiao20098 小时前
Dubbo-学习笔记1
笔记·学习
serendipity_hky8 小时前
【微服务 - easy视频 | day04】Seata解决分布式事务
java·spring boot·分布式·spring cloud·微服务·架构
卡提西亚8 小时前
C++笔记-23-类和对象-多态
c++·笔记
梁小憨憨8 小时前
Psychtoolbox (PTB)安装指南
笔记
摇滚侠8 小时前
Vue 项目实战《尚医通》,底部组件拆分与静态搭建,笔记05
前端·vue.js·笔记·vue
hour_go9 小时前
DeepHunt微服务故障定位系统核心技术解析1
微服务·云原生·架构
绝无仅有9 小时前
某东电商平台的MySQL面试知识点分析
后端·面试·架构
程序员古德10 小时前
25年11月软考架构真题《论无服务器架构(Serverless)》考后复盘总结
云原生·架构·serverless