淡若春风 發表於 2023-7-7 00:00:00

haproxy日志配置 + rsyslog

<span class="abstract"><fieldset>
<legend>摘要</legend>
<p>haproxy在默认情况不会记录日志,除了在haproxy.conf中的global段指定日志的输出外,还需要配置系统日志的配置文件。下面以centos6.4为例,haproxy使用系统自带的rpm报1.4版本</p>
<div class="clear"></div>
</fieldset></span>
                                                       
       
                                <p>haproxy在默认情况不会记录日志,除了在haproxy.conf中的global段指定日志的输出外,还需要配置系统日志的配置文件。下面以centos6.4为例,haproxy使用系统自带的rpm报1.4版本<br><span id="more-1360"></span></p>
<h3>编辑/etc/haproxy/haproxy.conf</h3>
<p></p><pre class="brush:bash;toolbar:false">global
 log 127.0.0.1 local3    
#local3是设备,对应于 /etc/rsyslog.conf中的配置,默认回收info的日志级别
 maxconn 1024
 user haproxy
 group haproxy
 daemon
 pidfile /var/run/haproxy.pid
defaults
 mode http
 log global
 option httplog
 option dontlognull
 option http-server-close
 option forwardfor except 127.0.0.0/8
 retries 2
 option redispatch
 maxconn 1024</pre><p></p>
<h3>编辑系统日志配置</h3>
<p></p><pre class="brush:bash;toolbar:false"># vim /etc/rsyslog.conf
默认有下面的设置,会读取 /etc/rsyslog.d/*.conf目录下的配置文件
$IncludeConfig /etc/rsyslog.d/*.conf</pre><p>为haproxy创建一个独立的配置文件</p><pre class="brush:bash;toolbar:false"># vim  /etc/rsyslog.d/haproxy.conf
$ModLoad imudp
$UDPServerRun 514
local3.*     /var/log/haproxy.log
#如果不加下面的的配置则除了在/var/log/haproxy.log中写入日志外,也会写入message文件
&amp;~</pre><p></p>
<h3>配置rsyslog的主配置文件,开启远程日志</h3>
<p></p><pre class="brush:bash;toolbar:false"># vim /etc/sysconfig/rsyslog
SYSLOGD_OPTIONS=”-c 2 -r -m 0″
#-c 2 使用兼容模式,默认是 -c 5
#-r 开启远程日志
#-m 0 标记时间戳。单位是分钟,为0时,表示禁用该功能</pre><p></p><pre class="brush:bash;toolbar:false"></pre><p></p>
<h3>重启haproxy和rsyslog服务</h3>
<p></p><pre class="brush:bash;toolbar:false">#/etc/init.d/rsyslog restart
#/etc/init.d/haproxy restart</pre><p>转自:http://www.zhengdazhi.com/archives/1360</p>
頁: [1]
查看完整版本: haproxy日志配置 + rsyslog