10月 23

AWstats インストール

By ststyle AWstats, Watch コメントは受け付けていません。

AWstatsとはWebログを解析しグラフィカルに表示することの出来る

アクセス解析のフリーソフトです。

その他に似たような解析ものとしては

analog
Webalizer

などもあります。

事前準備

まず、apache のログ形式を調査します。

ログのフォーマットをcombinedにします


# vi /usr/local/apache/conf/httpd.conf

で apache の設定ファイルを開きます。
(VirtualHost を使用していない場合です。)

commonになっている場合は、以下のようにフォーマット形式を変更してください。


#CustomLog logs/access_log common
CustomLog /usr/local/apache/logs/access_log combined

AWstatsのソース取得

1. ソースディレクトリへ移動


# cd /usr/local/src

2. ソースをダウンロード


# wget http://nchc.dl.sourceforge.net/sourceforge/awstats/awstats-6.9.tar.gz

3. 取得したファイルを解凍


# tar zxvf awstats-6.9.tar.gz

4. 解凍したフォルダへ移動


# cd awstats-6.9/wwwroot

5. ディレクトリをapache の cgi が動作するフォルダへコピー。


# mkdir /usr/local/apache/cgi-bin/awstats
# cp -r icon /usr/local/apache/cgi-bin/awstats/
# cd cgi-bin
# cp -r * /usr/local/apache/cgi-bin/awstats/

6. コピーしたディレクトリへ移動


# cd /usr/local/apache/cgi-bin/awstats/

7. 設定ファイルの準備


# cp awstats.model.conf awstats.conf
# chmod 644 awstats.conf

8. 設定ファイルの編集


vi awstats.conf

#ログファイルの指定
apacheのログの場所を定義します。

LogFile="/var/log/httpd/mylog.log"
↓変更
LogFile="/usr/local/apache/logs/access_log"  ←利用環境に置き換えてください。

#ログの種類を指定 W はweb のログになります。
LogType=W

#ログフォーマット(apache で combined の場合は 1 を設定)
LogFormat = 1

#運用しているドメインを指定します。
SiteDomain="www.example.com"

#DNSの逆引きをする場合は1を設定
DNSLookup=1

#解析後のデータ格納ディレクトリ
DirData="."

#CGI設置場所の指定(cgi を実行するディレクトリ)
http://SiteDomain/以下で閲覧するパスの指定です。
DirCgi="/cgi-bin/awstats"

#アイコンの場所を指定
DirIcons="/cgi-bin/awstats/icon"

#年間表示する場合は3を設定
AllowFullYearView=3

#日本語で表示する場合
Lang="jp"

#解析対象外にするホストを指定します。
SkipHosts="192.168.0.1 10.0.0.1"

#解析対象外にするユーザエージェントを指定
SkipUserAgents="IE6″

#解析対象外にするファイルを指定
SkipFiles="/badpage.php /page.php?param=x"

手動で解析テスト


# /usr/local/apache/cgi-bin/awstats/awstats.pl -config=awstats.conf -update

Create/Update database for config "/usr/local/apache/cgi-bin/awstats/awstats.conf" by AWStats version 6.9 (build 1.925)
From data in log file "/usr/local/apache/logs/access_log"...
Phase 1 : First bypass old records, searching new record...
Direct access after last parsed record (after line 116)
Jumped lines in file: 116
Found 116 already parsed records.
Parsed lines in file: 51
Found 0 dropped records,
Found 0 corrupted records,
Found 0 old records,
Found 51 new qualified records.

[/bash]

解析結果をHTML出力


/usr/local/apache/cgi-bin/awstats/awstats.pl -config=awstats.conf -output -staticlink > /usr/local/apache/htdocs/awstats.html

WEBブラウザで確認(HTML出力版)

http://<WEBサーバ>/awstats.html

こんな感じで解析されたHTMLが表示されます。

awstats

WEBブラウザで確認(CGI版)

http://<WEBサーバ>/cgi-bin/awstats/awstats.pl

シェルを作成


#!/bin/bash
#-------------------------
# AWstats WEBログ解析
#
# @author Seiji Tsukioka
#-------------------------
PATH=/usr/local/apache/cgi-bin/awstats
OUTPUT=/usr/local/apache/htdocs
CONF_NAME=awstats.conf

