๋ค์ด๊ฐ๋ฉฐ
์๋น์ค ์ด์ ์ค์์
์ ์, ์๋ฌ๋ก๊ทธ
๋ฅผ ์ด๋ป๊ฒ ๊ด๋ฆฌํ ๊น? ๊ณ ๋ฏผ์ด ๋์๊ณ ์ฐพ์๋ณด๋logrotate
๋ฅผ ์๊ฒ ๋์ด ์ ๋ฆฌํ๊ธฐ ์ํด ์์ฑํฉ๋๋ค.
How to install?
sudo yum install -y logrotate
logrotate
์ค์ ์ ์ด๋ป๊ฒ ํ ๊น?
/etc/logrotate.conf
๋ฅผ ํตํด ์ค์ ํ ์ ์๋ค.- logrotate์ ๊ธฐ๋ณธ ์ค์ ํ์ผ
๊ทธ๋ผ ์ถ๊ฐ/๋ณ๊ฒฝ์ ์ด๋์ ํ ๊น?
logrotate.d
์ ์ํ๋ ์ค์ ํ์ผ์ ์ถ๊ฐ/๋ณ๊ฒฝํ ์ ์์ต๋๋ค.
logrotate.d
|-- dracut
|-- nginx
|-- psacct
|-- syslog
`-- yum
Example - nginx logrotate ํ์ผ
/var/log/nginx/*log {
create 0664 nginx root # [๊ถํ ์ ์ ๊ทธ๋ฃน]์ผ๋ก rotation๋ ๋ก๊ทธํ์ผ ์์ฑ
daily # ๋ฐฑ์
์ฃผ๊ธฐ daily, weekly, monthly, yearly
rotate 10 # ์ต๋ ๋ก๊ทธ ํ์ผ ๊ฐ์
missingok # ๋ก๊ทธ ํ์ผ์ด ์กด์ฌํ์ง ์์๋ ์๋ฌ๋ฐ์ X
notifempty # ๋ก๊ทธ๊ฐ ๋น์ด์๋ค๋ฉด ๋กํ
์ดํธ ์งํ X
compress # gzip์ผ๋ก ์์ถ
sharedscripts # ๋ก๊ทธํ์ผ์ด ์ฌ๋ฌ๊ฐ ์์ด๋ ์คํฌ๋ฆฝํธ๋ฅผ ๊ณต์ ํ์ฌ prerotate, postrotate ์คํฌ๋ฆฝํธ๋ฅผ ํ๋ฒ๋ง ์คํ
postrotate # ์คํ ํ ์คํธ๋ฆฝํธ ํ์ผ ์คํ
/etc/init.d/nginx reopen_logs
endscript
}
logrotate ์ํ ํ์ผ ํ์ธํ๊ธฐ
/var/lib/logrotate.status
์ ๊ธฐ๋กํ์ฌ cron์ผ๋ก logrotate๋ ๋์ํฉ๋๋ค.
# cat /var/lib/logrotate.status
# logrotate.status #
logrotate state -- version 2
"/var/log/nginx/error.log" 2019-8-16