CentOS Stream 8 のログ監視にlogwatchをインストール

CentOS Stream 8 をVMware ESXi にインストールした覚書です。

今回は、logwatchをインストールしてログ監視の設定を行っていきたいと思います。

logwatchは、ログを解析してレポートしてくれるツールです。

なお本番環境で利用される場合はここにある内容だけを鵜呑みにせずセキュリティ専門家に相談されることをお勧めします。

環境

実施日2021-08-12
サーバVMware ESXi 6.7 U3
OSCentOS Stream 8
cat /etc/redhat-release
CentOS Stream release 8

logwatchのインストール

dnfからインストールします。

dnf install logwatch

設定の変更

logwatchの設定は、デフォルトの設定ファイルのほか、ローカル専用のファイルの計2つから構成されます。

ざっくり書くと、ローカル設定を読み込み、足らずをデフォルト設定から読み込むイメージです。

まずはデフォルト設定ファイルの内容を見てみます。

vi /usr/share/logwatch/default.conf/logwatch.conf

▲こちらの内容は変更しません。

次にローカル向けの設定ファイルを開いてみます。

vi /etc/logwatch/conf/logwatch.conf
# Local configuration options go here (defaults are in /usr/share/logwatch/default.conf/logwatch.conf)

▲のようにこのファイルにも書かれています。

ここに変更したい内容を書いていきます・・・

・・・というのが本来の使い方なのですが、慣れないうちは訳が分からなくなると思います。

なので、デフォルト設定ファイルをコピーして全書き換えします。

cp /usr/share/logwatch/default.conf/logwatch.conf /etc/logwatch/conf/logwatch.conf

上書きコピーします。

ということで、コピーしたファイルを書き換えていきましょう。

vi /etc/logwatch/conf/logwatch.conf
# メールの送り先
MailTo = root
MailTo = sample@example.com

# ログレベル
Detail = Low
Detail = Med
Detail = High

動作確認

設定ができたら動作確認を行っておきます。

# 標準出力に表示
logwatch --output stdout

# メールに送信
logwatch --output mail

# CRONにいることを確認
ls -la /etc/cron.daily/0logwatch