SUSE 11 に nagios をインストール

一般的に「システム統合管理ツール」を導入する敷居は高いようで、必要性を理解していても、利用者側の管理者が使いこなせない、正しい結果が得られない、投資効果が見えない、有償のツールとして導入するには高価すぎる、などの問題があります。

 運用丸投げなら、「使いこなせない」という問題もないのでしょうが、自社のビジネスとどのようにかかわりがあり、そのジョブ(システム)がクリティカルなのかの判断は利用者側が判断しなければあまり役には立ちません。システムの障害の「見える化」は非常に重要なのですが、見ている側が全く「重要性を判断できない」、「自社のビジネスにどのような影響を与えるか」という判断が出来なければ、高価で無駄な投資となりがちです。

nagios は GPL で公開されたソフトウェアで、SUSE Linux 11 sp2 では標準パッケージとして、代表的なプラグインなどがインストールできます。SUSE(SLES11)でのXEN仮想インスタンスは1サーバーあたりソケット数32という制限以外は無制限」という「他社にはあり得ない」おおらかなライセンス形態で、nagios は管理用仮想アプライアンスといして導入するには非常に良い選択です。

今回は SLES11 sp2 で導入してみました。

-インストール-

インストール前に次の文書、書籍を参考にしました。

opensuse Nagios を利用した監視

Nagios 3.0 - A Extensible Host and Service Monitoring

Nagios: Host and Service Monitoring Tool

Nagios統合監視[実践]リファレンス (Software Design plus) [単行本(ソフトカバー)]

今回は SLES11 を XEN 上の仮想マシンとして導入しました。

- vcpu:2
- memory: 512Mb
- ディスク: 6Gb

XEN の仮想マシンの導入手順はここでは述べませんが、幾つかポイントがあります。

1) Summary 画面より追加ソフトウェアとして WEB/LAMP を選択しておくこと

2) Summary 画面より Software > Detail ボタンから Nagios とプラグインを選択します。



SUSE 11 に nagios をインストール_a0056607_943944.jpg


これらの作業はシンプルにインストールした後の SLES から YaST を使って導入することもできます。

Yast > Software Management > Search >"nagios" よりスペースキーで選択し、Accept します。
SUSE 11 に nagios をインストール_a0056607_1524393.jpg


その他、SLES の導入の際

- UTC ではなく JST(+9) を指定
- 固定ipやホスト名の設定
- デフォルト run level は 3

などを行い、インストールが終わったら NTP の設定を行います。

-HTTP サービスの開始-

デフォルトでは HTTP サービスは Enable となっていないため、 YaST > Network Service > HTTP server から、HTTP servicxe を Dualing Boot に設定します。

nagios:~ # yast

SUSE 11 に nagios をインストール_a0056607_911411.jpg



-設定ファイル-

nagios をインストールした後のインストール先などです。ソースからコンパイル、インストールする式の教科書に載っていないディレクトリが幾つか使われているのでご注意ください。

nagios:~ # find / -name "nagios*"
/var/spool/nagios
/var/spool/nagios/nagios.cmd
/var/lib/nagios <----- objects.cache などの一時データ
/var/run/nagios
/var/run/nagios/nagios.pid
/var/log/nagios
/var/log/nagios/nagios.log
/usr/sbin/nagios <---- 本体
/usr/sbin/nagiostats
/usr/lib64/ruby/vendor_ruby/1.8/puppet/util/nagios_maker.rb
: 中略
/usr/lib64/ruby/vendor_ruby/1.8/puppet/type/nagios_command.rb
/usr/share/doc/packages/nagios-nsca
: 中略 
/usr/share/doc/packages/nagios-nrpe
/usr/share/nagios
/usr/share/nagios/docs/images/nagios.jpg
/usr/share/nagios/docs/nagiostats.html
/usr/share/nagios/images/logos/nagiosvrml.png
/usr/share/nagios/images/logos/nagios.gd2
/usr/share/nagios/images/logos/nagios.gif
/usr/share/man/man8/nagiosstats.8.gz
/usr/share/man/man8/nagios.8.gz
/usr/share/locale/fr/LC_MESSAGES/nagios-plugins.mo
/usr/share/locale/de/LC_MESSAGES/nagios-plugins.mo
/usr/share/augeas/lenses/dist/nagiosobjects.aug
/usr/share/augeas/lenses/dist/nagioscfg.aug
/usr/lib/nagios <--- plugin,cgi など
/etc/nagios <---- 設定ファイル
/etc/nagios/nagios.cfg
/etc/sysconfig/nagios
/etc/init.d/nagios
/etc/apache2/conf.d/nagios.conf
nagios:~ #



