カテゴリー
Linux

Logwatch導入でサーバの状態を定期チェックするよ!+ Evernoteも!

といっても、ログをメールしてくれるだけで、それをチェックしないと全く意味ないですけどね。今回は、Logwatch をインストールしてさらに、その結果を Evernote のノートとしてに自動的に反映させてみたいと思います。Evernote はよくいじるので定期的にチェックするはず。。。

次のページが参考になりました。ありがとうございます。

ちなみに、本家サイトのLogwatch – Browse Files at SourceForge.netはあまり参考にならなかったです。残念です。

環境の確認

  • OS
    cat /etc/redhat-release
    CentOS release 5.7 (Final)

インストール

yum install logwatch
Loaded plugins: fastestmirror
Repository 'vz-base' is missing name in configuration, using id
Repository 'vz-updates' is missing name in configuration, using id
Loading mirror speeds from cached hostfile
 * base: rsync.atworks.co.jp
 * epel: ftp.iij.ad.jp
 * extras: rsync.atworks.co.jp
 * remi: rpms.famillecollet.com
 * rpmforge: ftp-stud.fht-esslingen.de
 * updates: rsync.atworks.co.jp
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package logwatch.noarch 0:7.3-9.el5_6 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================================
 Package                             Arch                              Version                                  Repository                       Size
======================================================================================================================================================
Installing:
 logwatch                            noarch                            7.3-9.el5_6                              base                            244 k

Transaction Summary
======================================================================================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 244 k
Is this ok [y/N]: y
Downloading Packages:
logwatch-7.3-9.el5_6.noarch.rpm                                                                                                | 244 kB     00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : logwatch                                                                                                                       1/1

Installed:
  logwatch.noarch 0:7.3-9.el5_6

Complete!

設定。ここで Evernote に自動的にノートされるようにします。

デフォルト設定からの変更点を次のファイルに記述していきます。今回のポイントである、Evernote のノートとして自動的に反映させるためには「ノートのメール先」をメール送信先に設定します。これだけです。簡単ですね。なお、「ノートのメール先」は次の方法で確認できます。

【デスクトップ版】

  • ソフトを立ち上げ、上部にある使用量 > アカウント情報ウィンドウが開く > ノートのメール先
では実際に編集していきます。ちなみに、設定のメールアドレスはダミーですのであしからず。
vim /etc/logwatch/conf/logwatch.conf
# Local configuration options go here (defaults are in /usr/share/logwatch/default.conf/logwatch.conf)

# Local configuration options go here (defaults are in /usr/share/logwatch/default.conf/logwatch.conf)
MailTo = XXXXXX.9999x@m.evernote.com

覚えておいたほうがよいことまとめ

  • LogWatch の設定ファイル
    /usr/share/logwatch/default.conf/logwatch.conf
  • LogWatch の実行スクリプト(配信テストができる)
    /usr/share/logwatch/scripts/logwatch.pl
  • LogWatch テスト。コマンドライン上にメールで送る内容を表示する。–range all  ですべての内容を表示させる。
    /usr/share/logwatch/scripts/logwatch.pl –range all –print
  • Logwatch を一日一回行うシンボリックリンク
    /etc/cron.daily/0logwatch

    ll /etc/cron.daily/
    合計 20
    lrwxrwxrwx 1 root root  39  2月 27 23:31 0logwatch -> /usr/share/logwatch/scripts/logwatch.pl
    ・・・略・・・

    ※ /etc/cron.daily 以下に Logwatch を一日一回行うシンボリックリンクが出来ます(メール配信時間を変更したい場合は /etc/crontab を編集するらしいです)。

テスト

  1. 全ログをコマンドラインに表示してみます。
  2. ログメールを送信してみます。

1.全ログをコマンドラインに表示してみます。

