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
相关推荐
xlq223228 分钟前
30.进程池IPC
linux·运维·服务器
Predestination王瀞潞21 分钟前
5.2.1 通信->DNS域名系统协议标准(IETF RFC 1035):DNS(Domain Name System)
网络·网络协议·tcp/ip
nuomigege22 分钟前
beagleboneblack刷入官方IOT镜像后无法运行nodered问题的处理
linux·运维·服务器
huaxiu51 小时前
ubuntu下应用打不开
linux·运维·ubuntu
帐篷Li1 小时前
【AgenticCPS 】CPS联盟返利系统 - 实施计划
大数据·网络·人工智能
m0_683124791 小时前
Ubuntu服务设置开机自启
linux·运维·ubuntu
落叶花开又一年1 小时前
检验检测机构资质认定远程评审工作程序
linux·运维·服务器
wanhengidc1 小时前
《三国志异闻录》搬砖新游戏 云手机
运维·服务器·数据库·游戏·智能手机
Fly Wine1 小时前
IPsec 最简单场景总部和网关之间建立,并且流量不会全部经过总部
网络
i建模1 小时前
通过命令行使用密钥登录远程SSH主机
运维·ssh