目次

52.ログ管理-rsyslog

RainerScriptの書式で書かないと怒られる場合がある。
https://www.rsyslog.com/doc/v8-stable/index.html

rsyslog設定

1
2
3
4
5
6
7
8
#変更
vi /etc/rsyslog.conf
 
#文法確認
rsyslogd -N 1
 
#適用
systemctl restart rsyslog

MODULES

SysSockのRateLimitは、デフォルトで0になっている
https://www.rsyslog.com/doc/v8-stable/configuration/modules/imuxsock.html?#syssock-ratelimit-interval
imjournalのRatelimit.Intervalは、デフォルトで600なので、これを0とする。
https://www.rsyslog.com/doc/v8-stable/configuration/modules/imjournal.html#ratelimit-interval

・syslog集約サーバとする場合は、下記項目も考慮する。

パラメータ 説明
$ModLoad imudp #UDPでログを受け取る場合に記載(有効)する
$UDPServerRun #UDPでログを受け取るポート番号
$ModLoad imtcp #TCPでログを受け取る場合に記載(有効)する
$InputTCPServerRun #TCPでログを受け取るポート番号

GLOBAL DIRECTIVES

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#新規ファイルのデフォルトのパーミッション
$umask 0000
 
#rsyslogディレクトリ、ファイルのデフォルトパーミッション指定
$DirCreateMode 0755
$FileCreateMode 0644
 
# Use default timestamp format
module(load="builtin:omfile" Template="RSYSLOG_TraditionalFileFormat")   #変更前
module(load="builtin:omfile" Template="RSYSLOG_FileFormat")              #変更後
 
#RateLimit機能の値を0(無効)にする。
$imjournalRatelimitInterval 0
 
#xfsの場合に非同期書き込みデータがディスクにライトバックされる時間間隔が長くなるので、その対策
$ActionFileEnableSync on
$OMFileAsyncWriting on
$OMFileFlushInterval 5
$OMFileIOBufferSize 1024

RULES

特別な要件がない限り初期値から変更しなくて良い。
/var/log/boot.logが出力されないのはなんでだろう・・・。
※理由と対策が判明した、必要に応じて実施dmesgコマンドで良いという方は不要
インフラ構築/RHEL8/90.ナレッジ#RHEL8でvarlogbootlogが記録されない理由

https://milestone-of-se.nesuke.com/l7protocol/syslog/rsyslog-summary/
https://www.server-world.info/query?os=CentOS_8&p=rsyslog&f=1
https://knowledge.sakura.ad.jp/8969/
https://densan-hoshigumi.com/server/centos-logging
https://straypenguin.winfield-net.com/index.html
https://knowledge4linux.blogspot.com/2014/01/rsyslog-dircreatemodefilecreatemode.html

/var/log/配下のパーミッションを統一する

1
2
3
4
5
#ディレクトリパス配下のディレクトリを再帰的に755へ変更(btmpとwtmpは個別でパーミッションが指定されているため除外)
find /var/log/ -type d -not -name "*wtmp*" -not -name "*btmp*" -exec chmod 755 {} +
  
#ディレクトリパス配下のファイルを再帰的に644へ変更(btmpとwtmpは個別でパーミッションが指定されているため除外)
find /var/log/ -type f -not -name "*wtmp*" -not -name "*btmp*" -exec chmod 644 {} +

初期値

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# rsyslog configuration file
 
# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html
# or latest version online at http://www.rsyslog.com/doc/rsyslog_conf.html
# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html
 
#### MODULES ####
 
module(load="imuxsock"    # provides support for local system logging (e.g. via logger command)
       SysSock.Use="off") # Turn off message reception via local log socket;
                          # local messages are retrieved through imjournal now.
module(load="imjournal"             # provides access to the systemd journal
       StateFile="imjournal.state") # File to store the position in the journal
#module(load="imklog") # reads kernel messages (the same are read from journald)
#module(load="immark") # provides --MARK-- message capability
 
# Provides UDP syslog reception
#module(load="imudp") # needs to be done just once
#input(type="imudp" port="514")
 
# Provides TCP syslog reception
#module(load="imtcp") # needs to be done just once
#input(type="imtcp" port="514")
 
#### GLOBAL DIRECTIVES ####
 
# Where to place auxiliary files
global(workDirectory="/var/lib/rsyslog")
 
# Use default timestamp format
module(load="builtin:omfile" Template="RSYSLOG_TraditionalFileFormat")
 
# Include all config files in /etc/rsyslog.d/
include(file="/etc/rsyslog.d/*.conf" mode="optional")
 
#### RULES ####
 
# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.*                                                 /dev/console
 
# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none                /var/log/messages
 
# The authpriv file has restricted access.
authpriv.*                                              /var/log/secure
 
# Log all the mail messages in one place.
mail.*                                                  -/var/log/maillog
 
 
# Log cron stuff
cron.*                                                  /var/log/cron
 
# Everybody gets emergency messages
*.emerg                                                 :omusrmsg:*
 
# Save news errors of level crit and higher in a special file.
uucp,news.crit                                          /var/log/spooler
 
# Save boot messages also to boot.log
local7.*                                                /var/log/boot.log
 
 
# ### sample forwarding rule ###
#action(type="omfwd"
# An on-disk queue is created for this action. If the remote host is
# down, messages are spooled to disk and sent when it is up again.
#queue.filename="fwdRule1"       # unique name prefix for spool files
#queue.maxdiskspace="1g"         # 1gb space limit (use as much as possible)
#queue.saveonshutdown="on"       # save messages to disk on shutdown
#queue.type="LinkedList"         # run asynchronously
#action.resumeRetryCount="-1"    # infinite retries if host is down
# Remote Logging (we use TCP for reliable delivery)
# remote_host is: name/ip, e.g. 192.168.0.1, port optional e.g. 10514
#Target="remote_host" Port="XXX" Protocol="tcp")