$PATH/awstats.pl -config=$CONF_NAME -update
$PATH/awstats.pl -config=$CONF_NAME -output -staticlink &gt; $OUTPUT/awstats.html

Cronで定期実行する(ここでは30分おきに実施するようスケジュール)


# crontab -e
#AWstats::WEBログ解析
0,30 * * * * /root/bin/awstats.sh &gt; /root/bin/logs/awstats.log
Tagged with:
10月 22

net-snmp インストール

By ststyle Watch, net-snmp コメントは受け付けていません。

SNMPのインストール

「SNMP」とは「Simple Network Management Protocol」の略でルータやコンピュータなどの
様々な機器を監視、制御するためのプロトコルです。

SourceForgetから
net-snmp-5.1.2.tar.gzをDLします

http://sourceforge.net/project/showfiles.php?group_id=12694


$ tar xvzf net-snmp-5.4.1.2.tar.gz
$ cd net-snmp-5.4.1.2
$ ./configure
$ make
$ su
# make install

./configureの途中でSNMPのバージョンを

一番最初に問われるので ” v2 “ と入力し、(Enterでも良いです)
あとは全てEnterですっ飛ばします。

SNMP設定

デーモンの設定を行います

デフォルトの設定をコピーして、編集します。
編集すべき部分を矢印で示しますので、変更してください。


# cp EXAMPLE.conf /usr/local/share/snmp/snmpd.conf
# vi /usr/local/share/snmp/snmpd.conf

####
# First, map the community name (COMMUNITY) into a security name
# (local and mynetwork, depending on where the request is coming
# from):

# sec.name source community
→  com2sec local localhost private
→  #com2sec mynetwork XXX.XXX.XXX.0/24 public

####
# Second, map the security names into group names:

# sec.model sec.name
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyROGroup v1 local
group MyROGroup v2c local
group MyROGroup usm local

####
# Third, create a view for us to let the groups have rights to:

# incl/excl subtree mask
view all included .1 80

####
# Finally, grant the 2 groups access to the 1 view with different
# write permissions:

# context sec.model sec.level match read write notif
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none

###################################
# System contact information
#

# It is also possible to set the sysContact and sysLocation system
# variables through the snmpd.conf file. **PLEASE NOTE** that setting
# the value of these objects here makes these objects READ-ONLY
# (regardless of any access control settings). Any attempt to set the
# value of an object whose value is given here will fail with an error
# status of notWritable.

syslocation Right here, right now.
→  syscontact admin &lt;admin@server.jp&gt;

一番下に書いたsyscontactは各自、管理用のユーザ・アドレスに置き換えてください。

起動スクリプトの作成

「/etc/init.d/snmpd」として保存してください。


vi /etc/init.d/snmpd

#!/bin/bash
# ucd-snmp init file for snmpd
#
# chkconfig: - 50 50
# description: Simple Network Management Protocol (SNMP) Daemon
#
# processname: /usr/local/sbin/snmpd
# config: /usr/local/share/snmp/snmpd.conf
# pidfile: /var/run/snmpd

# source function library
. /etc/init.d/functions

OPTIONS="-Lsd -Lf /dev/null -p /var/run/snmpd -a"
RETVAL=0
prog="snmpd"

start() {
echo -n $"Starting $prog: "
if [ $UID -ne 0 ]; then
RETVAL=1
failure
else
daemon /usr/local/sbin/snmpd $OPTIONS
RETVAL=$?
[ $RETVAL -eq 0 ] &amp;&amp; touch /var/lock/subsys/snmpd
fi;
echo
return $RETVAL
}

stop() {
echo -n $"Stopping $prog: "
if [ $UID -ne 0 ]; then
RETVAL=1
failure
else
killproc /usr/local/sbin/snmpd
RETVAL=$?
[ $RETVAL -eq 0 ] &amp;&amp; rm -f /var/lock/subsys/snmpd
fi;
echo
return $RETVAL
}

reload(){
echo -n $"Reloading $prog: "
killproc /usr/local/sbin/snmpd -HUP
RETVAL=$?
echo
return $RETVAL
}

restart(){
stop
start
}

