#author("2018-04-13T09:50:01+09:00","default:zzr12000","zzr12000") * [[ログ]] [#k95e4376] 各種ログの参照の仕方を記述しておきます。詳細は/etc/syslog.confに記述されているので、こちらを参照しながら、ログの場所を確認します。またこのファイルにはファシリティ(プログラムの種類)+プライオリティ(メッセージの優先度(log4jのinfo見たいなやつ)+保存場所で記述されているので、プライオリティ毎にどこに書かれているかを確認して、調べていきましょう。またログはほっとけばどんどん大きくなるのですが、/etc/logrotate.confを参照してみてください。設定は、 weekly rotate 4 とあれば、週1回でローテートし、4週間保存することになる。また#compressとある場合、コメント#をとれば圧縮して、保存してくれる。 #contents ** boot [#z4b975e8] ブート時のログです。またdmesgも参考にしましょう。 /var/log/boot ** cron [#q208b55c] cronの実行ログです。 /var/log/cron ** wtmp [#q7ca0cf8] 最近ログインしたユーザ情報のログです。バイナリであるため、lastコマンドを使います。/var/log/wtmpにあるファイルをしているするか、 last -f wtmp.2 この-fでファイルを指定できます。特定のユーザだけの場合は、 last xxxuser とします。 ** lastlog [#v71c1824] ユーザ毎に最後にログインした日時やIPを表示する。実行は、 lastlog とする。bsdはlast ** secure [#yb7473c4] システムのログイン等承認関係のログです。ftpやcvs,swat等の承認ログが落ちてます。 /var/log/secure ** messages [#qf6d3d61] 専用のログファイルをもたないプログラムがこのファイルにログが残ってます。 /var/log/messages ** samba [#y69306ee] sambaのログです。 /var/log/samba ** mail [#v680cb20] mailのログです。 /var/log/maillog http://man.qmail.jp/jman5/qmail-log.html~ **logrotate [#n8a7c213] どんどん大きくなるログをローテーションします。/etc/cron.daily/logrotateで動いてました。ではデフォルトの設定のままではなんですので、いろいろと設定してみましょう。 # see "man logrotate" for details # rotate log files weekly 他にdaily,monthly weekly #毎週ローテイション # keep 4 weeks worth of backlogs rotate 4 #4回ローテーションする 1,2,3,4,1,2,3,4,1.... # create new (empty) log files after rotating old ones create #空のログファイルを作成 # packages drop log rotation information into this directory include /etc/logrotate.d #/etc/logrotate.dの設定ファイルをインクルード では/etc/logrotate.dにあるhttpdを見てみましょう。 /var/log/httpd/*log { missingok <-ログファイルが存在しなくてもエラーを出さない。 notifempty <-ログファイルが空ならローテーションしない。 sharedscripts <-複数指定したログファイルに対してpostrotateまたはprerotateで記述されたコマンドを実行する。 postrotate <-ログローテーション後に実行する。prerotateは前。 /bin/kill -HUP `cat /usr/local/apache2/logs/httpd.pid 2>/dev/null` 2>/dev/null || true endscript } 結果は/var/lib/logrotate.statusを参照します。 apacheにはrotatelogsというものがあるのですが、ログファイルは消されるまで残ります。またローテイト後のログファイルはクリアしないらしいです。 ** Logwatch [#v99f6851] ログ監視ツールです。http://www.logwatch.org/からlogwatch-5.2.2.tar.gzをダウンロードしました。 tar xzvf logwatch-5.2.2.tar.gz mkdir /etc/log.d cp -r logwatch-5.2.2/scripts/ /etc/log.d/ cp -r logwatch-5.2.2/lib/ /etc/log.d/ cp -r logwatch-5.2.2/conf/ /etc/log.d/ ln -s /etc/log.d/scripts/logwatch.pl /etc/cron.daily/ SUSEでは、めんどくさかったので、 yast -i logwatch これはcronで1日1回実行されます。いつ実行されるかは/etc/crontabを見てください。では設定ファイルを見ていきましょう。 /etc/log.d/conf/logwatch.confです。/etc/log.dがないときは/etc/logwatchや、/usr/share/logwatch/default.confを探してみます。 |LogDir|パス|ログのディレクトリです。| |TmpDir|パス|Tmpのディレクトリです。| |Print|yes,no|yesの場合、標準出力に表示。noの場合、メールで| |MailTo|email|通知先のメールアドレスです。複数の場合は、スペースを空けます。| |mailer|パス|メールのコマンドの場所| |Range|All,Yesterday,Today|All:すべてのログ,Yesterday:昨日だけ,Today:今日だけ| さてlogwatch.plを実行してみましょう。だめです。メールが送れません。qmailなんですが、どうもこれは、sendmail用みたいです(-sオプションがついてしまうようです)。ではlogwatch.plをなおしましょう。676行目あたりでメールを送信しています。その上を見てみるとSolaris用のプログラムがつかえそうなので、同じようにしてやります。またmailerは, mailer = /var/qmail/bin/qmail-inject としておいて、665行目から672行目をコピーして置き換えました。/etc/log.d/scripts/servicesにいろいろと各プログラム用の設定がありますので、一度見てみてください。 6.0.2が出ていたので、置き換えました。今度は749行目から置き換えてやりました。 7.1が出ていたので、インストールしました。 どうも今回は設定ファイルの場所がデフォルト用とカスタマイズ用に分かれているようです。READMEに従い、(7.3.6) mkdir /etc/logwatch mkdir /etc/logwatch/scripts mkdir /etc/logwatch/conf mkdir /etc/logwatch/conf/logfiles mkdir /etc/logwatch/conf/services touch /etc/logwatch/conf/logwatch.conf touch /etc/logwatch/conf/ignore.conf touch /etc/logwatch/conf/override.conf mkdir /usr/share/logwatch mkdir /usr/share/logwatch/dist.conf mkdir /usr/share/logwatch/dist.conf/logfiles mkdir /usr/share/logwatch/dist.conf/services mv conf/ /usr/share/logwatch/default.conf mv scripts/ /usr/share/logwatch/scripts mv lib /usr/share/logwatch/lib mkdir /var/cache/logwatch ln -s /usr/share/logwatch/scripts/logwatch.pl /etc/cron.daily/0logwatch ln -s /usr/share/logwatch/scripts/logwatch.pl /usr/sbin/logwatch ** Logsurfer [#pad2ad30] ログのリアルタイム監視をするツールです。swatchよりいいとのことなので、いれてみます。ただ開発が停止しているようです。では早速いれてみましょう。http://www.cert.dfn.de/eng/logsurf/からダウンロードします。 wget ftp://ftp.cert.dfn.de/pub/tools/audit/logsurfer/logsurfer-1.5b.tar tar xvf logsurfer-1.5b.tar cd logsurfer-1.5b ./configure make make install ** リンク [#l8dfcda1] [[rsyslogの導入>http://www.atmarkit.co.jp/flinux/rensai/newlog04/newlog04a.html]] ** 参考書籍 [#m1633bfe] [[Linuxインターネットサーバ構築ガイド>http://www.amazon.co.jp/exec/obidos/ASIN/4756144403/worried-22]]~ [[SoftwareDesign2005年2月号>http://www.gihyo.co.jp/magazines/SD]]~ ** コメント [#vd6a28f5] -#comment