/usr/share/logwatch/scripts/logwatch.pl --range all --print

 ################### Logwatch 7.3 (03/24/06) ####################
        Processing Initiated: Tue Feb 28 00:08:33 2012
        Date Range Processed: all
      Detail Level of Output: 0
              Type of Output: unformatted
           Logfiles for Host: oki2a24.com
  ##################################################################

 --------------------- httpd Begin ------------------------

 Requests with error response codes
    404 Not Found
       /MyAdmin/scripts/setup.php: 1 Time(s)
       /PMA2005/scripts/setup.php: 1 Time(s)
       /admin/phpmyadmin/scripts/setup.php: 1 Time(s)
       /admin/scripts/setup.php: 1 Time(s)
       /appConf.htm: 1 Time(s)
       /db/scripts/setup.php: 1 Time(s)
       /dbadmin/scripts/setup.php: 1 Time(s)
       /myadmin/scripts/setup.php: 1 Time(s)
       /mysql-admin/scripts/setup.php: 1 Time(s)
       /mysqladmin/scripts/setup.php: 2 Time(s)
       /mysqlmanager/scripts/setup.php: 1 Time(s)
       /php-my-admin/scripts/setup.php: 2 Time(s)
       /php-myadmin/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.2.3/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.2.6/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.5.1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.5.4/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.5.5-pl1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.5.5-rc1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.5.5-rc2/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.5.5/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.5.6-rc1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.5.6-rc2/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.5.7-pl1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.5.7/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.0-alpha/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.0-alpha2/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.0-beta1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.0-beta2/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.0-pl1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.0-pl2/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.0-pl3/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.0-rc1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.0-rc3/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.0/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.1-pl1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.1-pl2/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.1-pl3/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.1-rc1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.1-rc2/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.2-beta1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.2-pl1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.3-pl1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.3-rc1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.3/scripts/setup.php: 2 Time(s)
       /phpMyAdmin-2.6.4-pl1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.4-pl2/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.4-pl3/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.4-rc1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.6.4/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.7.0-beta1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.7.0-pl1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.7.0-pl2/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.7.0-rc1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.7.0/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.8.0-beta1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.8.0-rc2/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.8.0.1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.8.0.3/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.8.0.4/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.8.0/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.8.1-rc1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.8.1/scripts/setup.php: 1 Time(s)
       /phpMyAdmin-2.8.2/scripts/setup.php: 1 Time(s)
       /phpMyAdmin/scripts/setup.php: 2 Time(s)
       /phpadmin/scripts/setup.php: 1 Time(s)
       /phpmanager/scripts/setup.php: 1 Time(s)
       /phpmy-admin/scripts/setup.php: 1 Time(s)
       /phpmyadmin/scripts/setup.php: 3 Time(s)
       /phpmyadmin1/scripts/setup.php: 1 Time(s)
       /phpmyadmin2/scripts/setup.php: 1 Time(s)
       /pma/scripts/setup.php: 1 Time(s)
       /pma2005/scripts/setup.php: 1 Time(s)
       /scripts/setup.php: 1 Time(s)
       /sqlmanager/scripts/setup.php: 1 Time(s)
       /sqlweb/scripts/setup.php: 1 Time(s)
       /typo3/phpmyadmin/scripts/setup.php: 1 Time(s)
       /w00tw00t.at.blackhats.romanian.anti-sec:): 2 Time(s)
       /web/phpMyAdmin/scripts/setup.php: 1 Time(s)
       /web/scripts/setup.php: 1 Time(s)
       /webadmin/scripts/setup.php: 1 Time(s)
       /webdb/scripts/setup.php: 1 Time(s)
       /websql/scripts/setup.php: 2 Time(s)
       /xampp/phpmyadmin/scripts/setup.php: 1 Time(s)

 ---------------------- httpd End -------------------------

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

 Re-execs of init: 1 times

 **Unmatched Entries**
 no more processes left in this runlevel

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

 --------------------- pam_unix Begin ------------------------

 su:
    Sessions Opened:
       oki2a24(uid=500) -> root: 1 Time(s)

 su-l:
    Unknown Entries:
       session opened for user root by oki2a24(uid=0): 1 Time(s)

 ---------------------- pam_unix End -------------------------

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

 SSHD Killed: 1 Time(s)

 SSHD Started: 1 Time(s)

 Users logging in through sshd:
    oki2a24:
       114.18.233.53 (KD114018233053.ppp-bb.dion.ne.jp): 1 time

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

 --------------------- yum Begin ------------------------

 Packages Installed:
    libc-client-2004g-2.2.1.i386
    httpd-devel-2.2.3-53.el5.centos.3.i386
    php-common-5.1.6-27.el5_5.3.i386
    php-devel-5.3.9-1.el5.remi.i386
    mysqlclient15-5.0.67-1.el5.remi.i386
    nkf-2.07-1.1.fc6.i386
    xorg-x11-filesystem-7.1-2.fc6.noarch
    imake-1.0.2-3.i386
    libXmu-1.0.2-5.i386
    libaio-0.3.106-5.i386
    php-pdo-5.3.9-1.el5.remi.i386
    php-5.1.6-27.el5_5.3.i386
    openldap-devel-2.3.43-12.el5_7.10.i386
    libXext-1.0.1-2.1.i386
    mysql-5.5.20-1.el5.remi.i386
    mysql-server-5.5.20-1.el5.remi.i386
    php-gd-5.3.9-1.el5.remi.i386
    libgomp-4.4.4-13.el5.i386
    freetype-2.2.1-28.el5_7.2.i386
    glibc-headers-2.5-65.el5_7.1.i386
    mysql-5.5.19-1.el5.remi.i386
    cyrus-sasl-devel-2.1.22-5.el5_4.3.i386
    1:php-pear-1.9.4-3.el5.remi.noarch
    php-mcrypt-5.3.9-1.el5.remi.i386
    logwatch-7.3-9.el5_6.noarch
    mysql-libs-5.5.19-1.el5.remi.i386
    php-imap-5.3.9-1.el5.remi.i386
    libXau-1.0.1-3.1.i386
    cpp-4.1.2-51.el5.i386
    libtool-ltdl-1.5.22-7.el5_4.i386
    libXaw-1.0.2-8.1.i386
    php-cli-5.1.6-27.el5_5.3.i386
    libXpm-3.5.5-3.i386
    libSM-1.0.1-3.1.i386
    libICE-1.0.1-2.1.i386
    automake-1.9.6-2.3.el5.noarch
    apr-util-devel-1.2.7-11.el5_5.2.i386
    db4-devel-4.3.29-10.el5_5.2.i386
    iptables-1.3.5-5.3.el5_4.1.i386
    apr-devel-1.2.7-11.el5_6.5.i386
    perl-DBI-1.52-2.el5.i386
    perl-DBD-MySQL-3.0007-2.el5.i386
    gmp-4.1.4-10.el5.i386
    libXdmcp-1.0.1-2.1.i386
    php-mysql-5.3.9-1.el5.remi.i386
    expat-devel-1.95.8-8.3.el5_5.3.i386
    libXt-1.0.2-3.2.el5.i386
    kernel-headers-2.6.18-274.17.1.el5.i386
    1:pkgconfig-0.21-2.el5.i386
    gcc-4.1.2-51.el5.i386
    php-mbstring-5.3.9-1.el5.remi.i386
    libedit-20090923-3.0_1.el5.rf.i386
    autoconf-2.59-12.noarch
    t1lib-5.1.2-1.el5.rf.i386
    libmcrypt-2.5.8-4.el5.centos.i386
    libX11-1.0.3-11.el5_7.1.i386
    glibc-devel-2.5-65.el5_7.1.i386

 Packages Updated:
    mysql-libs-5.5.21-1.el5.remi.i386
    denyhosts-2.6-5.el5.noarch
    glibc-2.5-65.el5_7.3.i686
    php-devel-5.3.10-2.el5.remi.i386
    glibc-headers-2.5-65.el5_7.3.i386
    php-gd-5.3.10-2.el5.remi.i386
    nscd-2.5-65.el5_7.3.i386
    php-pdo-5.3.10-2.el5.remi.i386
    libxml2-2.6.26-2.1.12.el5_7.2.i386
    mysql-libs-5.5.20-1.el5.remi.i386
    php-cli-5.3.10-2.el5.remi.i386
    kernel-headers-2.6.18-274.18.1.el5.i386
    mysql-5.5.21-1.el5.remi.i386
    glibc-common-2.5-65.el5_7.3.i386
    php-imap-5.3.10-2.el5.remi.i386
    php-5.3.9-1.el5.remi.i386
    php-mysql-5.3.10-2.el5.remi.i386
    2:libpng-1.2.10-15.el5_7.i386
    mysql-server-5.5.21-1.el5.remi.i386
    php-5.3.10-2.el5.remi.i386
    lvm2-2.02.84-6.el5_7.2.i386
    glibc-devel-2.5-65.el5_7.3.i386
    php-common-5.3.10-2.el5.remi.i386
    openssl-0.9.8e-20.el5_7.1.0.1.centos.i686
    php-cli-5.3.9-1.el5.remi.i386
    rpmforge-release-0.5.2-2.el5.rf.i386
    php-mcrypt-5.3.10-2.el5.remi.i386
    php-common-5.3.9-1.el5.remi.i386
    php-mbstring-5.3.10-2.el5.remi.i386

 Packages Erased:
    mysql
    iptables

 ---------------------- yum End -------------------------

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

 Filesystem            Size  Used Avail Use% Mounted on
 /dev/simfs             10G  950M  9.1G  10% /

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

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

2.ログメールを送信してみます。

/usr/share/logwatch/scripts/logwatch.pl

無事に Evernote のノートとしてメールが自動的に届きました。

Logwatch for oki2a24.com (Linux) - Evernote 20120228 02853.jpg

最後に、今後の改善点

「Logwatch導入でサーバの状態を定期チェックするよ!+ Evernoteも!」への1件の返信

コメントを残す