我尝试了多个有关启用 HAProxy 统计信息的网络教程(只需谷歌搜索 haproxy 统计信息并尝试前 10 个链接),但我相信这些适用于较旧的 HAProxy 版本。我在 Ubuntu 16.04 LTS 上运行 1.7。
这是我的 /etc/haproxy/haproxy.cfg 文件(其中包括 Datadog 提供的有关启用统计数据的说明)。
如果我删除 listen.... 块,它就可以正常启动。当它在那里时,我收到以下错误:
sudo service haproxy stop
sudo service haproxy start
Job for haproxy.service failed because the control process exited with error code. See "systemctl status haproxy.service" and "journalctl -xe" for details.
journalctl 和 systemctl 输出都显示“服务启动太快错误
haproxy.service - HAProxy Load Balancer
Loaded: loaded (/lib/systemd/system/haproxy.service; enabled; vendor preset: enabled)
Active: inactive (dead) (Result: exit-code) since Sun 2016-07-31 11:24:06 BST; 1min 19s ago
Docs: man:haproxy(1)
file:/usr/share/doc/haproxy/configuration.txt.gz
Process: 1969 ExecReload=/bin/kill -USR2 $MAINPID (code=exited, status=0/SUCCESS)
Process: 2388 ExecReload=/usr/sbin/haproxy -c -f ${CONFIG} (code=exited, status=1/FAILURE)
Process: 2973 ExecStart=/usr/sbin/haproxy-systemd-wrapper -f ${CONFIG} -p /run/haproxy.pid $EXTRAOPTS (code=exited, status=0/SUCCESS)
Process: 3511 ExecStartPre=/usr/sbin/haproxy -f ${CONFIG} -c -q (code=exited, status=1/FAILURE)
Main PID: 2973 (code=exited, status=0/SUCCESS)
Jul 31 11:24:06 loadbalancervm-VirtualBox systemd[1]: haproxy.service: Control process exited, code=exited status=1
Jul 31 11:24:06 loadbalancervm-VirtualBox systemd[1]: Failed to start HAProxy Load Balancer.
Jul 31 11:24:06 loadbalancervm-VirtualBox systemd[1]: haproxy.service: Unit entered failed state.
Jul 31 11:24:06 loadbalancervm-VirtualBox systemd[1]: haproxy.service: Failed with result 'exit-code'.
Jul 31 11:24:06 loadbalancervm-VirtualBox systemd[1]: haproxy.service: Service hold-off time over, scheduling restart.
Jul 31 11:24:06 loadbalancervm-VirtualBox systemd[1]: Stopped HAProxy Load Balancer.
Jul 31 11:24:06 loadbalancervm-VirtualBox systemd[1]: haproxy.service: Start request repeated too quickly.
Jul 31 11:24:06 loadbalancervm-VirtualBox systemd[1]: Failed to start HAProxy Load Balancer.
haproxy.cfg文件
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
user haproxy
group haproxy
daemon
# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL). This list is from:
# https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
ssl-default-bind-options no-sslv3
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
frontend LOAD_BALANCER_TIER
bind *:80
default_backend WEB_SERVER_TIER
backend WEB_SERVER_TIER
balance roundrobin
mode http
server WebServer1 192.168.1.9:80 check
server WebServer2 192.168.1.11:80 check
listen stats :9000
mode http
stats enable
stats hide-version
stats realm HAproxy-Statistics
stats uri /haproxy_stats
stats auth admin:password
注意所有缩进行都使用制表符,而不是空格。项目之间使用空格。
有任何想法吗?
答案1
您对旧版本的看法是正确的。自从 HAProxy 1.5 中删除以来,绑定到代理(frontend
或)声明开始的那一行上的端口就不再有效。listen
这是正确的形式:
listen stats
bind :9000
请注意,您已经在frontend
声明中这样做了。Alisten
本质上是前端和后端的组合。