condrestart(){
[ -e /var/lock/subsys/snmpd ] &amp;&amp; restart
return 0
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
condrestart)
condrestart
;;
status)
status snmpd
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
RETVAL=1
esac

exit $RETVAL

(アンパサンド書き換えて三箇所)

権限付与と自動起動の設定

# cd /etc/init.d
# chmod 755 snmpd
# chkconfig --add snmpd
# chkconfig --level 2345 snmpd on

SNMPの実行


/etc/init.d/snmpd start
Tagged with:
10月 21

RRDTool+cacti インストール

By ststyle RRDTool, Watch, cacti コメントは受け付けていません。

RRDToolとはグラフを生成するためのものです.

主にcacti(かくたい)と組み合わせて利用し、

サーバのリソース監視をグラフィカルに行います。

以前はMRTGが主流?でしたが、現在はこちらが利用される事が多いようです。

いつものようにソースからコンパイルしてインストールしたいところですが、

RRDTool+catctiはモジュールの依存性が非常に高い為、

今回はお手軽にyumでインストールします。

リポジトリの設定

「RRDtool」、「Cacti」共にdagのリポジトリにあるので、
dagのパッケージを利用しインストールする。
なお、今後の競合を避ける為、基本的にdagのリポジトリは無効にし、
インストール時に一時的に有効にする。

○ ミラーサイト設定ファイルの編集

# vi /etc/yum.repos.d/CentOS-Base.repo
以下を追加
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://ftp.riken.jp/Linux/dag/redhat/el$releasever/en/$basearch/dag/
gpgcheck=1
enabled=0

■GPGキーのインポート

dagのリポジトリを利用する為にGPGキーをインポートする。

# wget http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt &lt;= GPGキーのダウンロード
# rpm --import RPM-GPG-KEY.dag.txt &lt;= GPGキーのインポート

■「RRDtool」のインストール

# yum -y install --enablerepo=dag rrdtool
# yum clean packages

■「Cacti」のインストール

「net-snmp-utils」を利用するので、
「net-snmp-utils」をインストール後、
「Cacti」をインストールする。

# yum -y install net-snmp-utils
# yum -y install --enablerepo=dag cacti
# yum clean packages

■「MySQL」の設定

mysql -u root -p
Enter password:<PASSWORD>

「cactiデータベースの作成」の設定

mysql&gt; create database cacti;

mysql&gt; show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| cacti              |
| db_nagiosql_v3     |
| mysql              |
| test               |
+--------------------+
5 rows in set (0.00 sec)

■「cactiteテーブルの作成」の設定


mysql -u root -p&lt;パスワード&gt; cacti &lt; /home/svmanager/cacti.sql

■「cactiteテーブルの確認」


mysql -u root -p&lt;パスワード&gt;
use cacti;
show tables;
mysql&gt; show tables;
+---------------------------+
| Tables_in_cacti           |
+---------------------------+
| cdef                      |
| cdef_items                |
| colors                    |
| data_input                |
| data_input_data           |
| data_input_fields         |
| data_local                |
| data_template             |
| data_template_data        |
| data_template_data_rra    |
| data_template_rrd         |
| graph_local               |
| graph_template_input      |
| graph_template_input_defs |
| graph_templates           |
| graph_templates_gprint    |
| graph_templates_graph     |
| graph_templates_item      |
| graph_tree                |
| graph_tree_items          |
| host                      |
| host_graph                |
| host_snmp_cache           |
| host_snmp_query           |
| host_template             |
| host_template_graph       |
| host_template_snmp_query  |
| poller                    |
| poller_command            |
| poller_item               |
| poller_output             |
| poller_reindex            |
| poller_time               |
| rra                       |
| rra_cf                    |
| settings                  |
| settings_graphs           |
| settings_tree             |
| snmp_query                |
| snmp_query_graph          |
| snmp_query_graph_rrd      |
| snmp_query_graph_rrd_sv   |
| snmp_query_graph_sv       |
| user_auth                 |
| user_auth_perms           |
| user_auth_realm           |
| user_log                  |
| version                   |
+---------------------------+
48 rows in set (0.00 sec)

■「cactiuserの作成&パスワード設定」


mysql -u root -p&lt;パスワード&gt;
grant all on cacti.* to cactiuser@localhost identified by 'CACTI-DBパスワード';

「Cacti」の設定


