운영체제
[linux] cron.d 설정으로 haproxy 로그 logrotate 적용
warpmemory
2023. 10. 20. 17:12
1분 주기로 haproxy 로그 확인해서 100M 넘으면 로테이트해서 500개 까지 보관(crontab 사용하지 않고, /etc/cron.d 설정)
mkdir /etc/logrotate.hourly
cat <<EOF > /etc/logrotate.hourly/haproxy
/var/log/haproxy/haproxy.log
/var/log/haproxy/haproxy-*.log {
hourly
missingok
nocompress
notifempty
size 100M
rotate 500
dateext
dateformat -%Y%m%d%H-%s
#copytruncate
postrotate
/usr/bin/pgrep rsyslogd | xargs -I{} kill -s HUP {}
endscript
}
EOF
mkdir /etc/cron.minutely
cat <<EOF > /etc/cron.minutely/0logrotate.hourly
/usr/sbin/logrotate /etc/logrotate.hourly/haproxy
EOF
chmod 750 /etc/cron.minutely/0logrotate.hourly
cat <<EOF > /etc/cron.d/0minutely
# Run the hourly jobs
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
* * * * * root run-parts /etc/cron.minutely
EOF
chmod 640 /etc/cron.d/0minutely