我正在运行 Ubuntu 18.04。我的配置文件和其他信息如下。我使用 apt-get 安装。
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats timeout 30s
user haproxy
group haproxy
daemon
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
frontend http_front
bind *:80
stats uri /haproxy?stats
default_backend http_back
backend http_back
balance roundrobin
server server1 ip:port check
server server2 ip:port check
我输入了 haproxy -f /etc/haproxy/haproxy.cfg -db 并收到了这个输出。
[ALERT] 359/031621 (6151) : parsing [/etc/haproxy/haproxy.cfg:2]: unknown keyword ‘log’ out of section.
[ALERT] 359/031621 (6151) : parsing [/etc/haproxy/haproxy.cfg:3]: unknown keyword ‘chroot’ out of section.
[ALERT] 359/031621 (6151) : parsing [/etc/haproxy/haproxy.cfg:4]: unknown keyword ‘stats’ out of section.
[ALERT] 359/031621 (6151) : parsing [/etc/haproxy/haproxy.cfg:5]: unknown keyword ‘user’ out of section.
[ALERT] 359/031621 (6151) : parsing [/etc/haproxy/haproxy.cfg:6]: unknown keyword ‘group’ out of section.
[ALERT] 359/031621 (6151) : parsing [/etc/haproxy/haproxy.cfg:7]: unknown keyword ‘daemon’ out of section.
[ALERT] 359/031621 (6151) : parsing [/etc/haproxy/haproxy.cfg:20] : unknown keyword ‘jstats’ in ‘frontend’ section
[ALERT] 359/031621 (6151) : Error(s) found in configuration file : /etc/haproxy/haproxy.cfg
[ALERT] 359/031621 (6151) : Fatal errors found in configuration.
我的 Haproxy 状态。
Dec 25 02:41:58 admin systemd[1]: haproxy.service: Scheduled restart job, restart counter is at 5.
Dec 25 02:41:58 admin systemd[1]: Stopped HAProxy Load Balancer.
Dec 25 02:41:58 admin systemd[1]: haproxy.service: Start request repeated too quickly.
Dec 25 02:41:58 admin systemd[1]: haproxy.service: Failed with result ‘exit-code’.
Dec 25 02:41:58 admin systemd[1]: Failed to start HAProxy Load Balancer.
答案1
从命令中得到的错误来看haproxy -f /etc/haproxy/haproxy.cfg -db
,问题在于您没有在文件的第一部分中设置配置部分。通过快速的 Google 搜索,该部分应该命名为 global。
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats timeout 30s
user haproxy
group haproxy
daemon
我认为你已经修复了最后一个配置错误
[ALERT] 359/031621 (6151) : parsing [/etc/haproxy/haproxy.cfg:20] : unknown keyword ‘jstats’ in ‘frontend’ section
stats
因为密钥看起来应该改为jstats