通常、Centosの標準では、syslogd というログ管理のシステムが入っており、このデーモンが各プログラムからログを集めては、/var/log 以下のフォルダにlogを記録していきます。
# vi /etc/logrotate.d/nginx /www/log/nginx/*log { daily rotate 10 missingok notifempty compress sharedscripts postrotate [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid` endscript }
syslog-ngとは、syslogの代わりに以下の機能を持ったログ管理デーモンです。
GLIBのインストールを行います。
# yum install glib2-devel
pkg-configをインストール
# wget http://pkgconfig.freedesktop.org/releases/pkg-config-0.23.tar.gz # tar zxvf pkg-config-0.23.tar.gz # cd pkg-config-0.23 # ./configure # make # make install
最初にeventLogをインストールします。
# wget http://www.balabit.com/downloads/files/syslog-ng/sources/stable/src/eventlog-0.2.7.tar.gz # tar zxvf eventlog-0.2.7.tar.gz # cd eventlog-0.2.7 # ./configure # make # make install
syslogdのインストールを行います。
# wget http://www.balabit.com/downloads/files/syslog-ng/sources/stable/src/syslog-ng-2.0.9.tar.gz # tar zxvf syslog-ng-2.0.9.tar.gz # cd syslog-ng-2.0.9 # ./configure --sysconfdir=/etc/syslog-ng # make # make install
# cd /usr/local/src/syslog-ng-2.0.9/contrib/rhel-packaging # cp syslog-ng.init /etc/rc.d/init.d/syslog-ng # cp syslog-ng.conf /etc # chmod 755 /etc/init.d/syslog-ng # chkconfig --add syslog-ng # chkconfig syslog-ng on # groupadd syslog # useradd -g syslog -d /var/syslog -s /bin/false syslog
# emacs /etc/syslog-ng.conf
# syslog-ng -s <- config file のチェック
# service syslogd stop # service syslog-ng start # chkconfig syslogd off # chkconfig --del syslogd
サーバへのログインログを確認する簡単な方法は、lastか whoコマンドで確認することだ。(表示する内容は同じ)
# last # who /vat/log/wtmp
このコマンドによって、直近のログイン履歴を確認することができる。また他のユーザーのログイン履歴をみる場合には、lastlogコマンドを利用する。
# lastlog
パラメータ | 内容 |
%b | そのリクエストで行われたデータの転送量(bytes) |
%f | リクエストされた仮想ディレクトリ+ファイル名 |
%{Foobar}e | 環境変数(Foobarで指定したもの)の内容 |
%h | リクエストしたコンピュータの名称またはIPアドレス |
%a | リクエストしたコンピュータのIPアドレス |
%{Foobar}i | リクエストヘッダ(Foobarで指定したもの)の内容 |
%l | リモートログ名(identdをクライアントがサポートしているとき) |
%{Foobar}n | ほかのモジュールからのノート(Foobarで指定したもの)の内容 |
%{Foobar}o | レスポンスヘッダ(Foobarで指定したもの)の内容 |
%p | リクエストを受けたポート番号 |
%P | リクエストを受けたApacheのプロセス番号(PID) |
%r | リクエストの最初の行 |
%s | リクエストに対するHTTPのステータスコード(下記参照) |
%t | リクエスト時間(day/month/%h:%T zone) |
%{文字列フォーマット}t | リクエスト時間(STRFTIME関数フォーマット参照) |
%T | リクエスト処理時間(秒) |
%u | クライアント側のユーザー名 |
%U | リクエストされたURLパス |
%v | サーバがリクエストを処理する正統なServerName |
%V | UseCanonicalNameの設定によるサーバ名 |
カテゴリ | コード | 内容 |
情報 | 100 | Continue |
101 | Switching Protocols | |
成功 | 200 | OK |
201 | Created | |
202 | Accepted | |
203 | Non-Authoritative Information | |
204 | No Content | |
205 | Reset Content | |
206 | Partial Content | |
転送 | 300 | Multiple Choices |
301 | Moved Permanently | |
302 | Moved Temporarily | |
303 | See Other | |
304 | Not Modified | |
305 | Use Proxy | |
エラー(アクセスする側の問題) | 400 | Bad Request |
401 | Unauthorized | |
402 | Payment Required | |
403 | Forbidden | |
404 | Not Found | |
405 | Method Not Allowed | |
406 | Not Acceptable | |
407 | Proxy Authentication Required | |
408 | Request Time-out | |
409 | Conflict | |
410 | Gone | |
411 | Length Required | |
412 | Precondition Failed | |
413 | Request Entity Too Large | |
414 | Request-URI Too Large | |
415 | Unsupported Media Type | |
エラー(アクセスされる側の問題) | 500 | Internal Server Error |
501 | Not Implemented | |
502 | Bad Gateway | |
503 | Service Unavailable | |
504 | Gateway Time-out | |
505 | HTTP Version not supported |
Logデータをデータベースに更新するソフト。
# wget http://ftp.de.debian.org/debian/pool/main/u/ulogd/ulogd_1.24.orig.tar.gz # tar zxvf ulogd_1.24.orig.tar.gz # cd ulogd_1.24 # ./configure --with-pgsql=/usr/local/pgsql --sysconfdir=/etc # make # make install # cp ulogd.init /etc/rc.d/init.d/ulogd # cp ulogd /usr/sbin/ulogd
# emacs /etc/ulogd.conf plugin="/usr/local/lib/ulogd/ulogd_LOCAL.so" <- add #plugin="/usr/local/lib/ulogd/ulogd_LOGEMU.so" <- comment plugin="/usr/local/lib/ulogd/ulogd_PGSQL.so" <- enable [PGSQL] table="log" schema="public" pass="ulog" user="ulog" db="ulog" host="localhost"
# chkconfig --add ulogd # chkconfig ulogd on # service ulogd start
次の1行を追加。
# emacs /etc/sysconfig/iptables iptables -A INPUT -m limit --limit 1/s -j ULOG --ulog-nlgroup 1 --ulog-prefix 'INPUT'
ULOGD ProjectPage
iptables と ulogd
http://www.netfilter.org/
Netfilter iptables のオフィシャルサイト。Linux で iptables および Netfilter をセットアップしようとするすべての人にとって必見。