内部用DNSとして、Dockerでdnsmasqを起動しているのだが、ログを取る設定にしていると、いつの間にか肥大して、HDDを圧迫してしまうので、logrotateで肥大化を防ぐ
logrotate
# cat << EOF >> /etc/logrotate.d/dnslog
/home/user/docker/dnsmasq/dnsmasq-DNS.log {
weekly
rotate 7
compress
delaycompress
missingok
notifempty
create 0640 user users
}
EOF
反映
$ sudo logrotate -f /etc/logrotate.d/dnslog
もし、エラーが出たら、確認する
$ sudo logrotate -dv /etc/logrotate.d/dnslog
Vagrant内の場合
下記のエラーが出る場合がある
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 username groupnameを挿入するためには、suディレクティブを適切なユーザー名とグループ名に置き換えて、設定ブロックの最初に追加します。このケースではvagrantユーザーとvagrantグループを使用します
/home/vagrant/app/docker/compose/dnsmasq/dnsmasq-DNS.log {
su vagrant vagrant
weekly
rotate 3
compress
delaycompress
missingok
notifempty
create 0640 vagrant vagrant
}