Logrotate

Linux log๋ฅผ ๊ด€๋ฆฌํ•ด์š”

References: man7.org, network.com, server-talk.tistory.com

https://byd0105.tistory.com/29

What is Logrotate?

  • Linux server์˜ log๋ฅผ ๊ด€๋ฆฌํ•˜๋„๋ก ์„ค์ •ํ•˜๋Š” ๊ธฐ๋Šฅ

  • ๋ณดํ†ต ๊ธฐ๋ณธ์ ์œผ๋กœ ์„ค์น˜๋˜์–ด ์žˆ๋‹ค

    • ์„ค์น˜ ํ™•์ธ

      $ rpm -qa | grep logrotate
      logrotate-3.8.6-17.el7.x86_64
  • logrotate ๋Š” log ํŒŒ์ผ๋“ค์„ ์ง€์ •ํ•œ ์„ค์ •์— ๋งž๊ฒŒ ์ž๋ฅด๊ณ , ์••์ถ•ํ•˜๊ณ , ์‚ญ์ œํ•˜๋Š” ๊ฒƒ์„ ๋Œ€์‹ ํ•ด์ค€๋‹ค

How logrotate works

: logrotate๋Š” cron์„ ํ†ตํ•ด ๋™์ž‘ํ•˜๋Š”๋ฐ, ๊ด€๋ จ๋œ file๋“ค์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค

  • /usr/sbin/logrotate

    • executable logrotate command

  • /etc/cron.daily/logrotate

    • logrotate๋ฅผ ๋งค์ผ ์‹คํ–‰ํ•˜๋Š” shell script

    • logrotate ์ž‘์—… ๋‚ด์—ญ log

  • /etc/logrotate.conf

    • logrotate ์„ค์ • ํŒŒ์ผ

  • /etc/logrotate.d

    • logrotate process ์„ค์ • ํŒŒ์ผ

    • /etc/logroate.conf ์— ํ•ด๋‹น directory๋ฅผ ํฌํ•จ์‹œํ‚ค๋„๋ก ์„ค์ •ํ•จ

      # RPM packages drop log rotation information into this directory
      include /etc/logrotate.d

Logrotate ์‹คํ–‰ ์ˆœ์„œ

  1. crontab

  2. cron.daily

  3. logrotate

  4. logrotate.conf

  5. logrotate.d

logrotate.conf

์•„๋ž˜๋Š” logrotate.conf ์˜ ์˜ˆ์‹œ์ด๋‹ค

# see "man logrotate" for details
# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
# Log file์˜ ๊ฐœ์ˆ˜๊ฐ€ 3๊ฐœ๊ฐ€ ๋˜๋ฉด ์ฒซ๋ฒˆ์งธ ์ƒ์„ฑ๋œ LogํŒŒ์ผ ์‚ญ์ œ ํ›„ ์ƒ์„ฑ
rotate 4

# create new (empty) log files after rotating old ones
# ์ƒˆ๋กœ์šด Log file์˜ ์ƒ์„ฑ ์—ฌ๋ถ€ - create: ์ƒ์„ฑo, empty: ์ƒ์„ฑx
create

# use date as a suffix of the rotated file
# ๋กœ๊ทธ ํŒŒ์ผ์— ๋‚ ์งœ๋ฅผ ๋ถ€์—ฌํ•˜๋Š” option
dateext

# uncomment this if you want your log files compressed
#compress
# RPM packages drop log rotation information into this directory
# Log process Rใ…•ใ…‡๋กœ
include /etc/logrotate.d

# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
    monthly
    create 0664 root utmp
        minsize 1M
    rotate 1
}
/var/log/btmp {
    missingok
    monthly
    create 0600 root utmp
    rotate 1
}


# system-specific logs may be also be configured here.

Options

  • rotate [์ˆซ์ž] : logํŒŒ์ผ์ด 5๊ฐœ ์ด์ƒ ๋˜๋ฉด ์‚ญ์ œ

    • ex) rotate 5

  • maxage [์ˆซ์ž] : logํŒŒ์ผ์ด 30์ผ ์ด์ƒ ๋˜๋ฉด ์‚ญ์ œ

    • ex) maxage 30

  • size : ์ง€์ •๋œ ์šฉ๋Ÿ‰๋ณด๋‹ค ํด ๊ฒฝ์šฐ rotate ์‹คํ–‰

    • ex)ใ€€size +100k

  • create [๊ถŒํ•œ] [์œ ์ €] [๊ทธ๋ฃน] : rotate ๋˜๋Š” ๋กœ๊ทธํŒŒ์ผ ๊ถŒํ•œ ์ง€์ •

    • ex) create 644 root root

  • notifempty : ๋กœ๊ทธ ๋‚ด์šฉ์ด ์—†์œผ๋ฉด rotate ํ•˜์ง€ ์•Š์Œ

  • ifempty : ๋กœ๊ทธ ๋‚ด์šฉ์ด ์—†์–ด๋„ rotate ์ง„ํ–‰

  • monthly(์›” ๋‹จ์œ„) , weekly(์ฃผ ๋‹จ์œ„) , daily(์ผ ๋‹จ์œ„) rotate ์ง„ํ–‰

  • compress : rotate ๋˜๋Š” log file gzip ์••์ถ•

  • nocompress : rotate ๋˜๋Š” ๋กœ๊ทธํŒŒ์ผ gzip ์••์ถ• X

  • missingok : ๋กœ๊ทธ ํŒŒ์ผ์ด ๋ฐœ๊ฒฌ๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ ์—๋Ÿฌ์ฒ˜๋ฆฌ ํ•˜์ง€ ์•Š์Œ

  • dateext : ๋ฐฑ์—… ํŒŒ์ผ์˜ ์ด๋ฆ„์— ๋‚ ์งœ๊ฐ€ ๋“ค์–ด๊ฐ€๋„๋ก ํ•จ

Last updated