Haproxy不logging请求?

所以,我configuration了Haproxy,所以日志logging将通过rsyslog进行处理,并且现在都被转储到一个文件中。

这是定义日志logging,因为我在启动时得到这些“启动”消息,但根本没有HTTP请求logging。 我的configuration有什么问题?

haproxy.cfg

global log /dev/log local0 debug chroot /var/lib/haproxy stats socket /run/haproxy/admin.sock mode 660 level admin 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 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 webfront option forwardfor stats enable stats uri /haproxy?statis stats realm Haproxy\ Auth stats auth user:password bind *:80 timeout client 86400000 acl is_discourse hdr_end(host) -i discourse.mydomain.com use_backend discourse if is_discourse use_backend webserver if !is_discourse backend discourse balance source option forwardfor option httpclose server server1 127.0.0.1:3080 weight 1 maxconn 1024 check inter 10000 backend webserver balance source option forwardfor option httpclose server server2 127.0.0.1:4080 weight 1 maxconn 1024 check inter 10000 

日志文件

 root@kayak:/var/log/haproxy# tail haproxy.log Nov 26 21:25:25 kayak haproxy[21646]: Proxy webfront started. Nov 26 21:25:25 kayak haproxy[21646]: Proxy webfront started. Nov 26 21:25:25 kayak haproxy[21646]: Proxy discourse started. Nov 26 21:25:25 kayak haproxy[21646]: Proxy webserver started. Nov 26 21:28:10 kayak haproxy[21868]: Proxy webfront started. Nov 26 21:28:10 kayak haproxy[21868]: Proxy discourse started. Nov 26 21:28:10 kayak haproxy[21868]: Proxy webserver started. Nov 26 21:30:31 kayak haproxy[22045]: Proxy webfront started. Nov 26 21:30:31 kayak haproxy[22045]: Proxy discourse started. Nov 26 21:30:31 kayak haproxy[22045]: Proxy webserver started. 

我访问了一些networking服务器页面,重新引导,并触发了几个404错误。 为什么没有显示出来?

编辑:rsyslog conf文件。

/etc/rsyslog.d/49-haproxy.conf:

 local0.* -/var/log/haproxy_0.log if ($programname == 'haproxy') then -/var/log/haproxy/haproxy.log & ~ 

如果您确实需要logging每个请求,则必须在前端指定日志。 但是通常这对于服务器来说是矫枉过正的,而且你的磁盘很快就会满了。

 frontend webfront log /dev/log local0 debug 

通过unix套接字日志logging不工作在我rhel 6.7.you可以试试这个conf。 haproxy(致力于81)转发http请求到httpd(工作在80)

/etc/haproxy/haproxy.cfg

 frontend web_front log 127.0.0.1 local6 option httplog bind *:81 default_backend web_back backend web_back server web1 127.0.0.1:80 

你必须启用rsyslog udp模块才能接收来自haproxy的系统日志,就像这样:

/etc/rsyslog.d/haproxy.conf

 $ModLoad imudp $UDPServerAddress 127.0.0.1 $UDPServerRun 514 local6.* /var/log/haproxy.log 

做一个http请求到81,你很好地得到这样的日志

 # tail -n 1 /var/log/haproxy.log May 18 13:51:07 localhost haproxy[31617]: 127.0.0.1:38074 [18/May/2016:13:51:06.999] web_front web_back/web1 0/0/0/2/2 404 466 - - ---- 1/1/0/1/0 0/0 "GET /how-are-you HTTP/1.1" 

这可能是由于在chroot监狱中运行造成的。 你需要确保rsyslog也在chroot jail中创build一个dgram套接字(例如/ var / lib / haproxy / dev / log)。 把你的日志指令指向/ dev / log套接字,你应该是好的。

我花了几个小时试图弄清楚这一点,因为除了日志logging失败以外,HAproxy不会告诉你任何错误。