LoginSignup
19

More than 3 years have passed since last update.

logwatch 設定手順 覚書

Last updated at Posted at 2019-11-19

検証環境

Ubuntu 18.04

logwatch のインストール

sudo apt-get install logwatch

logwatch と一緒に postfix がインストールされます。
logwatch は標準で postfix を使用する為、
特にこだわりがなければメール転送エージェントを
追加でインストールする必要はありません。

logwatch の設定

/usr/share/logwatch/default.conf/logwatch.conf から雛形をコピーして
/etc/logwatch/conf/logwatch.conf へ配置します。
下記のように編集してください。

/etc/logwatch/conf/logwatch.conf
# 自身の Gmail アドレスを指定する。
MailTo = xxxx@gmail.com
# メールの送信元(差出人)を指定する。
MailFrom = ubuntu_lxd
# logwatch のレポートの詳細度を指定する。
Detail = High

postfix の設定

/usr/share/postfix/main.cf.dist から雛形をコピーして
/etc/postfix/main.cf へ配置します。
下記のように編集してください。

/etc/postfix/main.cf
relayhost = [smtp.gmail.com]:587

#sasl setting
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_sasl_mechanism_filter = plain

#tls setting
smtp_use_tls = yes

続いて /etc/postfix/sasl_passwd を下記の書式で作成します。

/etc/postfix/sasl_passwd
# 自身の Gmail アドレスとパスワードを記述する。
[smtp.gmail.com]:587 xxxx@gmail.com:password

sasl_passwd の情報を postfix へ登録する為、下記のコマンドを実行します。

postmap /etc/postfix/sasl_passwd

Gmail の設定

https://myaccount.google.com/lesssecureapps から
「安全性の低いアプリの許可」を有効にします。

動作確認

下記コマンドを実行し、送信先 Gmail アドレスにメールが届いているかを確認します。

logwatch --output mail

cron への登録

インストール時に自動でやってくれるようです。
/etc/cron.daily/00logwatch というファイルが作成されていれば、
毎日自動的に logwatch のレポートがメール送信されます。
中身は至ってシンプル。

/etc/cron.daily/00logwatch
#!/bin/bash

#Check if removed-but-not-purged
test -x /usr/share/logwatch/scripts/logwatch.pl || exit 0

#execute
/usr/sbin/logwatch --output mail

参考資料

VPS(scaleway)へのlogwatchの導入+gmailへ送信

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19