logrotate: 리눅스 로그 회전 설정과 -d, -f 테스트 방법

공정위 광고 문구 Ver 3.1
공정위 광고 문구 Ver 3.2(모바일 전용)
테스트 환경RHEL 계열AlmaLinux 9.8logrotate 3.18.0root 계정Debian 122026-10-29 확인
시스템 정보 · 설정logrotate위치/usr/sbin/logrotate

logrotate(로그로테이트)는 리눅스에서 계속 커지는 로그 파일을 정해진 주기나 크기마다 새 파일로 바꾸고, 오래된 파일은 압축하거나 지우는 프로그램입니다. AlmaLinux 9 서버의 시험 폴더에 로그와 설정 파일을 따로 만들어 -d로 미리 본 뒤 -f로 회전해 본 결과, 운영 설정은 건드리지 않고도 rotate와 compress, dateext 같은 지시어가 로그 파일 이름과 개수를 어떻게 바꾸는지 확인할 수 있었습니다.

아래 출력은 AlmaLinux 9.8 서버의 root 계정과 Debian 12 서버에서 실행한 결과입니다. 운영 중인 설정 파일과 타이머는 읽기만 했고, 회전 시험은 시험 폴더 안의 로그에만 했습니다. 시험 폴더 경로와 시각은 예시 값으로 바꿨습니다.

1️⃣ logrotate 동작 방식

logrotate는 systemd 타이머가 하루 한 번 실행하는 명령입니다. 실행되면 설정 파일에 적힌 로그를 차례로 확인해 회전하고 종료합니다. 설치된 버전과 기본 경로는 --version으로 확인합니다.

logrotate --version
logrotate 3.18.0

    Default mail command:       /bin/mail
    Default compress command:   /bin/gzip
    Default uncompress command: /bin/gunzip
    Default compress extension: .gz
    Default state file path:    /var/lib/logrotate/logrotate.status
    ACL support:                yes
    SELinux support:            yes

AlmaLinux 9.8 서버의 logrotate는 3.18.0이었습니다. 압축에는 /bin/gzip을 사용하고, 로그마다 마지막으로 회전한 시각은 /var/lib/logrotate/logrotate.status 상태 파일에 기록합니다.

하루 한 번 실행하는 일정은 logrotate.timer에 들어 있습니다.

systemctl cat logrotate.timer
# /usr/lib/systemd/system/logrotate.timer
[Unit]
Description=Daily rotation of log files
Documentation=man:logrotate(8) man:logrotate.conf(5)

[Timer]
OnCalendar=daily
AccuracySec=1h
Persistent=true

[Install]
WantedBy=timers.target

OnCalendar=daily는 매일 0시에 실행하는 일정입니다. 공식 매뉴얼 기준으로 Persistent=true는 서버가 꺼져 있어 실행 시각을 놓치면 다음에 켜질 때 바로 실행하는 설정입니다.

systemctl list-timers logrotate.timer
NEXT                        LEFT     LAST                        PASSED  UNIT            ACTIVATES
Fri 2026-10-30 00:00:00 UTC 14h left Thu 2026-10-29 00:00:00 UTC 9h ago  logrotate.timer logrotate.service

1 timers listed.
Pass --all to see loaded but inactive timers, too.

NEXT 칸은 다음 실행 시각, LAST 칸은 마지막으로 실행한 시각입니다. 타이머가 실행하는 logrotate.service에는 운영 설정 파일 /etc/logrotate.conf를 넘기는 줄이 들어 있었습니다.

grep ExecStart /usr/lib/systemd/system/logrotate.service
ExecStart=/usr/sbin/logrotate /etc/logrotate.conf

타이머와 설정 파일, 상태 파일의 관계는 아래와 같습니다.

🖥️ logrotate 실행 구조
logrotate.timer매일 0시 · Persistent=true
logrotate.servicelogrotate /etc/logrotate.conf 실행
/etc/logrotate.conf전역 기본값 · weekly · rotate 4 · create · dateext
include /etc/logrotate.d서비스별 설정 파일을 차례로 읽음
/var/lib/logrotate/logrotate.status로그마다 마지막 회전 시각

2️⃣ logrotate.conf 기본 설정

