前提
Amazon Linux 2においてlogrotateでローテーション条件になっても古いログへ書き込み続ける場合の対処法をcopytruncateなしで教えてください。
現在対処中のシステムについて、ローテーションの時期になってlogrotateはファイル操作をするのですが、なぜかログ出力するシステムは移動されたファイルへ書き込み続けるのでログローテートの意味がなく困っています。
なお対処法としてcopytruncateは無しでお願いします。
copytruncateを使えば想定通りシステムは正しくログ出力し、ファイル肥大化しないことは確認しています。
しかし何としてもすべてのログを残す必要があるので、NGといたします。
※logrotateファイルの中身は同じなのに別のアカウントIDはどこか構成違いが影響しているのか、正常にlogrotateをしていて悩ましいです。
実現したいこと
以下のようにログ出力してほしい。
access.log <-ここにログを書き込む ...(略)... access.log-20221103 access.log-20221110
発生している問題
※肥大化するファイルはシステムの再起動タイミングなどで異なる。
access.log <-ファイルサイズが0 ...(略)... access.log-20221103 <-ファイルサイズが肥大化 access.log-20221110 <-ファイルサイズが0
該当のソースコード
/etc/logrotate.conf
logrotate
1# see "man logrotate" for details 2# rotate log files weekly 3weekly 4 5# keep 4 weeks worth of backlogs 6rotate 4 7 8# create new (empty) log files after rotating old ones 9create 10 11# use date as a suffix of the rotated file 12#dateext 13 14# uncomment this if you want your log files compressed 15#compress 16 17# packages drop log rotation information into this directory 18include /etc/logrotate.d 19 20# system-specific logs may be also be configured here.
cat /etc/logrotate.d/apache2
logrotate
1/var/log/apache2/*.log { 2 daily 3 missingok 4 rotate 14 5 compress 6 delaycompress 7 notifempty 8 create 640 root adm 9 sharedscripts 10 postrotate 11 if invoke-rc.d apache2 status > /dev/null 2>&1; then \ 12 invoke-rc.d apache2 reload > /dev/null 2>&1; \ 13 fi; 14 endscript 15 prerotate 16 if [ -d /etc/logrotate.d/httpd-prerotate ]; then \ 17 run-parts /etc/logrotate.d/httpd-prerotate; \ 18 fi; \ 19 endscript 20}
デバッグモードでの実行結果
text
1# logrotate -d /etc/logrotate.conf 2WARNING: logrotate in debug mode does nothing except printing debug messages! Consider using verbose mode (-v) instead if this is not what you want. 3 4reading config file /etc/logrotate.conf 5including /etc/logrotate.d 6reading config file alternatives 7reading config file apache2 8reading config file apt 9reading config file btmp 10reading config file dpkg 11reading config file rsyslog 12reading config file wtmp 13Reading state from file: /var/lib/logrotate/status 14Allocating hash table for state file, size 64 entries 15 16Handling 9 logs 17 18rotating pattern: /var/log/alternatives.log monthly (12 rotations) 19empty log files are not rotated, old logs are removed 20considering log /var/log/alternatives.log 21 log /var/log/alternatives.log does not exist -- skipping 22Creating new state 23 24rotating pattern: /var/log/apache2/*.log after 1 days (14 rotations) 25empty log files are not rotated, old logs are removed 26considering log /var/log/apache2/access.log 27Creating new state 28 Now: 2022-11-11 06:28 29 Last rotated at 2022-11-11 06:00 30 log does not need rotating (log has been already rotated) 31considering log /var/log/apache2/error.log 32Creating new state 33 Now: 2022-11-11 06:28 34 Last rotated at 2022-11-11 06:00 35 log does not need rotating (log has been already rotated) 36considering log /var/log/apache2/other_vhosts_access.log 37Creating new state 38 Now: 2022-11-11 06:28 39 Last rotated at 2022-11-11 06:00 40 log does not need rotating (log has been already rotated) 41not running prerotate script, since no logs will be rotated 42not running postrotate script, since no logs were rotated 43 44rotating pattern: /var/log/apt/term.log monthly (12 rotations) 45empty log files are not rotated, old logs are removed 46considering log /var/log/apt/term.log 47Creating new state 48 Now: 2022-11-11 06:28 49 Last rotated at 2022-11-11 06:00 50 log does not need rotating (log has been already rotated) 51 52rotating pattern: /var/log/apt/history.log monthly (12 rotations) 53empty log files are not rotated, old logs are removed 54considering log /var/log/apt/history.log 55Creating new state 56 Now: 2022-11-11 06:28 57 Last rotated at 2022-11-11 06:00 58 log does not need rotating (log has been already rotated) 59 60rotating pattern: /var/log/btmp monthly (1 rotations) 61empty log files are rotated, old logs are removed 62considering log /var/log/btmp 63 log /var/log/btmp does not exist -- skipping 64Creating new state 65 66rotating pattern: /var/log/dpkg.log monthly (12 rotations) 67empty log files are not rotated, old logs are removed 68considering log /var/log/dpkg.log 69Creating new state 70 Now: 2022-11-11 06:28 71 Last rotated at 2022-11-11 06:00 72 log does not need rotating (log has been already rotated) 73 74rotating pattern: /var/log/syslog 75 after 1 days (7 rotations) 76empty log files are not rotated, old logs are removed 77considering log /var/log/syslog 78Creating new state 79 Now: 2022-11-11 06:28 80 Last rotated at 2022-11-11 06:00 81 log does not need rotating (log has been already rotated) 82 83rotating pattern: /var/log/mail.info 84/var/log/mail.warn 85/var/log/mail.err 86/var/log/mail.log 87/var/log/daemon.log 88/var/log/kern.log 89/var/log/auth.log 90/var/log/user.log 91/var/log/lpr.log 92/var/log/cron.log 93/var/log/debug 94/var/log/messages 95 weekly (4 rotations) 96empty log files are not rotated, old logs are removed 97considering log /var/log/mail.info 98Creating new state 99 Now: 2022-11-11 06:28 100 Last rotated at 2022-11-11 06:00 101 log does not need rotating (log has been already rotated) 102considering log /var/log/mail.warn 103Creating new state 104 Now: 2022-11-11 06:28 105 Last rotated at 2022-11-11 06:00 106 log does not need rotating (log has been already rotated) 107considering log /var/log/mail.err 108Creating new state 109 Now: 2022-11-11 06:28 110 Last rotated at 2022-11-11 06:00 111 log does not need rotating (log has been already rotated) 112considering log /var/log/mail.log 113Creating new state 114 Now: 2022-11-11 06:28 115 Last rotated at 2022-11-11 06:00 116 log does not need rotating (log has been already rotated) 117considering log /var/log/daemon.log 118 log /var/log/daemon.log does not exist -- skipping 119Creating new state 120considering log /var/log/kern.log 121 log /var/log/kern.log does not exist -- skipping 122Creating new state 123considering log /var/log/auth.log 124Creating new state 125 Now: 2022-11-11 06:28 126 Last rotated at 2022-11-11 06:00 127 log does not need rotating (log has been already rotated) 128considering log /var/log/user.log 129Creating new state 130 Now: 2022-11-11 06:28 131 Last rotated at 2022-11-11 06:00 132 log does not need rotating (log has been already rotated) 133considering log /var/log/lpr.log 134 log /var/log/lpr.log does not exist -- skipping 135Creating new state 136considering log /var/log/cron.log 137 log /var/log/cron.log does not exist -- skipping 138Creating new state 139considering log /var/log/debug 140 log /var/log/debug does not exist -- skipping 141Creating new state 142considering log /var/log/messages 143Creating new state 144 Now: 2022-11-11 06:28 145 Last rotated at 2022-11-11 06:00 146 log does not need rotating (log has been already rotated) 147not running postrotate script, since no logs were rotated 148 149rotating pattern: /var/log/wtmp monthly (1 rotations) 150empty log files are rotated, only log files >= 1048576 bytes are rotated, old logs are removed 151considering log /var/log/wtmp 152 log /var/log/wtmp does not exist -- skipping 153Creating new state
※/var/lib/logrotate/logrotate.status も調べようとしましたが、/var/lib/logrotate内が空フォルダだったので、他の場所に格納していないか調査中です
以上よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー