실습> logrotate 실행하기
man logrotate
사용법 :
logrotate [-dv] [-f|--force] [-s|--state file] config_file ..
-f --force : 강제순환
-s --state statefile : 상태를 저장할 파일을 지정
# vi /etc/logrotate.conf
-- /etc/logrotate.conf --
# see "man logrotate" for details
# rotate log files weekly
weekly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# use date as a suffix of the rotated file
dateext
# uncomment this if you want your log files compressed
compress
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
monthly
#create 0664 root utmp
create 0600 root utmp
minsize 1M
#rotate 1
rotate 4
}
/var/log/btmp {
missingok
monthly
create 0600 root utmp
#rotate 1
rotate 4
}
-- /etc/logrotate.conf --
# date
2022. 03. 04. (금) 21:21:29 KST
# logrotate -s logroteStatus.txt /etc/logrotate.conf
# cat logroteStatus.txt
logrotate state -- version 2
"/var/log/yum.log" 2022-3-4-21:0:0
"/var/log/firewalld" 2022-3-4-21:0:0
"/var/log/boot.log" 2022-3-4-21:0:0
"/var/log/wtmp" 2022-3-4-21:0:0
"/var/log/chrony/*.log" 2022-3-4-21:0:0
"/var/log/spooler" 2022-3-4-21:0:0
"/var/log/btmp" 2022-3-4-21:0:0
"/var/log/maillog" 2022-3-4-21:0:0
"/var/log/wpa_supplicant.log" 2022-3-4-21:0:0
"/var/log/secure" 2022-3-4-21:0:0
"/var/log/messages" 2022-3-4-21:0:0
"/var/log/cron" 2022-3-4-21:0:0
# ls -l /etc/cron.daily/
합계 8
-rwx------. 1 root root 219 4월 1 2020 logrotate
-rwxr-xr-x. 1 root root 618 10월 30 2018 man-db.cron
# cat /etc/cron.daily/logrotate
#!/bin/sh
/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
# ls /var/log
a.c boot.log cron grubby_prune_debug maillog secure tuned
anaconda btmp dmesg httpd messages spooler wtmp
audit chrony firewalld lastlog rhsm tallylog yum.log
강제로 logrotate 를 실행해서 로그가 순환되는 것을 확인한다.
# logrotate -f -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf
# ls /var/log
a.c chrony httpd secure wtmp-20220304
anaconda cron lastlog secure-20220304 yum.log
audit cron-20220304 maillog spooler yum.log-20220304
boot.log dmesg maillog-20220304 spooler-20220304
boot.log-20220304 firewalld messages tallylog
btmp firewalld-20220304 messages-20220304 tuned
btmp-20220304 grubby_prune_debug rhsm wtmp
# ls -l /var/log/wtmp*
-rw-rw-r--. 1 root utmp 0 3월 4 21:35 /var/log/wtmp
-rw-rw-r--. 1 root utmp 4608 3월 4 20:48 /var/log/wtmp-20220304
'Linux > 보안장비 운용' 카테고리의 다른 글
| 웹서버 로그 분석 툴 goaccess 설치하기 (0) | 2022.03.08 |
|---|---|
| logger 사용하기 (0) | 2022.03.04 |
| 로그 관리 프로그램 logrotate (0) | 2022.03.04 |
| 원격 로그 서버 구축하기 (0) | 2022.03.04 |
| 장치에 로그 출력하기 (0) | 2022.03.04 |