Haproxy在Freebsd下不能记录日志的问题

这几天给蹦心(bengxin.com) 开发环境配置haproxy,遇到的这个问题困扰了我一个晚上,google和baidu了N次也没有找到解决办法,最后自己通读了syslogd和syslog.conf以及haproxy的log相关的man pages,经过若干次的syslogd -d (debug) ,终于在debug日志里面发现了端倪,有这么一个东西导致了日志不能正确的记录到haproxy指定的日志文件里面:

validate: dgram from IP 127.0.0.1, port 49336, name localhost.bengxin.com;
rejected in rule 0 due to port mismatch.
rejected in rule 1 due to port mismatch.
rejected in rule 2 due to port mismatch.

于是给syslogd启动参数加入了下面的内容:

-a 127.0.0.1/32:* -a localhost:* -a 192.168.222.0/16:*

于是乎,期待了很久的haproxy日志出现了!

dev# tail -f /var/log/haproxy/haproxy_3.log
Aug 22 15:32:06 localhost haproxy[64136]: Proxy www started.
Aug 22 15:32:06 localhost haproxy[64136]: Proxy cherokee started.
Aug 22 15:32:06 localhost haproxy[64136]: Proxy wap started.
Aug 22 15:32:06 localhost haproxy[64136]: Proxy pic started.
Aug 22 15:32:06 localhost haproxy[64136]: Proxy img started.
Aug 22 15:32:06 localhost haproxy[64136]: Proxy public started.
Aug 22 15:32:06 localhost haproxy[64136]: Proxy public started.
Aug 22 15:32:59 localhost haproxy[64137]: 219.142.128.30:6416 [22/Aug/2009:15:32:59.754] public stats/ 0/-1/-1/-1/0 200 17329 – – PR– 0/0/0/0/0 0/0 “GET /?stats HTTP/1.1”
Aug 22 15:32:59 localhost haproxy[64137]: 219.142.128.30:6416 [22/Aug/2009:15:32:59.754] public stats/ 0/-1/-1/-1/0 200 17329 – – PR– 0/0/0/0/0 0/0 “GET /?stats HTTP/1.1”

我的haproxy和日志相关的配置部分如下:



log global
mode http
option httplog
option dontlognull
log 127.0.0.1 local3

还有部分非常关键的东西需要注意,首先是syslog.conf里面必须使用作为分隔符,貌似空格就有问题,然后是需要写成下面的这个格式:

!*
local0.* /var/log/haproxy/haproxy_0.log

最后这一点要感谢bsd社区上的一个老外给我的帮助,回复maillist真是够迅速的!

finally,BS很多国外站点被封,查资料那叫一个不方便!!!!

以上内容,绝对是目前的终极可行的解决方案,查不到第二个!

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
8 Responses
  1. 金融危机的影响 says:

    自己动手 丰衣足食。。 很多时候XX知道的东西 答案都很多水分的

  2. Michael says:

    [Comment ID #31684 Will Be Quoted Here]

    没错,官方文档+源码最靠谱! 不过有些时候,他人的经验还是不错的。

  3. 减肥方法 says:

    看你博客写的都很专业的 一定很厉害

  4. 百度优化 says:

    确实好专业 天天来拜读了

  5. 英语翻译器 says:

    讲的好啊

  6. 土匪头 says:

    NB!

  7. test says:

    请问下,你这个参数加载那个文件里面,-a 127.0.0.1/32:* -a localhost:* -a 192.168.222.0/16:* 是加入到syslogd这个文件中么?麻烦指点下,谢谢!

  8. Michael says:

    自己动手 丰衣足食。。很多时候XX知道的东西 答案都很多水分的

    这个参数加到 /etc/rc.conf里面,类似下面的

    syslogd_flags=”-a localhost:* -a 127.0.0.1/32:* -a 192.168.222.0/16:*”

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image