linux中haproxy日誌配置的詳解

來源:互聯網
上載者:User

haproxy在預設情況不會記錄日誌,除了在haproxy.conf中的global段指定日誌的輸出外,還需要配置系統日誌的設定檔。下面以centos6.4為例,haproxy使用系統內建的rpm報1.4版本

1、vim /etc/haproxy/haproxy.conf

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

2、編輯系統日誌配置

vim /etc/rsyslog.conf

預設有下面的設定,會讀取 /etc/rsyslog.d/*.conf目錄下的設定檔

$IncludeConfig /etc/rsyslog.d/*.conf
為haproxy建立一個獨立的設定檔

vim  /etc/rsyslog.d/haproxy.conf
$ModLoad imudp
$UDPServerRun 514
local3.*     /var/log/haproxy.log
aproxy.log中寫入日誌外,也會寫入message檔案
&~

3、配置rsyslog的主設定檔,開啟遠程日誌

vim /etc/sysconfig/rsyslog
SYSLOGD_OPTIONS=”-c 2 -r -m 0″
#-c 2 使用相容模式,預設是 -c 5
#-r 開啟遠程日誌
#-m 0 標記時間戳記。單位是分鐘,為0時,表示禁用該功能

配置完成後重啟haproxy和rsyslog服務

/etc/init.d/rsyslog restart
/etc/init.d/haproxy restart

4、在紅帽5上配置系統日誌與紅帽6不同,紅帽5的/etc/rsyslog.conf 不包含/etc/rsyslog.d/*.conf,配置如下

#加入haproxy.none表示不把haproxy日誌寫入message
*.info;mail.none;authpriv.none;cron.none;haproxynone                /var/log/messages
local3.*        /var/log/haproxy.log

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.