AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 790056
Accepted
BentCoder
BentCoder
Asked: 2016-07-16 06:10:31 +0800 CST2016-07-16 06:10:31 +0800 CST 2016-07-16 06:10:31 +0800 CST

合并 haproxy.cfg 中后端块的重复项

  • 772

我有这个 HAProxy 配置,如您所见,我在backends 中有很多重复的东西。有没有办法摆脱重复,例如stats?

global
    log 127.0.0.1 local0
    log 127.0.0.1 local1 notice
    daemon
    maxconn 2000

defaults
    log global
    mode http
    option httplog
    option dontlognull
    retries 3
    option redispatch
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms

frontend http-in
    bind *:80
    acl url_a path_reg ^\/a$|\/a\/
    use_backend webservers_a if url_a
    acl url_b path_reg ^\/b$|\/b\/
    use_backend webservers_b if url_b
    default_backend webservers_main

backend webservers_main
    mode http
    stats enable
    stats auth admin:admin
    stats uri /haproxy?stats
    balance roundrobin
    option httpchk
    option forwardfor
    option http-server-close
    server web1 192.168.50.21:80 maxconn 32 check

backend webservers_a
    mode http
    stats enable
    stats auth admin:admin
    stats uri /haproxy?stats
    balance roundrobin
    option httpchk
    option forwardfor
    option http-server-close
    server web2 192.168.50.22:80 maxconn 32 check

backend webservers_b
    mode http
    stats enable
    stats auth admin:admin
    stats uri /haproxy?stats
    balance roundrobin
    option httpchk
    option forwardfor
    option http-server-close
    server web3 192.168.50.23:80 maxconn 32 check
haproxy
  • 1 1 个回答
  • 935 Views

1 个回答

  • Voted
  1. Best Answer
    gxx
    2016-07-16T06:53:58+08:002016-07-16T06:53:58+08:00

    您可以在配置中添加如下内容:

    listen stats
        bind ${PRIVATE_IP}:${PORT}
        stats enable
        stats uri /stats
        stats auth admin:admin
    
    • 我假设以下几点:

    • 你不想把你的暴露stats给公众。如果不是这种情况,只需将您的统计数据移动到您现有的frontend指令中。

    • 替换${PRIVATE_IP}为您机器上可用的私有 IP(或为此设置一个),以及${PORT}未使用的端口,例如8080.

    • 警告:如果您使用与 stats 指令不同的端口80,则必须stats通过在url. 为了防止和规避:

      • frontend将您的to${PUBLIC_IP}:80和您的listen stats部分绑定到${PRIVATE_IP}:80.
    • 2

相关问题

  • 具有动态路由的代理服务器

  • nginx 访问日志忽略某些请求

  • HAProxy 和“分片”

  • 带有 HAProxy 的远程 IP

  • SSL 网站的高可用性

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve