haproxy不记录日志,这是啥子情况~,没碰到过,不懂~~
随机Google了一把,参照文章搞了搞,还是不行有木有~
Ps:网上多是关于syslog的文章~(道理是相通的,就是路不同,但就是走不通~)
看文档~
1.安装haproxy
1
2
3
4
|
[root@localhost vagrant]# yum install haproxy -y
[root@localhost vagrant]# rpm -qa | grep haproxy
haproxy-1.4.24-2.el6.x86_64
[root@localhost vagrant]#
|
2.设置rsyslog(6.x之后使用rsyslog取代了syslog)
-
rsyslog的特性:
1.后端存查日志支持的客户端多支持MySQL、PostgresSQL、Oracle 等 2.在同一台机器上支持多子rsyslog进程,可以监听在不同端口 3.直接兼容系统自带的syslog.conf配置文件 4.可将消息过来后再次转发 5.配置文件中可以写简单的逻辑判断 6.有现成的前端web展示程序等等。 另外和rsyslog功能差不多还有syslog-ng,但是syslog-ng免费版本是闭源。 |
-
修改rsyslog.conf文件
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@localhost vagrant]# sed -e '/^#/d;/^$/d;/^\*/d' /etc/rsyslog.conf
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imklog # provides kernel logging support (previously done by rklogd)
$ModLoad imudp
$UDPServerRun 514
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$IncludeConfig /etc/rsyslog.d/*.conf
authpriv.* /var/log/secure
mail.* -/var/log/maillog
cron.* /var/log/cron
uucp,news.crit /var/log/spooler
local7.* /var/log/boot.log
local2.* /var/log/haproxy.log
|
-
上文中修改了两行,添加了一行
-
修改的两行是:(取消注释)
1
2
|
$ModLoad imudp
$UDPServerRun 514
|
-
添加的一行是:(和haproxy中定义的log level要一致)
1
|
local2.* /var/log/haproxy.log
|
-
且看haproxy中定义的log level:
1
2
3
4
|
[root@localhost vagrant]# grep 'local*' /etc/haproxy/haproxy.cfg
# 2) configure local2 events to go to the /var/log/haproxy.log
# local2.* /var/log/haproxy.log
log 127.0.0.1 local2
|
-
重启rsyslog服务重新验证日志相关信息
1
2
3
4
5
|
[root@localhost vagrant]#
[root@localhost vagrant]# cat /var/log/haproxy.log
[root@localhost vagrant]# service rsyslog restart
Shutting down system logger: [ OK ]
Starting system logger: [ OK ]
|
-
重启haproxy(提示后端上游服务器没有开启)
1
2
3
4
5
6
7
8
9
10
11
|
[root@localhost vagrant]# cat /var/log/haproxy.log
Jun 7 09:46:23 localhost haproxy[2479]: Proxy main started.
Jun 7 09:46:23 localhost haproxy[2479]: Proxy static started.
Jun 7 09:46:23 localhost haproxy[2479]: Proxy app started.
Jun 7 09:46:23 localhost haproxy[2479]: Server static/static is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
Jun 7 09:46:23 localhost haproxy[2479]: backend static has no server available!
Jun 7 09:46:24 localhost haproxy[2480]: Server app/app1 is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 3 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
Jun 7 09:46:24 localhost haproxy[2480]: Server app/app2 is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 2 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
Jun 7 09:46:24 localhost haproxy[2480]: Server app/app3 is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 1 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
Jun 7 09:46:25 localhost haproxy[2480]: Server app/app4 is DOWN, reason: Layer4 connection problem, info: "Connection refused", check duration: 0ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
Jun 7 09:46:25 localhost haproxy[2480]: backend app has no server available!
|
Note:
如果你是自行编译安装haproxy的话,有时候可能会自定义日志文件在编译目录下面,但是rsyslog并没有读取该目录的权限,所以只能呵呵了~,不过办法总归是有的,就是折腾。。。
本文转自lovelace521 51CTO博客,原文链接:http://blog.51cto.com/lovelace/1423434,如需转载请自行联系原作者