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
相关推荐
Menior_几秒前
[Linux] vim及gcc工具
linux·运维·vim
----云烟----14 分钟前
使用libUSB-win32的简单读写例程参考
网络
weixin_4738947722 分钟前
前端服务器部署分类总结
前端·网络·性能优化
不念霉运26 分钟前
2025年中国DevOps工具选型指南:主流平台能力横向对比
运维·ci/cd·团队开发·devops
HelloZheQ27 分钟前
MVCC:数据库并发控制的利器
服务器·数据库·oracle
珹洺39 分钟前
Jsp技术入门指南【十四】实现基于MySQL+JDBC+JSP数据库验证的登录界面与登录跳转功能
java·运维·数据库·mysql·servlet
OpenVINO生态社区43 分钟前
【美国将取消对能源之星支持 严重影响AI服务器】
服务器·人工智能·能源
珹洺1 小时前
计算机操作系统(七)详细讲解进程的组成与特性,状态与转换
运维·服务器·计算机网络
上海云盾-高防顾问1 小时前
SCDN如何有效防护网站免受CC攻击?——安全加速网络的实战解析
网络·安全
alden_ygq1 小时前
nginx 出现大量connect reset by peer
服务器·网络·nginx