/etc/logrotate.conf는 모든 로그에 적용할 기본값을 정하는 파일입니다. AlmaLinux 9.8 서버의 기본 파일을 읽었습니다.

cat /etc/logrotate.conf
# see "man logrotate" for details

# global options do not affect preceding include directives

# 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

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

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

주석을 뺀 지시어는 다섯 줄입니다. weekly는 일주일마다 회전하고, rotate 4는 회전한 파일을 네 개까지 남깁니다. create는 회전 직후 같은 이름의 빈 로그를 새로 만들고, dateext는 회전한 파일 이름 끝에 숫자 대신 날짜를 붙입니다. compress는 주석 처리되어 있어 기본 설정에서는 압축하지 않습니다.

include /etc/logrotate.d 줄은 그 폴더 안의 파일을 차례로 읽어 들입니다. 패키지를 설치하면 서비스마다 로그 경로와 지시어를 담은 파일이 이 폴더에 생기고, 그 파일에 적지 않은 지시어는 위의 기본값을 따릅니다.

파일 맨 위 주석처럼 전역 지시어는 자기보다 앞에 있는 include에는 적용되지 않습니다. 기본값을 바꿀 때는 include 줄보다 위에 적습니다.

3️⃣ logrotate 설정 지시어

서비스별 설정은 로그 경로 뒤 중괄호 안에 지시어를 한 줄씩 적는 꼴입니다. 시험 폴더에 printf로 세 줄짜리 시험 로그 app.log를 만들고, 그 로그를 회전할 시험 설정 test.conf를 작성했습니다.

cat /home/user/logtest/test.conf
/home/user/logtest/logs/app.log {
    daily
    rotate 3
    compress
    delaycompress
    missingok
    notifempty
    create 0640 root root
    postrotate
        echo "postrotate: app.log rotated"
    endscript
}

자주 사용하는 지시어는 아래와 같습니다.

지시어하는 일
daily · weekly · monthly회전 주기 — 하루 · 일주일 · 한 달
rotate 3회전한 파일을 3개까지 남기고 더 오래된 파일은 삭제
size 1k주기와 관계없이 파일이 1KB를 넘을 때 회전(k · M · G)
compress회전한 파일을 gzip으로 압축
delaycompress방금 회전한 파일은 다음 회전 때 압축
missingok로그 파일이 없으면 오류 없이 건너뜀
notifempty빈 로그는 회전하지 않음
create 0640 root root회전 직후 빈 로그를 권한 · 소유자 · 그룹으로 새로 생성
copytruncate로그를 복사해 남긴 뒤 원래 파일을 비움
dateext회전한 파일 이름 끝에 숫자 대신 날짜
postrotate … endscript회전이 끝난 뒤 실행할 명령
su 사용자 그룹회전할 때 사용할 사용자와 그룹

postrotate와 endscript 사이에는 회전이 끝난 뒤 실행할 셸 명령을 적습니다. 공식 매뉴얼의 예시는 이 자리에서 syslogd에 HUP 신호를 보내 로그 파일을 다시 열게 합니다. 시험 설정에는 실행 여부만 확인하도록 echo 한 줄을 넣었습니다.

4️⃣ logrotate -d 테스트

-d는 실제로 회전하지 않고, 설정을 읽어 어떤 로그를 회전할지 판단하는 과정만 출력하는 옵션입니다. -s는 상태 파일 경로를 정하는 옵션입니다. 시험에서는 시험 폴더의 state 파일을 지정해, 운영 상태 파일과 기록이 섞이지 않게 했습니다.

logrotate -d -s /home/user/logtest/state /home/user/logtest/test.conf
WARNING: logrotate in debug mode does nothing except printing debug messages!  Consider using verbose mode (-v) instead if this is not what you want.

reading config file /home/user/logtest/test.conf
Reading state from file: /home/user/logtest/state
error: error opening state file /home/user/logtest/state: No such file or directory
Allocating hash table for state file, size 64 entries

Handling 1 logs

rotating pattern: /home/user/logtest/logs/app.log  after 1 days (3 rotations)
empty log files are not rotated, old logs are removed
considering log /home/user/logtest/logs/app.log
Creating new state
  Now: 2026-10-29 09:39
  Last rotated at 2026-10-29 09:00
  log does not need rotating (log has already been rotated)