#vi /var/www/cacti/include/config.php
$database_password = "cactiuser";
↓
$database_password = "CACTI-DBパスワード";

「Apache」の設定

「Cacti」用のディレクトリにアクセス出来るよう、「Apache」を設定する。


# vi /etc/httpd/conf.d/cacti.conf &lt;= 設定ファイルの編集
Alias /cacti/ /var/www/cacti/
&lt;Directory /var/www/cacti/&gt;
DirectoryIndex index.php
Options -Indexes
AllowOverride all
order deny,allow
Allow from all
AddType application/x-httpd-php .php
php_flag magic_quotes_gpc on
php_flag track_vars on
&lt;/Directory&gt;

※セキュアにする場合はallow from 等で行う.
<h3>「Apache」の再起動</h3>




# /usr/local/apache/bin/apachectl  restart

データ収集のテスト


/usr/bin/php /var/www/cacti/poller.php

OK u:0.00 s:0.00 r:1.01
OK u:0.00 s:0.00 r:1.01
OK u:0.00 s:0.00 r:1.01
OK u:0.00 s:0.00 r:1.01
OK u:0.00 s:0.00 r:1.01
OK u:0.00 s:0.00 r:1.01
OK u:0.00 s:0.00 r:1.01

上記のように表示されればOKです.

「Cacti」の定期実行

デフォルトでcronにより定期的に実行される。

設定ファイルの確認


# cat /etc/cron.d/cacti
*/5 * * * *    cacti    php /var/www/cacti/poller.php &amp;&gt;/dev/null

「Cacti」のセットアップ

http://<サーバのIPアドレス>/cacti/
とアクセスすれば、「Cacti」の初期設定画面が表示される。

[Next] を押下

cacti-01

[New Install] を選択し、[Next]を押下.

cacti-02

実行環境を確認及び設定し[Finish] ボタンを押下

cacti-03

初期ログイン画面が表示されます。

UserName: admin

Password  : admin

を入力します。

cacti-04

パスワードを設定します。

cacti-05

トップメニューが表示されます。

あとは使い倒すだけです。

cacti-06

※監視するサーバにはnet-snmpをインストールし

snmpdを起動しておく事.

</p>
<p style="padding-left: 30px;">/etc/init.d/snmpd/ start</p>
<p style="padding-left: 30px;">chkconfig --add snmpd</p>
<p style="padding-left: 30px;">

Tagged with:
10月 19

Nagios インストール

By ststyle Nagios, Watch コメントは受け付けていません。

Nagios(なぎおす)とはオープンソースで開発されている

ネットワーク及び、サーバを監視するソフトウェアです。

Webブラウザからサーバやネットワークの状況を監視でき、異常があれば、メールを送信して

サーバ担当者やネットワーク担当者に状況を知らせる事ができます。

Nagiosの取得

公式サイト より本体・プラグインなどをダウンロードします。

今回は以下のファイルを取得しました。

nagios-3.1.0.tar.gz

nagios-plugins-1.4.14.tar.gz

nrpe-2.12.tar.gz (Nagios Remote Plugin Executor::リモートエージェント)

日本語化パッチも取得しておきます。

nagios-3.1.0-ja-utf8.patch.gz

※日本語パッチのバージョンとnagios本体のバージョンは必ずあわせておく!

事前準備

○apache と PHPをインストールしておく

○Nagiosの実行ユーザーの作成

useradd -d /usr/local/nagios -r nagios

展開


cd /usr/local/src
tar xvfz nagios-3.1.0.tar.gz

日本語化パッチ適用

# tar zxvf nagios-3.1.0.tar.gz
# cd nagios-3.1.0
# gzip -dc ../nagios-3.1.0-ja-utf8.patch.gz| patch -p0

展開&コンパイル&インストール


chown -R root.root nagios-3.1.0

cd nagios-3.2.0
./configure --prefix=/usr/local/nagios

*** Configuration summary for nagios 3.1.0 01-25-2009 ***:

General Options:
-------------------------
Nagios executable:  nagios
Nagios user/group:  nagios,nagios
Command user/group:  nagios,nagios
Embedded Perl:  no
Event Broker:  yes
Install ${prefix}:  /usr/local/nagios
Lock file:  ${prefix}/var/nagios.lock
Check result directory:  ${prefix}/var/spool/checkresults
Init directory:  /etc/rc.d/init.d
Apache conf.d directory:  /etc/httpd/conf.d
Mail program:  /bin/mail
Host OS:  linux-gnu