-nagios の Basic 認証パスワード-

SLES11 標準パッケージでは手動で設定する重要な部分です。ここ以外の作業の大部分は YaST が自動的に設定します。(<---ここ重要でした)

#htpasswd2 -c /etc/nagios/htpasswd.users nagiosadmin

nagios:~ # htpasswd2 -c /etc/nagios/htpasswd.users nagiosadmin
New password: Your-Password
Re-type new password: Your-Password
Adding password for user nagiosadmin
nagios:~ #


※ /etc/nagios/htpasswd.users をリネームすると ブラウザが"Server error!"を返します。ここは一番のはまりどころです。

SUSE Linux に nagios(を始めアプリケーション) を入れる時は素直に YaST を使うのが王道で、ほかのディストリビューションのように設定ファイルをあれこれいじくりまわすとトラブルの元になります。SUSE は YaST のおかげで 「なんちゃってLinux」 の容易な管理、構築が可能なのですね。

-サービスを起動してみる-

nagios:~ # /etc/init.d/apache2 restart
Syntax OK
Shutting down httpd2 (waiting for all children to terminate) done
Starting httpd2 (prefork) done
nagios:~ # /etc/init.d/nagios restart
Shutting down Nagios done
Starting Nagios done
nagios:~ #
nagios:~ # tail /var/log/nagios/nagios.log
[1362008121] Nagios 3.0.6 starting... (PID=3848)
[1362008121] Local time is Thu Feb 28 08:35:21 JST 2013
[1362008121] LOG VERSION: 2.0
[1362008121] Finished daemonizing... (New PID=3849)
nagios:~ #


一応うまく行ったようです。

http://MyNagios-ip/nagios

をブラウザで開き、認証画面が出てきたらhtpasswd2 で設定した nagiosadmin/Your-Password でブラウザからログインします。
SUSE 11 に nagios をインストール_a0056607_946106.jpg


/var/lib/nagios 以下のファイルが更新されています。

nagios:/var/lib/nagios # ls -al
total 56
drwxr-xr-x 2 nagios nagios 4096 Feb 28 08:52 .
drwxr-xr-x 47 root root 4096 Feb 28 08:45 ..
-rw-r--r-- 1 nagios nagios 12931 Feb 28 08:40 objects.cache
-rw------- 1 nagios nagcmd 13468 Feb 28 08:40 retention.dat
-rw-rw-r-- 1 nagios nagios 14164 Feb 28 08:52 status.dat
nagios:/var/lib/nagios #


-自動起動-

YaST > Software Management > System Service(run Level) の Expert option から Runlevel 3,5 にチェックが入っていることを確認します。

SUSE 11 に nagios をインストール_a0056607_1247126.jpg


-各種設定ファイル-

/etc/nagios の下に各種設定ファイルがあります。

