Leopard に logrotate をインストール
久しぶりに(どういうサーバー管理者だ) apacheのログディレクトリをチェックしたら、 access_log が 512M とか貯まっていた。
こりゃえらいこっちゃということで、logrotate を導入することにした。
MacPorts からインストール
[yuanying@Kohrin] /opt/local/apache2/logs
$ sudo port install logrotate
---> Fetching logrotate
---> Verifying checksum(s) for logrotate
---> Extracting logrotate
---> Applying patches to logrotate
---> Configuring logrotate
---> Building logrotate with target all
---> Staging logrotate into destroot
---> Installing logrotate 3.7.1\_1
---> Activating logrotate 3.7.1\_1
---> Cleaning logrotate
設定ファイルの修正
/opt/local/etc にサンプルの設定ファイルがインストールされているので、
[yuanying@Kohrin] /opt/local/etc
$ ll -h
total 320
drwxr-xr-x 5 root admin 170B 4 10 11:40 LaunchDaemons/
drwxr-xr-x 6 root admin 204B 4 10 10:49 dovecot/
drwxr-xr-x 6 root admin 204B 12 4 10:35 fonts/
-rwxr-xr-x 2 root admin 505B 4 17 14:57 logrotate.conf.sample*
logrotate.conf という名前でコピーして修正。
[yuanying@Kohrin] /opt/local/etc
$ sudo cp /opt/local/etc/logrotate.conf.sample /opt/local/etc/logrotate.conf
Password:
[yuanying@Kohrin] /opt/local/etc
$ sudo vim logrotate.conf
[yuanying@Kohrin] /opt/local/etc
$ diff logrotate.conf.sample logrotate.conf
15c15
< include /etc/logrotate.d
---
> include /opt/local/etc/logrotate.d
18,22c18,22
< /var/log/wtmp {
< monthly
< create 0664 root utmp
< rotate 1
< }
---
> #/var/log/wtmp {
> # monthly
> # create 0664 root utmp
> # rotate 1
> #}
/var/log/wtmp ~~ が残ってると、そんなファイルが無いよ、とか言われるのでコメントアウトする。
あと、ログ設定ファイルのディレクトリを /opt/local/etc/logrotate.d に修正。
このまま実行すると、/var/lib がねえぞって怒られるので、ついでに /var/lib も作っておく。
本当は /opt/local/var/lib に変更したいんだけど、設定方法がわからない。
[yuanying@Kohrin] /opt/local/etc
$ sudo mkdir -p /var/lib
apache のログローテート設定
apache の ログ用にローテートの設定ファイルを書く。
[yuanying@Kohrin] /opt/local/apache2/logs
$ sudo vim /opt/local/etc/logrotate.d/apache2
[yuanying@Kohrin] /opt/local/apache2/logs
$ more /opt/local/etc/logrotate.d/apache2
/opt/local/apache2/logs/*log {
rotate 4
missingok
notifempty
sharedscripts
postrotate
/bin/kill -HUP `cat /opt/local/apache2/logs/httpd.pid 2>/dev/null` 2> /dev/null || true
endscript
}
/opt/local/apache2/logs/ ディレクトリ以下の *log ファイルをすべてローテートしてやる。
cron で毎日 logrotate する
[yuanying@Kohrin] /opt/local/apache2/logs
$ sudo crontab -e
以下がcronの設定。
43 03 * * * /opt/local/sbin/logrotate /opt/local/etc/logrotate.conf