Haproxy 七层负载和四层负载

1、拓扑结构

2、调度器配置 Haproxy

复制代码
[root@haproxy-lb1 ~]# /etc/haproxy/haproxy.cfg
global
    log                     127.0.0.1 local2
    chroot                  /var/lib/haproxy
    pidfile                 /var/run/haproxy.pid
    maxconn                 4000
    user                    haproxy
    group                   haproxy
    daemon

defaults
    mode                     http
    log                      global
    option                   dontlognull
    retries                  3
    maxconn                  3000
    timeout connect          50000
    timeout client           50000
    timeout server           50000

listen stats
    bind                    *:1314
    stats                   enable
    stats                   hide-version
    stats uri               /haproxystats
    stats realm             Haproxy\ stats
    stats auth              admin:admin
    stats admin             if TRUE

frontend web
    option                   httplog
    option                   http-server-close
    option forwardfor        except 127.0.0.0/8
    #option                  redispatch
    mode                     http
    bind                     *:80
    default_backend          httpservers

backend httpservers
    balance roundrobin
    server http1 8.154.47.100:80 check maxconn 2000
    server http2 121.199.30.100:80 check maxconn 2000

3、登录 web 监控页面查看状态

4、HAProxy 监控页面参数解释

1、服务状态说明
  • pid = 3698 (process #2, nbproc = 2, nbthread = 2) # pid为当前pid号,process为当前进程号,nbproc和nbthread为一共多少进程和每个进程多少个线程

    uptime = 0d 0h00m08s # 启动了多长时间

  • system limits: memmax = unlimited; ulimit-n = 131124 # 系统资源限制:内存/最大打开文件数/

  • maxsock = 131124; maxconn = 65536; maxpipes = 0 # 最大socket连接数/单进程最大连接数/最大管道数maxpipes

  • current conns = 1; current pipes = 0/0; conn rate = 1/sec # 当前连接数/当前管道数/当前连接速率

    Running tasks: 1/9; idle = 100 % # 运行的任务/当前空闲率

  • active UP: # 在线服务器 backup UP: # 标记为backup的服务器

  • active UP, going down: # 监测未通过正在进入down过程 backup UP, going down: # 备份服务器正在进入down过程

  • active DOWN, going up: # down的服务器正在进入up过程 backup DOWN, going up:# 备份服务器正在进入up过程

  • active or backup DOWN: # 在线的服务器或者是backup的服务器已经转换成了down状态 not checked:# 标记为不监测的服务器

  • active or backup DOWN for maintenance (MAINT) #active或者backup服务器认为下线的

  • active or backup SOFT STOPPED for maintenance #active或者backup被认为软下线(人为将weight改成0)

2、前后端状态说明
1、Queue(队列信息)
  • Cur: current queued requests # 当前的队列请求数量

  • Max:max queued requests # 最大的队列请求数量

  • Limit:sessions limit # 队列限制数量

2、Session rate(每秒的连接回话信息)
  • scur: current sessions # 每秒的当前回话的限制数量

  • smax: max sessions # 每秒的新的最大的会话量

  • slim: sessions limit # 每秒的新会话的限制数量

2、Sessions(会话信息)
  • Total: # 总共会话量

  • Cur: # 当前的会话

  • Max: # 最大会话

  • Limit: # 会话限制

  • Lbtot: total number of times a server was selected # 选中一台服务器所用的总时间

3、Bytes(流量统计信息)
  • In: # 网络的字节数输入总量

  • Out: # 网络的字节数输出总量

4、Denied(拒绝统计信息)
  • Req: denied requests # 拒绝请求量

  • Resp:denied responses # 拒绝回应

5、Errors (错误统计信息)
  • Req:request errors # 错误请求

  • Conn:connection errors # 错误的连接

  • Resp: response errors (among which srv_abrt) # 错误的回应

6、Warnings (警告统计信息)
  • Retr: retries (warning) # 重新尝试

  • Redis:redispatches (warning) # 再次发送

7、Server (real server信息)
  • Status: 后端机器状态,包括up(后端机活动)和down(后端机挂掉)两种状态

  • LastChk: 持续检查后端服务器的时间

  • Wght: (weight) : 权重

  • Act: server is active (server), number of active servers (backend) # 活动链接数量

  • Bck: server is backup (server), number of backup servers (backend) # 备份的服务器数量

  • Chk: 心跳检测时间

  • Down:后端服务器连接后都是down的数量

  • Downtime: downtime: total downtime (in seconds) # 总的downtime 时间

  • Throttle: warm up status # server 的状态

Haproxy 实现四层负载

1、Haproxy L4 配置

复制代码
[root@haproxy-lb1 ~]# /etc/haproxy/haproxy.cfg
global
    log                     127.0.0.1 local2
    chroot                  /var/lib/haproxy
    pidfile                 /var/run/haproxy.pid
    maxconn                 4000
    user                    haproxy
    group                   haproxy
    daemon
    
defaults
    mode                    http
    log                     global
    option                  dontlognull
    retries                 3
    maxconn                 3000
    contimeout              50000
    clitimeout              50000
    srvtimeout              50000

listen stats
    bind                    *:1314
    stats                   enable
    stats                   hide-version
    stats uri               /haproxystats
    stats realm             Haproxy\ stats
    stats auth              admin:admin
    stats admin             if TRUE

frontend web
    option                   httplog
    option                   http-server-close
    option forwardfor        except 127.0.0.0/8
    #option                  redispatch
    mode                     http
    bind                     *:80
    default_backend          httpservers

backend httpservers
    balance roundrobin
    server http1 121.40.149.21:80 check maxconn 2000
    server http2 121.40.149.21:80 check maxconn 2000
    server http3 121.40.149.21:80 check maxconn 2000

listen mysql
    bind *:3306
    mode tcp
    balance roundrobin
    server mysql1 8.154.47.100:3306 weight 1  check inter 1s rise 2 fall 2
    server mysql2 121.199.30.100:3306 weight 1  check inter 1s rise 2 fall 2
相关推荐
zxanz13 分钟前
SSL 证书有哪些类型,怎么选择适合自己使用的?
网络·网络协议·ssl
牢姐与蒯7 分钟前
Linux信号(二).信号产生续 && 信号保存
linux·运维·服务器·ubuntu
何中应9 分钟前
Jenkins 如何给设置公司 Logo
运维·ci/cd·jenkins
皓月盈江12 分钟前
WordPress博客迁移到Hexo静态博客教程
linux·服务器·hexo·wordpress·博客迁移·静态博客
Szime12 分钟前
项目结束后,剩余的电子元器件怎么处理?——从“库存滞留”到“资产盘活”的更高解法
运维·嵌入式硬件
中杯可乐多加冰13 分钟前
解决方案:CEB 文件 Web 端在线预览方案,Linux部署ceb文件在线预览工具
linux·运维·前端·ceb
troy12816 分钟前
从 JIRA 到监控:一条完整的 DevOps 交付流水线实战
运维·devops·jira
通信数码研究院17 分钟前
2026户外监控选什么?TOP5场景适配榜单:五类安装环境与产品选型参考
网络
何中应24 分钟前
Jenkins 如何配置工作节点
运维·ci/cd·jenkins
谢亮_vipxieliang24 分钟前
容器日志收集与管理:从 stdout 规范到 ELK/Loki 落地
运维·网络·人工智能·elk·docker·容器