m_shige1979のときどきITブログ

プログラムの勉強をしながら学習したことや経験したことをぼそぼそと書いていきます

Github(変なおっさんの顔でるので気をつけてね)

https://github.com/mshige1979

logwatchの設定

logwatchを入れる

手順

yumでインストール
[root@localhost ~]# yum install -y logwatch
[root@localhost ~]#
「/usr/sbin/logwatch --print」で確認
 ################### Logwatch 7.3.6 (05/19/07) ####################
        Processing Initiated: Thu Nov 21 06:18:58 2013
        Date Range Processed: yesterday
                              ( 2013-Nov-20 )
                              Period is day.
      Detail Level of Output: 0
              Type of Output: unformatted
           Logfiles for Host: localhost.localdomain
  ##################################################################

 --------------------- Selinux Audit Begin ------------------------

  Number of audit daemon stops: 2

 ---------------------- Selinux Audit End -------------------------


 --------------------- Init Begin ------------------------


 **Unmatched Entries**
 Disconnected from system bus
 Disconnected from system bus

 ---------------------- Init End -------------------------


 --------------------- Postfix Begin ------------------------

        3   Postfix start
        2   Postfix stop


 ---------------------- Postfix End -------------------------


 --------------------- Connections (secure-log) Begin ------------------------


 Root logins on tty's: 1 Time(s).

 **Unmatched Entries**
    useradd: failed adding user 'mysql', data deleted: 1 Time(s)

 ---------------------- Connections (secure-log) End -------------------------


 --------------------- SSHD Begin ------------------------


 SSHD Killed: 2 Time(s)

 SSHD Started: 6 Time(s)

 Users logging in through sshd:
    root:
       192.168.51.1: 3 times

 SFTP subsystem requests: 1 Time(s)

 **Unmatched Entries**
 Exiting on signal 15 : 1 time(s)

 ---------------------- SSHD End -------------------------


 --------------------- Disk Space Begin ------------------------

 Filesystem            Size  Used Avail Use% Mounted on
 /dev/mapper/VolGroup-lv_root
                        18G  9.2G  7.3G  56% /
 /dev/sda1             485M   95M  366M  21% /boot


 ---------------------- Disk Space End -------------------------


 ###################### Logwatch End #########################

[root@localhost ~]#
設定ファイルを確認
[root@localhost ~]# vim /etc/logwatch/conf/logwatch.conf
----
# Local configuration options go here (defaults are in /usr/share/logwatch/default.conf/logwatch.conf)
----

となっているので「/usr/share/logwatch/default.conf/logwatch.conf」の内容を確認し、ファイルを編集する

今回はメール先を変更
[root@localhost ~]# vim /etc/logwatch/conf/logwatch.conf
----
# Local configuration options go here (defaults are in /usr/share/logwatch/default.conf/logwatch.conf)

# メール送信
MailTo = hogehoge@test.com  ←ここに自身が受信するメールアドレスを設定

----
実際に送信
[root@localhost ~]# logwatch
[root@localhost ~]# 
1日ごとに実行してメールするようになっている
[root@localhost ~]# ll /etc/cron.daily/0logwatch
-rwxr-xr-x 1 root root 265  6月 25 19:17 2011 /etc/cron.daily/0logwatch
[root@localhost ~]#
メール内容(一部のみ)

f:id:m_shige1979:20131122144948j:plain

まとめ

これをVPSに実装したら覚えのないログインなどがわかるとのこと
未実装のVPSがある場合は対応する