첫 줄의 WARNING은 디버그 모드라 아무것도 바꾸지 않는다는 안내입니다. error 줄은 상태 파일이 아직 없어서 나온 것입니다. -d는 상태 파일을 만들지 않아, 상태 파일 없이 -d로 실행하면 이 줄이 나옵니다.

rotating pattern 줄의 after 1 days (3 rotations)는 daily와 rotate 3을 읽은 결과입니다. 마지막 줄은 log has already been rotated였습니다. 바로 위 Now 줄은 09:39, Last rotated at 줄은 09:00이었습니다. 상태 파일에 기록이 없는 로그는 이처럼 지금 시각의 정각을 마지막 회전 시각으로 잡아, daily 로그는 다음 날이 되어야 회전 대상이 됩니다. 그래서 설정을 바꾼 직후 결과를 보려면 -f로 강제 회전합니다.

5️⃣ logrotate -f 강제 회전과 -v 옵션

-f는 주기와 크기 조건과 관계없이 바로 회전하는 옵션이고, -v는 회전 과정을 한 줄씩 출력합니다. 같은 상태 파일과 설정으로 -f와 -v를 함께 실행했습니다.

logrotate -f -v -s /home/user/logtest/state /home/user/logtest/test.conf
reading config file /home/user/logtest/test.conf
Creating stub state file: /home/user/logtest/state
Reading state from file: /home/user/logtest/state
Allocating hash table for state file, size 64 entries

Handling 1 logs

rotating pattern: /home/user/logtest/logs/app.log  forced from command line (3 rotations)
empty log files are not rotated, old logs are removed
considering log /home/user/logtest/logs/app.log
Creating new state
  Now: 2026-10-29 09:39
  Last rotated at 2026-10-29 09:00
  log needs rotating
rotating log /home/user/logtest/logs/app.log, log->rotateCount is 3
dateext suffix '-20261029'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
previous log /home/user/logtest/logs/app.log.1 does not exist
renaming /home/user/logtest/logs/app.log.3.gz to /home/user/logtest/logs/app.log.4.gz (rotatecount 3, logstart 1, i 3), 
old log /home/user/logtest/logs/app.log.3.gz does not exist
renaming /home/user/logtest/logs/app.log.2.gz to /home/user/logtest/logs/app.log.3.gz (rotatecount 3, logstart 1, i 2), 
old log /home/user/logtest/logs/app.log.2.gz does not exist
renaming /home/user/logtest/logs/app.log.1.gz to /home/user/logtest/logs/app.log.2.gz (rotatecount 3, logstart 1, i 1), 
old log /home/user/logtest/logs/app.log.1.gz does not exist
renaming /home/user/logtest/logs/app.log.0.gz to /home/user/logtest/logs/app.log.1.gz (rotatecount 3, logstart 1, i 0), 
old log /home/user/logtest/logs/app.log.0.gz does not exist
log /home/user/logtest/logs/app.log.4.gz doesn't exist -- won't try to dispose of it
renaming /home/user/logtest/logs/app.log to /home/user/logtest/logs/app.log.1
creating new /home/user/logtest/logs/app.log mode = 0640 uid = 0 gid = 0
running postrotate script
postrotate: app.log rotated

rotate 3이라 app.log.4.gz까지 번호를 한 칸씩 미는 renaming 줄이 먼저 나왔고, 아직 회전한 파일이 없어 does not exist 줄이 이어졌습니다. 그다음 app.log를 app.log.1로 바꾸고, create 0640 root root에 맞춰 빈 app.log를 새로 만들었습니다. 마지막 줄은 postrotate에 넣은 echo의 출력입니다.

ls -l /home/user/logtest/logs/app.log*
-rw-r----- 1 root root   0 Oct 29 09:39 /home/user/logtest/logs/app.log
-rw-r--r-- 1 root root 128 Oct 29 09:39 /home/user/logtest/logs/app.log.1

새 app.log는 create에 적은 0640 권한으로 만들어졌고, app.log.1은 원래 파일의 권한을 그대로 유지했습니다.

printf로 app.log 끝에 한 줄을 더했습니다.

printf '2026-10-29 10:00:01 request GET /index.html 200\n' >> /home/user/logtest/logs/app.log

