Nagios 2.11 の導入+日本語化

nagiosはサーバやネットワークを監視したりできるかなり便利な機能を提供してくれるアプリケーションです。
Nagiosも他のアプリケーションと同様にPortsで提供されてはいるのですが、新しいバージョンが出ても直ぐには更新されないというのと英語が苦手な私には必須の日本語化が出来てなかったりしますので手動でのインストールする方法を記載しています。
大まかな流れとしては本家からNagios本体のアーカイブと、日本語化を支援しているサイトからパッチを取ってきて行うようになりますが、とりあえず導入のみに絞っているため運用に関する設定は省略しています。

作成日:2008.3.16
更新日:2008.3.29

前提条件
これを行ったときの環境を以下のようにしています。
■環境
・nagios-2.11.tar.gz :Nagios本体
・nagios-2.11-ja.patch :日本語パッチ
・Apache2.2.x

■パラメータ
・作業場所 :/tmp
・Webデータ :/usr/local/www/nagios
・Nagiosユーザ :nagios
・Nagiosグループ :nagios
・コマンド実行ユーザ :nagios
・コマンド実行グループ :www
・設定ファイル :/usr/local/etc/nagios

ApacheをSuEXECで実行している場合はWebデータのインストール先やNagiosユーザ作成時のIDなどを適切に設定しておかないと実行時に内部エラーになりますので気をつけてください。

ページのトップへ

インストール
まず、インストールに必要なファイルをサイトからダウンローしてFTPかSSHで作業用ディレクトリに入れます。

Nagios本体 nagios-2.11.tar.gz
日本語パッチ nagios-2.11-ja.patch

次はNagiosの実行に必要なアカウントの作成やインストール先のディレクトリの用意などを行います。
(色分け:入力値コマンドラインコメント)
アカウントの作成
# adduser

Username: nagios
Full name: Nagios User
Uid (Leave empty for default): 
Login group [vmail]:
Login group is  mailuser. Invite mailuser into other groups:
Login class [default]:
Shell (sh csh tcsh nologin) [sh]: nologin
Home directory [/home/mailuser]: /usr/local/www/nagios
Use password-based authentication? [yes]:
Use an empty password? (yes/no) [no]:
Use a random password? (yes/no) [no]:
Enter password: *******
Enterpassword again: *******
Lock out the account after creation? [no]:

データのインストール先ディレクトリの作成
# mkdir /usr/local/www/nagios

所有者情報の変更
# chown nagios.nagios /usr/local/www/nagios

グループの追加
# usermod -G www nagios

次はインストールを行っていきま。
(色分け:入力値コマンドラインコメント)
作業ディレクトリへ移動して圧縮ファイルを解凍・展開する
# cd /tmp
# tar -xzf nagios-2.11.tar.gz

パッチファイルをコピー
# cp nagios-2.11-ja.patch ./nagios-2.11

展開先へ移動
# cd nagios-2.11

パッチの適用
# patch < nagios-2.11-ja.patch

Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|diff -Nnaur cgi/avail.c.orig cgi/avail.c 
|--- cgi/avail.c.orig   Sun Jan 13 01:26:21 2008
|+++ cgi/avail.c        Sun Jan 13 00:51:54 2008
--------------------------
Patching file cgi/avail.c using Plan A...
Hunk #1 succeeded at 384.
Hunk #2 succeeded at 408.
Hunk #3 succeeded at 453.
Hunk #4 succeeded at 522.
Hunk #5 succeeded at 585.
Hunk #6 succeeded at 637.
Hunk #7 succeeded at 655.
Hunk #8 succeeded at 705.
Hunk #9 succeeded at 735.
Hunk #10 succeeded at 747.
Hunk #11 succeeded at 829.
Hunk #12 succeeded at 838.
Hunk #13 succeeded at 848.
Hunk #14 succeeded at 859.
Hunk #15 succeeded at 868.
Hunk #16 succeeded at 878.
Hunk #17 succeeded at 886.
Hunk #18 succeeded at 900.
Hunk #19 succeeded at 910.
Hunk #20 succeeded at 940.
こんな感じでsucceededが表示されていれば大丈夫です。


