rsyslog.conf 수정할 내용
해당 파일에 아래 내용 수정 및 추가하기
# syslog 수신 포트 설정
module(load="imudp") # 주석 제거하여 활성화
input(type="imudp" port="514") # 주석 제거하여 활성화
# syslog 수신 시 저장할 위치 및 파일 설정 템플릿
$template Remote,"/var/log/rsyslog/%fromhost-ip%/%$YEAR%-%$MONTH%-%$DAY%.log"
# syslog 수신 시 fromhost-ip가 127.0.0.1이 아닌 경우 템플릿 Remote 정책을 적용
:fromhost-ip, !isequal, "127.0.0.1" ?Remote
# 템플릿 Remote로 수신한 경우 로그 처리 중지
# 중지하지 않을 경우, OS에서 수집하는 syslog나 message에도 로그가 수집 됨 (중복 수집 됨)
& stop
rsyslog.conf 전체 내용 (수정할 로그의 위치 파악용)
[root@localhost ~]# cat /etc/rsyslog.conf
# 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
#### 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")
#### 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
# for parameters see http://www.rsyslog.com/doc/imudp.html
module(load="imudp") # needs to be done just once 주석제거하여 활성화
input(type="imudp" port="514") # 주석제거하여 활성화
# Provides TCP syslog reception
# for parameters see http://www.rsyslog.com/doc/imtcp.html
#module(load="imtcp") # needs to be done just once
#input(type="imtcp" port="514")
#### Template ###
$template Remote,"/var/log/rsyslog/%fromhost-ip%/%$YEAR%-%$MONTH%-%$DAY%.log"
#### RULES ####
# 로그가 Remote template을 거친 경우 여기서 로그 수집 중단
# 로그 수집이 중단되지 않을 경우 해당 경로 이후의 syslog 프로세스를 거침
# 일반적으로 syslog나 message 파일에 등록 되어 Remote template에도 등록이 되었기 때문에 중복 메시지가 됨.
:fromhost-ip, !isequal, "127.0.0.1" ?Remote
& stop
# 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")
'기술 노트 > rsyslog' 카테고리의 다른 글
rsyslog 서비스로 syslog 수신하기 (0) | 2023.02.15 |
---|