그다음 -v 없이 한 번 더 실행하자 postrotate의 echo 출력만 나왔습니다.

logrotate -f -s /home/user/logtest/state /home/user/logtest/test.conf
postrotate: app.log rotated
ls -l /home/user/logtest/logs/app.log*
-rw-r----- 1 root root  0 Oct 29 09:39 /home/user/logtest/logs/app.log
-rw-r----- 1 root root 48 Oct 29 09:39 /home/user/logtest/logs/app.log.1
-rw-r--r-- 1 root root 96 Oct 29 09:39 /home/user/logtest/logs/app.log.2.gz

delaycompress 때문에 첫 회전에서 남긴 app.log.1은 이번 회전에서 압축되어 app.log.2.gz가 되었고, 방금 회전한 app.log.1은 압축하지 않은 채 남았습니다.

빈 app.log는 notifempty 때문에 -f를 붙여도 회전하지 않았습니다.

logrotate -f -v -s /home/user/logtest/state /home/user/logtest/test.conf
reading config file /home/user/logtest/test.conf
Reading state from file: /home/user/logtest/state
Allocating hash table for state file, size 64 entries
Creating new state

Handling 1 logs

rotating pattern: /home/user/logtest/logs/app.log  forced from command line (3 rotations)
empty log files are not rotated, old logs are removed
considering log /home/user/logtest/logs/app.log
  Now: 2026-10-29 09:39
  Last rotated at 2026-10-29 09:39
  log does not need rotating (log is empty)

app.log에 한 줄씩 더하며 두 번 더 회전하자, 마지막 회전에서 네 번째 파일 app.log.4.gz가 삭제되었습니다. -v 출력에서 removing 줄만 골라 확인했습니다.

logrotate -f -v -s /home/user/logtest/state /home/user/logtest/test.conf 2>&1 | grep removing
removing old log /home/user/logtest/logs/app.log.4.gz
ls -l /home/user/logtest/logs/app.log*
-rw-r----- 1 root root  0 Oct 29 09:39 /home/user/logtest/logs/app.log
-rw-r----- 1 root root 48 Oct 29 09:39 /home/user/logtest/logs/app.log.1
-rw-r----- 1 root root 68 Oct 29 09:39 /home/user/logtest/logs/app.log.2.gz
-rw-r----- 1 root root 66 Oct 29 09:39 /home/user/logtest/logs/app.log.3.gz

rotate 3에 맞춰 회전한 파일은 app.log.1과 app.log.2.gz, app.log.3.gz 세 개만 남았습니다. 압축한 파일의 내용은 zcat으로 확인합니다.

zcat /home/user/logtest/logs/app.log.2.gz
2026-10-29 11:00:01 request GET /index.html 200

상태 파일에는 로그마다 마지막으로 회전한 날짜와 시각이 한 줄씩 기록되어 있었습니다.

cat /home/user/logtest/state
logrotate state -- version 2
"/home/user/logtest/logs/app.log" 2026-10-29-9:39:9

logrotate는 다음에 실행될 때 이 시각과 daily · weekly 같은 주기를 견주어 회전할지 정합니다.

🔲 logrotate 시뮬레이터

아래 시뮬레이터에서 시험 폴더의 test.conf와 size.conf, date.conf, copy.conf를 -d와 -f, -v로 실행하고, logs 폴더에서 회전한 파일을 확인할 수 있습니다.

logrotate 시뮬레이터logrotate 3.18.0
[root@server work]#
브라우저 안에서만 동작하는 가상 AlmaLinux 서버이며, 회전된 로그는 왼쪽 logs 폴더에 나오고 ↑↓ 로 앞에서 쓴 명령을 다시 불러옵니다.

6️⃣ logrotate size, dateext, copytruncate

size는 주기 대신 파일 크기로 회전 여부를 정합니다. 1,515바이트짜리 시험 로그 size.log에 size 1k를 적은 size.conf를 -f 없이 실행했습니다.

cat /home/user/logtest/size.conf
/home/user/logtest/logs/size.log {
    size 1k
    rotate 2
    missingok
}
logrotate -v -s /home/user/logtest/state-size /home/user/logtest/size.conf
reading config file /home/user/logtest/size.conf
Creating stub state file: /home/user/logtest/state-size
Reading state from file: /home/user/logtest/state-size
Allocating hash table for state file, size 64 entries