初期設定(実際は一行で記述します)
# ./configure --prefix=/usr/local \ --with-cgiurl=/nagios/cgi-bin \ --with-htmlurl=/nagios \ --with-nagios-user=nagios \ --with-nagios-group=nagios \ --with-command-user=nagios \ --with-command-group=www \ --sbindir=/usr/local/www/nagios/cgi-bin \ --libexecdir=/usr/local/libexec/nagios \ --datadir=/usr/local/www/nagios \ --sysconfdir=/usr/local/etc/nagios \ --localstatedir=/var/spool/nagios \ --with-perlcache \ --enable-embedded-perl \ CFLAGS="-I/usr/local/include -fPIC" \ LIBS="-L/usr/local/lib" \
config.status: creating include/nagios.h
config.status: creating include/cgiutils.h
config.status: include/cgiutils.h is unchanged

Creating sample config files in sample-config/ ...


*** Configuration summary for nagios 2.11 03-12-2008 ***:

 General Options:
 -------------------------
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagios
            Embedded Perl:  yes, with caching
             Event Broker:  yes
        Install ${prefix}:  /usr/local
                Lock file:  /var/spool/nagios/nagios.lock
           Init directory:  /usr/local/etc/rc.d
  Apache conf.d directory:  /etc/httpd/conf.d
                  Host OS:  freebsd6.0

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


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


エラーがなければmake
# make all

*** Compile finished ***

If the main program and CGIs compiled without any errors, you
can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):

この時点で表示される後作業
  make install
     - This installs the main program, CGIs, and HTML files

  make install-init
     - This installs the init script in /usr/local/etc/rc.d

  make install-commandmode
     - This installs and configures permissions on the
       directory for holding the external command file

  make install-config
     - This installs *SAMPLE* config files in /usr/local/etc/nagios
       You'll have to modify these sample files before you can
       use Nagios.  Read the HTML documentation for more info
       on doing this.  Pay particular attention to the docs on
       object configuration files, as they determine what/how
       things get monitored!


*** Support Notes *******************************************

If you have questions about configuring or running Nagios,
please make sure that you:

     - Look at the sample config files
     - Read the HTML documentation
     - Read the FAQs online at http://www.nagios.org/faqs

before you post a question to one of the mailing lists.
Also make sure to include pertinent information that could
help others help you.  This might include:

     - What version of Nagios you are using
     - What version of the plugins you are using
     - Relevant snippets from your config files
     - Relevant error messages from the Nagios log file

For more information on obtaining support for Nagios, visit:

       http://www.nagios.org/support/

*************************************************************

Enjoy.


インストール
# make install

