在運維etcd集群時硅堆,3.4版本可以制定--logger zap
(3.5是默認參數(shù)是zap)赁酝,然后通過--log-outputs 'etcd.log'
的方式輸出到制定文件敞嗡,但在3.3或在3.4使用非zap的logger時,--log-outputs
只支持default
/stdout
/stderr
等3種方式光涂。在使用systemd管理的情況下會輸出到journalctl
日杈。
那現(xiàn)在問題就是: 如何將systemd的日志輸出到制定文件遣铝。
在/usr/lib/systemd/system/etcd.service中增加如下3行:
StandardOutput=syslog # 主要是這3行
StandardError=syslog #
SyslogIdentifier=etcd #
在/etc/rsyslog.d/
目錄下增加配置文件,如etcd.conf
$vim /etc/rsyslog.d/etcd.conf
if $programname == 'etcd' then /data/etcd.log
& stop
新建/data/etcd.log文件莉擒,并修改文件歸屬到etcd用戶【應(yīng)該是syslog用戶酿炸,但我系統(tǒng)上沒這個用戶,暫時就用etcd涨冀,測試可以寫入】
重啟rsyslog和etcd
systemctl daemon-reload
systemctl restart etcd rsyslog
然后觀察對應(yīng)文件是否正常輸出填硕,如果不對,通過journalctl -f -u <promgramname>查看相關(guān)日志輸出鹿鳖。
如果幫到你扁眯,辛苦點贊鼓勵下吧!
遇到的問題:
我使用的系統(tǒng)版本是:Description: CentOS Linux release 7.6.1810 (Core)
systemd的版本:systemd 219
當配置如下:
if $programname == 'etcd' then /data/etcd.log
& stop
報錯如下:
invalid character in selector line - ';template' expected [v8.24.0-34.el7]
error during parsing file /etc/rsyslog.d/etcd.conf, on or before line 1: errors occured in file '/etc/rsyslog.d/etcd.conf' around line 1 [v8.24.0-34.el7 try http://www.rsyslog.com/e/2207 ]
根據(jù)他提供的bug地址栓辜,我架構(gòu)stop修改為stopp恋拍,結(jié)果新的報錯和提示如下:
action 'stopp' treated as ':omusrmsg:stopp' - please use ':omusrmsg:stopp' syntax instead, 'stopp' will not be supported in the future [v8.24.0-34.el7 try http://www.rsyslog.com/e/2184 ]
error during parsing file /etc/rsyslog.d/etcd.conf, on or before line 2: warnings occured in file '/etc/rsyslog.d/etcd.conf' around line 2 [v8.24.0-34.el7 try http://www.rsyslog.com/e/2207 ]
按照提示我們將stopp修改為':omusrmsg:stopp'
最終/etc/rsyslog.d/etcd.conf
內(nèi)容如下:
if $programname == 'etcd' then /data/etcd.log
& :omusrmsg:stopp