Web Interface Options:
------------------------
HTML URL:  http://localhost/nagios/
CGI URL:  http://localhost/nagios/cgi-bin/
Traceroute (used by WAP):  /bin/traceroute

Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.

#make all

Enjoy.

と表示された(よさそう)

以下を実施


make install
make install-init
make install-commandmode
make install-config

Web用ベーシック認証の作成 (.htaccess)

○.htaccessの設定

/usr/local/nagios/sbin/.htaccess

/usr/local/nagios/share/.htaccess を viで作成する。

内容は下記のようにし、両方の.htaccessは同じ内容でよい。


AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
require valid-user

○Nagios閲覧用ユーザーの作成(htpasswd)

※セキュリティを考慮するならばnagiosadminではなく、他の任意の名前を付けること。

(ファイル権限は644)


cd /usr/local/nagios/etc
/usr/local/apache/bin/htpasswd -c htpasswd.users nagios

Nagios Pluginのインストール


# cd /usr/local/src/
# tar zxvf nagios-plugins-1.4.14.tar.gz
# cd nagios-plugins-1.4.14
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios

サマリー表示


--with-apt-get-command:
--with-ping6-command:
--with-ping-command: /bin/ping -n -U -w %d -c %d %s
--with-ipv6: yes
--with-mysql: no
--with-openssl: yes
--with-gnutls: no
--enable-extra-opts: no
--with-perl: /usr/bin/perl
--enable-perl-modules: no
--with-cgiurl: /nagios/cgi-bin
--with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin

# make
# make install

Nagios設定ファイルの構文チェック

設定ファイルを修正する度に、エラーが無いか確認しましょう


<code>/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg</code>

Total Warnings: 0
Total Errors:   0

Nagios 自動起動設定


# chkconfig --add nagios
# chkconfig nagios on
# chkconfig --list nagios

Nagiosの起動


# service nagios start

Apacheの設定

httpd.confの編集(一番最後にでも追記)


vi /usr/local/apache/conf/httpd.conf

#nagios begin
ScriptAlias /nagios/cgi-bin/ /usr/local/nagios/sbin/
&lt;Directory "/usr/local/nagios/sbin/"&gt;
AllowOverride AuthConfig
Options ExecCGI
Order allow,deny
Allow from all
&lt;/Directory&gt;

Alias /nagios/ /usr/local/nagios/share/
&lt;Directory "/usr/local/nagios/share"&gt;
AllowOverride AuthConfig
Options None
Order allow,deny
Allow from all
&lt;/Directory&gt;
#nagios end

Apacheの再起動

apacheを再起動します。


/usr/local/apache/bin/apachectl restart

Webブラウザへアクセス

http://<Nagiosサーバ>/nagios/ へアクセスします。

ベーシック認証が無事に行われるとNagiosの画面が表示されます。

nagios

あとはNagiosの面倒くさい設定ファイルをいじっていくだけですが、

その面倒を解消してくれるすばらしいツールがあります.

NagiosQLです。

これまでにも何回かNagiosを立てた事はありますが、

その設定ファイルの面倒さに苦労していました。

そこにGUIで設定がNagiosQLの登場です。

素敵です。

使わない手はありません。

CGI関連でエラーが出る場合の対処方法

要求したサービスを閲覧する権限が無いようです。
このメッセージが何らかのエラーである場合はHTTPサーバのこのCGIに対するアクセス権限の設定かNagiosのCGI用設定ファイルの認証に関するオプションを調べてみてください

Nagiosのサブメニューを起動したときに上記メッセージが表示された場合は以下のように対応

use_authenticationを ‘0 ‘ に修正


vi /usr/local/nagios/etc/cgi.cfg

#use_authentication=1
use_authentication=0

でnagiosを再起動


service nagios restart

アイコンのインストール


$ tar zxvf  imagepak-base.tar.gz
$ cd base/
$ chown nagios:nagios *
$ cp -p * /usr/local/nagios/share/images/logos

Tagged with:
preload preload preload