for file in images/*.jpg;  do /usr/bin/install -c -m 664 -o nagios
 -g nagios $file /usr/local/www/nagios/images; done
for file in images/*.png;  do /usr/bin/install -c -m 664 -o nagios
 -g nagios $file /usr/local/www/nagios/images; done
for file in images/logos/*.*;  do /usr/bin/install -c -m 664 -o
 nagios -g nagios $file /usr/local/www/nagios/images/logos; done
make install-basic
/usr/bin/install -c -m 775 -o nagios -g nagios -d /var/spool/nagios
/usr/bin/install -c -m 775 -o nagios -g nagios -d /var/spool/nagios
/archives
if [ yes = yes ]; then  /usr/bin/install -c -m 664 -o nagios -g
 nagios p1.pl /usr/local/bin;  fi;

*** Main program, CGIs and HTML files installed ***

You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):

この時点で表示される後作業

  make install-init起動用スクリプトのインストール
     - This installs the init script in /usr/local/etc/rc.d


  make install-commandmode外部コマンドファイルのインストール
     - This installs and configures permissions on the
       directory for holding the external command file


  make install-config設定ファイルのインストール
     - This installs *SAMPLE* config files in /usr/local/etc/nagios
       You'll have to modify these sample files before you can
       use Nagios.  Read the HTML documentation for more info
       on doing this.  Pay particular attention to the docs on
       object configuration files, as they determine what/how
       things get monitored!

起動用スクリプトのインストール
# make install-init

設定ファイルのインストール
# make install-config


特に問題が出るような所はないとは思いますが、設定ファイルはNagiosを起動させるときに必須になりますのでこれだけは最低限行っておきます。
それから、環境によるものかわかりませんが、"make install-init"を実行してもエラーになって起動スクリプトが作成されないことがあります。
その場合は手動でコピーして利用します。
(色分け:入力値コマンドラインコメント)
# cp /tmp/nagios-2.11/daemon-init /usr/local/etc/rc.d/nagios.sh
あと、SuEXECの環境ではインストール時に設定されるパーミッションの関係で実行時にエラーになりますのでパーミッションの変更を行っておきます。
(色分け:入力値コマンドラインコメント)
# chmod -R 755 /usr/local/www//nagios/cgi-bin/
ページのトップへ

設定
Webツールを使うためにApacheに設定を追加します。
とりあず、新規でバーチャルホストを追加する場合を記載していますがローカル内で直接IP指定を前提にしているのでホスト名などの設定は簡略化しています。
また、NagiosのWebツールは認証機能がないのでApacheの認証を利用する設定も加えています。
"/usr/local/etc/apache22/extra/httpd-vhosts.conf"
(色分け:書換追記コメント)
<VirtualHost *>
    DocumentRoot /usr/local/www/nagios

   <Directory /usr/local/www/nagios>
       AllowOverride None
       Options +ExecCGI
       Order Deny,Allow
       Deny from all
       Allow from 192.168.
 許可するネットワーク、ホストを記述

       AuthName "Nagios Access"
       AuthType Basic
       AuthUserFile /usr/local/etc/nagios/htpasswd
       Require valid-user
   </Directory>
</VirtualHost>
もし、Nagiosだけ追加する場合であれば下のようにAliasを使って行えばインストール先のディレクトリを気にする必要はなくなります。
"/usr/local/etc/apache22/extra/httpd-vhosts.conf"
(色分け:書換追記コメント)
Alias /nagios "/usr/local/www/nagios"

<Directory /usr/local/www/nagios>
    AllowOverride None
    Options +ExecCGI
    Order Deny,Allow
    Deny from all
    Allow from 192.168.
 許可するネットワーク、ホストを記述
</Directory>
ページのトップへ

動作確認&起動方法
それほど作業は多くありませんが起動や動作確認を簡単に行います。
(色分け:入力値コマンドラインコメント)
Nagiosの起動
# /usr/local/etc/rc.d/nagios.sh start

Apacheの起動
#apachectl configtest
#/usr/local/etc/rc.d/apache22.sh start

Apacheが既に起動している場合は再起動
#apachectl configtest
#apachectl graceful
正常に起動できていればWebブラウザ上でNagiosのURLを入力すると下のような画面が表示されます。
ページのトップへ

補足&メモ
これでインストール自体は出来ますがcgiの設定ファイルの認証に関する部分がデフォルトで有効になっているためこのままでは権限エラーで利用することは出来ません。
ローカル内での閲覧でしかも利用する人間が自分一人という場合であれば、cgi.cfgファイルを書き換えて認証機能を無効にすれば利用することが出来ます
"/usr/local/etc/nagios/cgi.cfg"
(色分け:書換追記コメント)
69: # AUTHENTICATION USAGE
70: # This option controls whether or not the CGIs will use any 
71: # authentication when displaying host and service information, as
72: # well as committing commands to Nagios for processing.  
73: #
74: # Read the HTML documentation to learn how the authorization works!
75: #
76: # NOTE: It is a really *bad* idea to disable authorization, unless
77: # you plan on removing the command CGI (cmd.cgi)!  Failure to do
78: # so will leave you wide open to kiddies messing with Nagios and
79: # possibly hitting you with a denial of service attack by filling up
80: # your drive by continuously writing to your command file!
81: #
82: # Setting this value to 0 will cause the CGIs to *not* use
83: # authentication (bad idea), while any other value will make them
84: # use the authentication functions (the default).
85: 
86: use_authentication=0
87: 
88: 
89: 
90: # DEFAULT USER
91: # Setting this variable will define a default user name that can
あと、デフォルトの状態では「傾向」などでグラフを作成したときの画像内に表示されている文字が英語になっていますが、これを日本語にするにはいくつかの作業が必要になりますので別ページにて記載します。
ページのトップへ