nagios:/etc/nagios # ls -lR
.:
total 104
-rw-rw-r-- 1 root root 10683 Oct 5 2011 cgi.cfg
-rw-rw-r-- 1 root root 15760 Feb 27 2009 command.cfg
-rw-r--r-- 1 root root 26 Feb 28 08:39 htpasswd.users
-rw-r--r-- 1 root root 42509 Oct 5 2011 nagios.cfg
-rw-r--r-- 1 root root 7194 Jul 14 2011 nrpe.cfg
-rw-r--r-- 1 root root 5329 Feb 21 2009 nsca.cfg
drwxrwxr-x 2 root root 4096 Feb 28 08:24 objects
-rw-rw---- 1 nagios nagcmd 1336 Oct 5 2011 resource.cfg
-rw-r--r-- 1 root root 1628 Feb 21 2009 send_nsca.cfg

./objects:
total 52
-rw-rw-r-- 1 root root 7710 Oct 5 2011 commands.cfg
-rw-rw-r-- 1 root root 2166 Oct 5 2011 contacts.cfg
-rw-rw-r-- 1 root root 5403 Oct 5 2011 localhost.cfg
-rw-r--r-- 1 root root 185 Jul 14 2011 nrpe_check_control.cfg
-rw-rw-r-- 1 root root 3124 Oct 5 2011 printer.cfg
-rw-rw-r-- 1 root root 3293 Oct 5 2011 switch.cfg
-rw-rw-r-- 1 root root 10812 Oct 5 2011 templates.cfg
-rw-rw-r-- 1 root root 3209 Oct 5 2011 timeperiods.cfg
-rw-rw-r-- 1 root root 4007 Oct 5 2011 windows.cfg
nagios:/etc/nagios #


cgi の場所

nagios:/usr/lib/nagios/cgi # ls -al
total 3472
drwxr-xr-x 2 root root 4096 Feb 28 08:25 .
drwxr-xr-x 5 root root 4096 Feb 28 08:24 ..
-rwxr-xr-x 1 root root 251680 Oct 5 2011 avail.cgi
-rwxr-xr-x 1 root root 248288 Oct 5 2011 cmd.cgi
-rwxr-xr-x 1 root root 210624 Oct 5 2011 config.cgi
-rwxr-xr-x 1 root root 263904 Oct 5 2011 extinfo.cgi

 :中略

-rwxr-xr-x 1 root root 206624 Oct 5 2011 statuswml.cgi
-rwxr-xr-x 1 root root 190176 Oct 5 2011 statuswrl.cgi
-rwxr-xr-x 1 root root 210720 Oct 5 2011 summary.cgi
-rwxr-xr-x 1 root root 202528 Oct 5 2011 tac.cgi
-rwxr-xr-x 1 root root 5335 Oct 5 2011 traceroute.cgi
-rwxr-xr-x 1 root root 219008 Oct 5 2011 trends.cgi
nagios:/usr/lib/nagios/cgi #

プラグインの一覧

nagios:/usr/lib/nagios/plugins # ls -l

total 2032
-rwxr-xr-x 1 root root 97584 Feb 27 2009 check_apt
-rwxr-xr-x 1 root root 2271 Feb 27 2009 check_breeze
-rwxr-xr-x 1 root root 36440 Feb 27 2009 check_by_ssh
lrwxrwxrwx 1 root root 9 Feb 28 08:22 check_clamd -> check_tcp
-rwxr-xr-x 1 root root 23440 Feb 27 2009 check_cluster
-rwxr-xr-x 1 root root 35928 Feb 27 2009 check_dhcp
-rwxr-xr-x 1 root root 31960 Feb 27 2009 check_dig

 : 中略

