当前位置: 首页 > news >正文

Haproxy实验

环境:

        servera(Haproxy):192.168.233.132
        serverb(web1):192.168.233.144
        serverc(web2):192.168.233.140
        serverd(客户端):192.168.233.141
 

servera(Haproxy):

yum install haproxy -y
vim /etc/haproxy/haproxy.cfg(配置文件) 
# 设置日志,记录在本地3号设备上,记录级别为info
globallog 127.0.0.1 local3 info# 最大连接数为4096maxconn 4096# 运行haproxy的用户和组user nobodygroup nobody# 以守护进程方式运行daemon# 进程数为1nbproc 1# PID文件路径pidfile /run/haproxy.pid# 默认配置
defaults# 全局日志记录log global# 模式为HTTPmode http# 最大连接数为2048maxconn 2048# 重试次数为3retries 3# 开启转发option redispatch# 连接超时时间为5秒timeout connect 5000# 客户端超时时间为50秒timeout client 50000# 服务器超时时间为50秒timeout server 50000# 关闭连接时强制关闭option abortonclose# 配置统计页面stats uri /admin?statsstats realm Private landsstats auth admin:passwordstats hide-version# 前端配置
frontend http-in# 监听所有IP的80端口bind 0.0.0.0:80# 使用HTTP模式mode http# 记录日志log global# 开启httplog选项option httplog# 关闭HTTP长连接option httpclose# 定义acl规则acl html url_reg -i \.html$# 如果是HTML文件,则使用html-server后端use_backend html-server if html# 默认使用html-server后端default_backend html-server# 后端配置
backend html-server# 使用HTTP模式mode http# 负载均衡算法为轮询balance roundrobin# 健康检查请求为GET /index.htmloption httpchk GET /index.html# 插入SERVERID COOKIE,并且间接设置,不缓存cookie SERVERID insert indirect nocache# 配置服务器Aserver html-A web1:80 weight 1 cookie 3 check inter 2000 rise 2 fall 5# 配置服务器Bserver html-B web2:80 weight 1 cookie 4 check inter 2000 rise 2 fall 5systemctl start haproxy

serverb(web1):

    setenforce 0systemctl stop firewalldyum install httpd -yecho web1 > /var/www/html/index.htmlsystemctl enable httpdsystemctl start httpd

serverc(web2):

setenforce 0systemctl stop firewalldyum install httpd -yecho web2 > /var/www/html/index.htmlsystemctl enable httpdsystemctl start httpd

serverd(客户端):

vim /etc/hosts
192.168.233.141 client
192.168.233.144 web1
192.168.233.140 web2
192.168.233.132 haproxy
所有server及都要配hosts

在haproxy端访问:

lynx --dump http://haproxy

http://www.lryc.cn/news/301753.html

相关文章:

  • CSRNET图像修复,DNN
  • 004 - Hugo, 分类
  • Vue3之ElementPlus中Table选中数据的获取与清空方法
  • Leetcode 516.最长回文子序列
  • cool Node后端 中实现中间件的书写
  • Leecode之面试题消失的数字
  • STM32的三种下载方式
  • 华为 huawei 交换机 接口 MAC 地址学习限制接入用户数量 配置示例
  • 使用Python生成二维码的完整指南
  • 排序前言冒泡排序
  • 红队笔记Day3-->隧道上线不出网机器
  • C 练习实例70-求字符串长度
  • HarmonyOS—@State装饰器:组件内状态
  • Linux系统——防火墙拓展及重点理解
  • 阿里云短信验证码的两个坑
  • c入门第十五篇——学而时习之(阶段性总结)
  • 抽象的前端
  • UPC训练赛二十/20240217
  • 【51单片机】LCD1602(江科大)
  • conda与pip的常用命令
  • 你知道什么是物联网MQTT么?
  • P8 pair vector
  • 奇异值分解(SVD)的应用——图像压缩
  • RTDETR改进系列指南
  • 类和结构体的区别
  • 利用Excel模拟投币试验
  • WebService接口测试
  • 语音唤醒——
  • typeScript 类型推论
  • JavaScript 设计模式之代理模式