Handling 1 logs

rotating pattern: /home/user/logtest/logs/size.log  1024 bytes (2 rotations)
empty log files are rotated, old logs are removed
considering log /home/user/logtest/logs/size.log
Creating new state
  Now: 2026-10-29 09:28
  Last rotated at 2026-10-29 09:00
  log needs rotating
rotating log /home/user/logtest/logs/size.log, log->rotateCount is 2
dateext suffix '-20261029'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /home/user/logtest/logs/size.log.2 to /home/user/logtest/logs/size.log.3 (rotatecount 2, logstart 1, i 2), 
old log /home/user/logtest/logs/size.log.2 does not exist
renaming /home/user/logtest/logs/size.log.1 to /home/user/logtest/logs/size.log.2 (rotatecount 2, logstart 1, i 1), 
old log /home/user/logtest/logs/size.log.1 does not exist
renaming /home/user/logtest/logs/size.log.0 to /home/user/logtest/logs/size.log.1 (rotatecount 2, logstart 1, i 0), 
old log /home/user/logtest/logs/size.log.0 does not exist
log /home/user/logtest/logs/size.log.3 doesn't exist -- won't try to dispose of it
renaming /home/user/logtest/logs/size.log to /home/user/logtest/logs/size.log.1

rotating pattern 줄에 1024 bytes가 나왔고, 상태 파일을 새로 만든 첫 실행인데도 크기가 1KB를 넘어 바로 회전했습니다. size.conf에는 create를 적지 않아 새 size.log는 만들어지지 않았습니다.

size.log를 한 줄짜리 파일로 다시 만든 뒤 같은 명령을 실행하자 회전하지 않았습니다.

logrotate -v -s /home/user/logtest/state-size /home/user/logtest/size.conf
reading config file /home/user/logtest/size.conf
Reading state from file: /home/user/logtest/state-size
Allocating hash table for state file, size 64 entries
Creating new state

Handling 1 logs

rotating pattern: /home/user/logtest/logs/size.log  1024 bytes (2 rotations)
empty log files are rotated, old logs are removed
considering log /home/user/logtest/logs/size.log
  Now: 2026-10-29 09:28
  Last rotated at 2026-10-29 09:28
  log does not need rotating (log size is below the 'size' threshold)

dateext를 적으면 회전한 파일 이름 끝에 숫자 대신 날짜가 붙습니다. date.conf에는 weekly와 rotate 4, dateext, compress를 적었습니다.

logrotate -f -v -s /home/user/logtest/state-date /home/user/logtest/date.conf
reading config file /home/user/logtest/date.conf
Creating stub state file: /home/user/logtest/state-date
Reading state from file: /home/user/logtest/state-date
Allocating hash table for state file, size 64 entries

Handling 1 logs

rotating pattern: /home/user/logtest/logs/date.log  forced from command line (4 rotations)
empty log files are rotated, old logs are removed
considering log /home/user/logtest/logs/date.log
Creating new state
  Now: 2026-10-29 09:28
  Last rotated at 2026-10-29 09:00
  log needs rotating
rotating log /home/user/logtest/logs/date.log, log->rotateCount is 4
dateext suffix '-20261029'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding old rotated logs failed
renaming /home/user/logtest/logs/date.log to /home/user/logtest/logs/date.log-20261029
compressing log with: /bin/gzip
ls -l /home/user/logtest/logs | grep date
-rw-r--r-- 1 root root   56 Oct 29 09:28 date.log-20261029.gz

날짜는 하루 단위라 같은 날 다시 회전하면 이름이 겹칩니다. date.log에 새 줄을 넣고 -f로 한 번 더 실행하자 회전을 건너뛰고 종료 코드 1로 끝났습니다.

logrotate -f -v -s /home/user/logtest/state-date /home/user/logtest/date.conf
reading config file /home/user/logtest/date.conf
Reading state from file: /home/user/logtest/state-date
Allocating hash table for state file, size 64 entries
Creating new state

Handling 1 logs