lrwxrwxrwx 1 root root 9 Feb 28 08:25 check_spop -> check_tcp
-rwxr-xr-x 1 root root 27672 Feb 27 2009 check_ssh
lrwxrwxrwx 1 root root 9 Feb 28 08:25 check_ssmtp -> check_tcp
-rwxr-xr-x 1 root root 27632 Feb 27 2009 check_swap
-rwxr-xr-x 1 root root 36568 Feb 27 2009 check_tcp
-rwxr-xr-x 1 root root 27672 Feb 27 2009 check_time
lrwxrwxrwx 1 root root 9 Feb 28 08:22 check_udp -> check_tcp
-rwxr-xr-x 1 root root 31800 Feb 27 2009 check_ups
-rwxr-xr-x 1 root root 23472 Feb 27 2009 check_users
-rwxr-xr-x 1 root root 3016 Feb 27 2009 check_wave
-rwxr-xr-x 1 root root 2319 Feb 27 2009 check_xenvm
drwxr-xr-x 4 root root 4096 Feb 28 08:24 eventhandlers
-rwxr-xr-x 1 root root 27664 Feb 27 2009 negate
-rwxr-xr-x 1 root root 10592 Jul 14 2011 nrpe_check_control
-rwxr-xr-x 1 root root 23440 Feb 27 2009 urlize
-rw-r--r-- 1 root root 2070 Feb 27 2009 utils.pm
-rwxr-xr-x 1 root root 862 Feb 27 2009 utils.sh
nagios:/usr/lib/nagios/plugins #




- ターゲット側 NRPE -

監視ターゲット側には NRPE(Nagios Remote Plugin Executer) を導入します。別にこれは必須ではないのですが、死活監視以上の詳細な管理を行う場合は、このソフトウェアエージェントを導入します。

YaST > Software Management > Search から nagios で検索すると
SUSE 11 に nagios をインストール_a0056607_1250734.jpg

nagios NRPE のパッケージがあります。このパッケージをスペースキーで選択して Accept すると、 Nagios NRPE がインストールされます。
デフォルトでは allowd hosts がローカルだけなので nagios core が動作するサーバーを追加します。
/etc/nagios/nrpe.cfg を次のように編集し、NRPEをリスタートします。

nagios-target:/etc/nagios # grep allow nrpe.cfg
#allowed_hosts=127.0.0.1
allowed_hosts=127.0.0.1,192.168.1.221
nagios-target:/etc/nagios #

nagios-target:/etc/nagios # /etc/init.d/nrpe restart
Shutting down Nagios NRPE done
Starting Nagios NRPE done
nagios-target:/etc/nagios #


NRPE もnagios core 同様に system service から起動できるよう runlevel にチェックを付けます。

-Windows の NRPE-
Windows 用 NRPE は NSClient++ としてリリースされています。
http://www.nsclient.org/nscp/

今回は Windows8 の32ビット版ということでリンク先のダウンロードページから 32bit 用の msi インストーラを使いました。ウィザードに従ってインストールすると、次のようなスクリーンがあります。
SUSE 11 に nagios をインストール_a0056607_1331024.jpg

ここで、許可する nagios core サーバーと許可するプラグイン、パスワードが設定できます。とりあえず、nagios 本体のアドレスと許可するプラグインを全部チェックしてみました。
インストールが終わると Windows のサービスの中に NSCP++ のサービスが起動します。
SUSE 11 に nagios をインストール_a0056607_13101260.jpg



-ホスト側から応答を確認-

NRPEが正しく動作しているかどうかは plugin ディレクトリの check_nrpe プラグインを使います。

nagios:/usr/lib/nagios/plugins # ls -l check_nrpe
-rwxr-xr-x 1 root root 25648 Jul 14 2011 check_nrpe
nagios:/usr/lib/nagios/plugins #

-Linuxに対して
nagios:/usr/lib/nagios/plugins # ./check_nrpe -H 192.168.1.22
NRPE v2.12
nagios:/usr/lib/nagios/plugins #


-Windows に対して-
nagios:/etc/nagios # /usr/lib/nagios/plugins/check_nrpe -H 192.168.1.31
I (0,4,1,90 2013-02-04) seem to be doing fine...
nagios:/etc/nagios #


このように、バージョンが帰ってくれば正常に動作しているということになります。

-あとは nagios.cfg の設定-

