haproxy軟件的日志如何輸出到指定文件
haproxy軟件日志輸出到指定文件
默認(rèn)haproxy的日志是輸出到系統(tǒng)syslog中,查看起來不是非常方便,為了更好的管理haproxy的日志,我們?cè)谏a(chǎn)環(huán)境中一般單獨(dú)定義出來。需要將haproxy的info及notice日志分別記錄到不同的日志文件中。
需要修改rsyslog配置,為了便于管理。
將haproxy相關(guān)的配置獨(dú)立定義到haproxy.conf,并放到/etc/rsyslog.d/下,rsyslog啟動(dòng)時(shí)會(huì)自動(dòng)加載此目錄下的所有配置文件。
默認(rèn)的haproxy的配置文件
如下
#--------------------------------------------------------------------- # Example configuration for a possible web application. See the # full configuration options online. # # http://haproxy.1wt.eu/download/1.4/doc/configuration.txt # #--------------------------------------------------------------------- #--------------------------------------------------------------------- # Global settings #--------------------------------------------------------------------- global # to have these messages end up in /var/log/haproxy.log you will # need to: # # 1) configure syslog to accept network log events. This is done # by adding the '-r' option to the SYSLOGD_OPTIONS in # /etc/sysconfig/syslog # # 2) configure local2 events to go to the /var/log/haproxy.log # file. A line like the following can be added to # /etc/sysconfig/syslog # # local2.* /var/log/haproxy.log # log 127.0.0.1 local2 info chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 40000 user haproxy group haproxy daemon # turn on stats unix socket stats socket /var/lib/haproxy/stats #--------------------------------------------------------------------- # common defaults that all the 'listen' and 'backend' sections will # use if not designated in their block #--------------------------------------------------------------------- defaults mode http log global option httplog option dontlognull option http-server-close option forwardfor except 127.0.0.0/8 option redispatch retries 3 timeout http-request 10s timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout http-keep-alive 10s timeout check 10s maxconn 3000 #--------------------------------------------------------------------- # main frontend which proxys to the backends #--------------------------------------------------------------------- #frontend main *:5000 # acl url_static path_beg -i /static /images /javascript /stylesheets # acl url_static path_end -i .jpg .gif .png .css .js # # use_backend static if url_static # default_backend app #--------------------------------------------------------------------- # static backend for serving up images, stylesheets and such #--------------------------------------------------------------------- #backend static # balance roundrobin # server static 127.0.0.1:4331 check #--------------------------------------------------------------------- # round robin balancing between the various backends #--------------------------------------------------------------------- #backend app # balance roundrobin # server app1 127.0.0.1:5001 check # server app2 127.0.0.1:5002 check # server app3 127.0.0.1:5003 check # server app4 127.0.0.1:5004 check
其中日志的配置文件有關(guān)日志的配置是 log 127.0.0.1 local2 info
為了便于管理將haproxy相關(guān)的配置獨(dú)立定義到haproxy.conf
配置方式
1.編輯“/etc/sysconfig/rsyslog”文件
將如下配置增加 -r 參數(shù):
SYSLOGD_OPTIONS="" 改成 SYSLOGD_OPTIONS="-r"
2.編輯“/etc/rsyslog.conf”取消紅框部分內(nèi)容的注釋
并在“local7.*”前面插入一行:
local2.* /var/log/haproxy/haproxy.log
3.重啟服務(wù)
重啟 rsyslog
systemctl restart rsyslog
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
LuManager VPS主機(jī)控制面板安裝和Eduvps免費(fèi)VPS測(cè)評(píng)
這篇文章主要介紹了LuManager VPS主機(jī)控制面板安裝和Eduvps免費(fèi)VPS測(cè)評(píng),需要的朋友可以參考下2016-04-04Linux之如何設(shè)置CPU Performance模式
這篇文章主要介紹了Linux之如何設(shè)置CPU Performance模式問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06關(guān)于linux下core dump【總結(jié)】
下面小編就為大家?guī)硪黄P(guān)于linux下core dump【總結(jié)】。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-01-01ubuntu 16.04系統(tǒng)完美解決pip不能升級(jí)的問題
這篇文章主要介紹了ubuntu 16.04系統(tǒng)完美解決pip不能升級(jí)的問題 ,本文圖文并茂給大家介紹的非常詳細(xì),需要的朋友可以參考下2018-04-04Apache之AllowOverride參數(shù)使用說明
通常利用Apache的rewrite模塊對(duì) URL 進(jìn)行重寫的時(shí)候, rewrite規(guī)則會(huì)寫在 .htaccess 文件里。但要使 apache 能夠正常的讀取.htaccess 文件的內(nèi)容,就必須對(duì).htaccess 所在目錄進(jìn)行配置。2011-01-01linux讓程序開機(jī)自動(dòng)運(yùn)行最簡單的方法
在本篇文章里小編給大家整理的是一篇關(guān)于linux讓程序開機(jī)自動(dòng)運(yùn)行最簡單的方法以及相關(guān)代碼,需要的朋友們學(xué)習(xí)下。2019-11-11