반응형
CentOS 6에서 rsyslog 데몬 설정 및 로그 정책 변경(rsyslogd)
1. /etc/rsyslog.conf 주요 설정
기본 설정 파일은 /etc/rsyslog.conf에 위치합니다.
모듈 로딩 섹션
#### MODULES ####
$ModLoad imuxsock.so # 로컬 소켓 지원 (logger 명령어 등)
$ModLoad imklog.so # 커널 메시지 수집
#$ModLoad immark.so # --MARK-- 메시지 주기 출력 (비활성화됨)
- immark.so는 시스템 상태 표시용 주기 메시지 기능이지만 일반적으로 사용하지 않으므로 주석 처리되어 있습니다.
네트워크 수신
# UDP 수신 활성화 (비활성화됨)
#$ModLoad imudp.so
#$UDPServerRun 514
# TCP 수신 활성화 (비활성화됨)
#$ModLoad imtcp.so
#$InputTCPServerRun 514
- 외부 서버에서 로그 수신을 구성하려면 위 항목의 주석을 해제하고 포트 허용합니다.
로그 저장 규칙
*.info;mail.none;authpriv.none;cron.none /var/log/messages
authpriv.* /var/log/secure
mail.* -/var/log/maillog
cron.* /var/log/cron
*.emerg *
uucp,news.crit /var/log/spooler
local7.* /var/log/boot.log
원격 로그 포워딩 설정(비활성화됨)
# ### begin forwarding rule ###
#$WorkDirectory /var/spool/rsyslog
#$ActionQueueFileName fwdRule1
#$ActionQueueMaxDiskSpace 1g
#$ActionQueueSaveOnShutdown on
#$ActionQueueType LinkedList
#$ActionResumeRetryCount -1
#*.* @@remote-host:514
# ### end of the forwarding rule ###
더보기
---
cat /etc/rsyslog.conf
#rsyslog v3 config file
# if you experience problems, check
# http://www.rsyslog.com/troubleshoot for assistance
#### MODULES ####
$ModLoad imuxsock.so # provides support for local system logging (e.g. via logger command)
$ModLoad imklog.so # provides kernel logging support (previously done by rklogd)
#$ModLoad immark.so # provides --MARK-- message capability
# Provides UDP syslog reception
#$ModLoad imudp.so
#$UDPServerRun 514
# Provides TCP syslog reception
#$ModLoad imtcp.so
#$InputTCPServerRun 514
#### GLOBAL DIRECTIVES ####
# Use default timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
# File syncing capability is disabled by default. This feature is usually not required,
# not useful and an extreme performance hit
#$ActionFileEnableSync on
#### 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 *
# 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
# ### begin forwarding rule ###
# The statement between the begin ... end define a SINGLE forwarding
# rule. They belong together, do NOT split them. If you create multiple
# forwarding rules, duplicate the whole block!
# Remote Logging (we use TCP for reliable delivery)
#
# 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.
#$WorkDirectory /var/spppl/rsyslog # where to place spool files
#$ActionQueueFileName fwdRule1 # unique name prefix for spool files
#$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible)
#$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
#$ActionQueueType LinkedList # run asynchronously
#$ActionResumeRetryCount -1 # infinite retries if host is down
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
#*.* @@remote-host:514
# ### end of the forwarding rule ###
---
728x90
2. 로그 순환 설정
logrotate를 통해 주기적으로 로그 파일을 순환(rotate)할 수 있습니다.
vim /etc/logrotate.d/syslog
/var/log/cron
/var/log/maillog
/var/log/messages
/var/log/secure
/var/log/spooler
{
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/syslogd.pid 2>/dev/null` 2>/dev/null || true
endscript
}
- postrotate는 로그 순환 후 rsyslogd 데몬에 HUP 시그널을 보내 설정을 반영합니다.
3. rsyslog 데몬 옵션
vim /etc/sysconfig/rsyslog
# Options to syslogd
# syslogd options are deprecated since rsyslog v3
# if you want to use them, switch to compatibility mode 2 by "-c 2"
SYSLOGD_OPTIONS="-c 4"
- -c 4는 rsyslog v3 호환 모드를 의미합니다. 이는 CentOS 6.x 기본 설정이며, 버전에 따라 다를 수 있습니다.
4. 설정 적용 방법
서비스 재시작
service rsyslog restart
데몬 상태 확인
service rsyslog status
로그 확인
tail -f /var/log/messages
반응형
'리눅스' 카테고리의 다른 글
[리눅스] MySQL 스키마 백업 및 복원 (0) | 2013.06.21 |
---|---|
리눅스 Bonding 모드 (1) | 2013.06.20 |
CentOS 6.2 에서 dkms를 설치하는 방법 (0) | 2013.06.20 |
cronolog를 컴파일하여 설치하고 Apache에 로그를 설정하는 방법 (0) | 2013.06.20 |
[리눅스] 우분투에서 PHP-FPM 최신(php-fpm 8.1) 버전 설치하기 (1) | 2013.06.20 |