nagios.cfg の windows.cfg,switch.cfg,printer.cfg の3行がコメントアウトされていたので、このコメントアウトを外して nagios を再起動してみました。これらの3ファイルはデフォルトでインストールされるサンプルファイルです。

# Definitions for monitoring the local (Linux) host
cfg_file=/etc/nagios/objects/localhost.cfg

# Definitions for monitoring a Windows machine
cfg_file=/etc/nagios/objects/windows.cfg

# Definitions for monitoring a router/switch
cfg_file=/etc/nagios/objects/switch.cfg

# Definitions for monitoring a network printer
cfg_file=/etc/nagios/objects/printer.cfg

SUSE 11 に nagios をインストール_a0056607_1316144.jpg


このような感じで監視ターゲットが nagios web コンソールに出てきます。ちょっと当てになりませんね。チューニングが必要です。ここは勉強です。

-nagios.cfg の確認-

# /usr/sbin/nagios -v nagios.cfg
で nagios の設定ファイルを確認することができます。

nagios:/etc/nagios # nagios -v ./nagios.cfg

Nagios 3.0.6
Copyright (c) 1999-2008 Ethan Galstad (http://www.nagios.org)
Last Modified: 12-01-2008
License: GPL

Reading configuration data...

Running pre-flight check on configuration data...

Checking services...
Checked 8 services.

 : 中略


Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors: 0

Things look okay - No serious problems were detected during the pre-flight check


何等かの記述ミスがあると次のようにエラー行が表示されます。じーっとよく見て確認して修正します。

nagios:/etc/nagios # nagios -v ./nagios.cfg
Nagios 3.0.6
Copyright (c) 1999-2008 Ethan Galstad (http://www.nagios.org)
Last Modified: 12-01-2008
License: GPL

Reading configuration data...

Error: Invalid host object directive 'named'.
Error: Could not add object property in file '/etc/nagios/objects/dns2.cfg' on line 27.


***> One or more problems was encountered while processing the config files...

Check your configuration file(s) to ensure that they contain valid
directives and data defintions. If you are upgrading from a previous
version of Nagios, you should be aware that some variables/definitions
may have been removed or modified in this version. Make sure to read
the HTML documentation regarding the config files, as well as the
'Whats New' section to find out what has changed.

nagios:/etc/nagios #


エラーファイルは  /var/log//nagios/config.err にも記録されます。
-----

 ということで、 SUSELinux 11 sp2 (sles11sp2) の標準パッケージに含まれている nagios 統合管理ツールの導入について順を追って説明してきました。

 おそらく、他のディストリビューションでは、 nagios のユーザ設定、ディレクトリやアクセス権の設定など、一応教科書通りにやってもうまく動かないケースがありそうですが、 SUSE11 添付の nagios パッケージは nagiosadmin の basic 認証パスワードの設定を htpasswd2 で変えるだけで YaST で全部設定することが出来ました。

-- 実際、インストールした後、いろいろ設定ファイルを変更してトライすたより、フレッシュインストールから nagios を導入したら、一発で動いてしまった、ということです。

 一応、 SLES の公式パッケージに含まれているので、(プレミアムサブスクリプションを買うと)サポートも SUSE 社が行う(ただし2013年現在ノベルK.Kは行わないだろうけど...)公式にサポートできる監視ツールです。

 性能や機能はともかくも、「統合監視ツール」っていったいどれだけ使えるんだ? という場合は「まず導入してみるには」いいチャレンジ対象でした。

なお、openSUSE 12.2では 1 click インストールができるので、サポート不要で自己責任でチャレンジするには良い選択だと思います。

さてこれから、本格的に導入して利用するには

SUSE + nagios でプリンタ管理

SUSE + Nagios で管理する Windows Server

SUSE + Nagios で Linux の管理

islandcenter.jp

-Keyword-

SUSE SLES openSUSE nagios 統合管理ツール Linux オープンソース Novell アセット管理
by islandcenter | 2013-03-01 13:55 | SUSE | Comments(0)