rotating pattern: /home/user/logtest/logs/date.log  forced from command line (4 rotations)
empty log files are rotated, old logs are removed
considering log /home/user/logtest/logs/date.log
  Now: 2026-10-29 09:28
  Last rotated at 2026-10-29 09:28
  log needs rotating
rotating log /home/user/logtest/logs/date.log, log->rotateCount is 4
dateext suffix '-20261029'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
error: destination /home/user/logtest/logs/date.log-20261029.gz already exists, skipping rotation

copytruncate는 로그를 복사해 .1로 남긴 뒤 원래 파일의 내용을 비웁니다. 원래 파일을 그대로 두므로, 로그 파일을 다시 열지 못하는 프로그램에 사용합니다.

logrotate -f -v -s /home/user/logtest/state-copy /home/user/logtest/copy.conf
reading config file /home/user/logtest/copy.conf
Creating stub state file: /home/user/logtest/state-copy
Reading state from file: /home/user/logtest/state-copy
Allocating hash table for state file, size 64 entries

Handling 1 logs

rotating pattern: /home/user/logtest/logs/copy.log  forced from command line (2 rotations)
empty log files are rotated, old logs are removed
considering log /home/user/logtest/logs/copy.log
Creating new state
  Now: 2026-10-29 09:28
  Last rotated at 2026-10-29 09:00
  log needs rotating
rotating log /home/user/logtest/logs/copy.log, log->rotateCount is 2
dateext suffix '-20261029'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /home/user/logtest/logs/copy.log.2 to /home/user/logtest/logs/copy.log.3 (rotatecount 2, logstart 1, i 2), 
old log /home/user/logtest/logs/copy.log.2 does not exist
renaming /home/user/logtest/logs/copy.log.1 to /home/user/logtest/logs/copy.log.2 (rotatecount 2, logstart 1, i 1), 
old log /home/user/logtest/logs/copy.log.1 does not exist
renaming /home/user/logtest/logs/copy.log.0 to /home/user/logtest/logs/copy.log.1 (rotatecount 2, logstart 1, i 0), 
old log /home/user/logtest/logs/copy.log.0 does not exist
log /home/user/logtest/logs/copy.log.3 doesn't exist -- won't try to dispose of it
copying /home/user/logtest/logs/copy.log to /home/user/logtest/logs/copy.log.1
truncating /home/user/logtest/logs/copy.log
ls -l /home/user/logtest/logs | grep copy
-rw-r--r-- 1 root root    0 Oct 29 09:28 copy.log
-rw-r--r-- 1 root root   72 Oct 29 09:28 copy.log.1

copy.log는 0바이트가 되었고, 내용은 copy.log.1로 옮겨졌습니다. 공식 매뉴얼은 복사와 비우기 사이에 기록된 줄은 사라질 수 있다고 적고 있어, 로그 파일을 다시 열게 할 수 있는 서비스에는 create와 postrotate를 사용합니다.

7️⃣ 로그로테이트 오류 확인

logrotate가 로그를 회전하지 않을 때는 같은 설정을 -d로 실행해 considering log 아래 마지막 줄을 확인합니다. 시험에서 나온 문구는 넷이었습니다.

considering log 아래 마지막 줄뜻
log needs rotating회전 대상
log does not need rotating (log has already been rotated)주기가 아직 지나지 않음 · 상태 파일에 처음 기록된 로그
log does not need rotating (log is empty)notifempty이고 로그가 빈 파일
log does not need rotating (log size is below the 'size' threshold)size에 적은 크기보다 작음

로그 파일이 없을 때는 missingok가 결과를 정합니다. missingok 없이 없는 파일을 적은 miss.conf는 오류로 끝났습니다.

logrotate -f -s /home/user/logtest/state-miss /home/user/logtest/miss.conf
error: stat of /home/user/logtest/logs/none.log failed: No such file or directory

같은 경로에 missingok를 더한 miss2.conf는 does not exist -- skipping 줄을 남기고 종료 코드 0으로 끝났습니다.

로그가 든 폴더의 권한이 열려 있어도 회전하지 않습니다. 시험 폴더 안에 권한이 777인 logs-open 폴더를 만들고 그 안의 로그를 회전하자 아래 오류가 나왔습니다.

logrotate -f -s /home/user/logtest/state-open /home/user/logtest/open.conf
error: skipping "/home/user/logtest/logs-open/open.log" because parent directory has insecure permissions (It's world writable or writable by group which is not "root") Set "su" directive in config file to tell logrotate which user/group should be used for rotation.

오류 문구대로 설정에 su 지시어로 회전할 사용자와 그룹을 적자, 같은 로그가 회전되었습니다.

cat /home/user/logtest/open2.conf
/home/user/logtest/logs-open/open.log {
    su root root
    daily
    rotate 2
}
logrotate -f -s /home/user/logtest/state-open /home/user/logtest/open2.conf

이번에는 오류 없이 끝났고, logs-open 폴더에 open.log.1이 생겼습니다.

ls -l /home/user/logtest/logs-open
total 4
-rw-r--r-- 1 root root 5 Oct 29 09:28 open.log.1

설정 파일에 지시어를 잘못 적으면 logrotate는 그 줄만 버리고 나머지 지시어로 실행합니다. rotate를 rotat으로 적은 bad.conf를 -d로 읽었습니다.

logrotate -d -s /home/user/logtest/state-bad /home/user/logtest/bad.conf
WARNING: logrotate in debug mode does nothing except printing debug messages!  Consider using verbose mode (-v) instead if this is not what you want.

reading config file /home/user/logtest/bad.conf
error: /home/user/logtest/bad.conf:3 unknown option 'rotat' -- ignoring line
Reading state from file: /home/user/logtest/state-bad
error: error opening state file /home/user/logtest/state-bad: No such file or directory
Allocating hash table for state file, size 64 entries

Handling 1 logs

rotating pattern: /home/user/logtest/logs/app.log  after 1 days (no old logs will be kept)
empty log files are rotated, old logs are removed
considering log /home/user/logtest/logs/app.log
Creating new state
  Now: 2026-10-29 09:33
  Last rotated at 2026-10-29 09:00
  log does not need rotating (log has already been rotated)

오류 줄에 파일 이름과 줄 번호가 나왔고, rotate 줄이 빠져 (no old logs will be kept)로 읽혔습니다. 이대로 회전하면 이전 로그를 하나도 남기지 않으므로, 설정을 고친 뒤에는 -d로 rotating pattern 줄부터 확인합니다.

🔢 FAQ & 추천 콘텐츠

공식 매뉴얼 기준으로 -d는 -v를 함께 켜고 로그 파일과 상태 파일을 바꾸지 않습니다. 시험 설정을 -d로 실행한 뒤에도 app.log는 그대로였고, 상태 파일은 만들어지지 않았습니다. 실제 회전은 -d를 빼고 실행할 때만 일어납니다.

설정에 hourly 지시어를 적고, logrotate를 매시간 실행하도록 타이머나 cron도 함께 바꿉니다. AlmaLinux 9.8 서버의 logrotate.timer는 OnCalendar=daily라 하루 한 번만 실행되었고, 공식 매뉴얼도 logrotate를 매시간 실행해야 hourly가 매시간 회전한다고 적고 있습니다.

Debian 12 서버의 logrotate는 3.21.0이었고, logrotate.timer도 같은 OnCalendar=daily였습니다. /etc/cron.daily/logrotate 파일도 있었지만 systemd로 부팅한 서버에서는 바로 종료하는 스크립트였습니다. 기본 /etc/logrotate.conf는 dateext 줄이 주석 처리되어 있어, 회전한 파일 이름에 날짜 대신 번호가 붙습니다.

ℹ️ 제휴 안내
본 사이트의 콘텐츠에는 제휴 링크가 포함되어 있습니다. 방문자가 이 링크를 통해 상품 또는 서비스를 구매하면 본 사이트는 판매처로부터 수수료를 지급받습니다. 이 과정에서 구매자가 지불하는 금액(이벤트 할인 시 금액이 내려갑니다↓)은 오르지 않습니다. 게시된 가격·할인·재고 정보는 작성 시점 기준이며 실제와 다를 수 있으므로, 구매 전 판매처에서 최종 확인하시기 바랍니다. 상품 선정과 평가는 자체 기준에 따라 작성되며, 수수료 지급 여부가 소개 순서나 평가 내용에 영향을 주지 않습니다.

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

Prove your humanity: 5   +   4   =