サーバーモニタリング · 3 min read · Oct 18, 2025
Debian SqueezeでのIcingaによるサーバーモニタリング - ページ3
4 リモートサーバー(server2)をIcingaに追加する
ローカルホストの監視は良いですが、もちろん、すべてのサーバーを1か所で監視できるとさらに良いでしょう。これはIcingaで可能であり、この章では、2台目のDebian Squeezeサーバー(server2.example.com)をセットアップに追加する方法を説明します。
これを行うには、server2にNagios NRPE (Nagios Remote Plugin Executor)サーバーをインストールし、server1にNagios NRPEプラグインをインストールする必要があります。NRPEサーバーはserver2でリッスンし、server1はNRPEプラグインを使用して接続し、NRPEサーバーがserver2で実行するコマンドを渡します。結果はserver1に返されます。
まず、server1にnagios-nrpe-pluginパッケージをインストールします:
server1:
apt-get install nagios-nrpe-pluginNagiosウェブ管理パスワード: <– nagiosadmin_password
パスワード確認: <– nagiosadmin_password
次に、server2に移動します:
server2:
nagios-nrpe-serverパッケージをインストールします:
apt-get install nagios-nrpe-serverワークグループ/ドメイン名: <– WORKGROUP
次に、/etc/nagios/nrpe.cfgを開きます:
vi /etc/nagios/nrpe.cfgNRPEサーバーがserver1 (IP: 192.168.0.100)の接続を許可するように設定する必要があるため、allowed_hosts行に192.168.0.100を追加します:
| [...] # ALLOWED HOST ADDRESSES # This is an optional comma-delimited list of IP address or hostnames # that are allowed to talk to the NRPE daemon. # # Note: The daemon only does rudimentary checking of the client's IP # address. I would highly recommend adding entries in your /etc/hosts.allow # file to allow only the specified host to connect to the port # you are running this daemon on. # # NOTE: This option is ignored if NRPE is running under either inetd or xinetd allowed_hosts=127.0.0.1,192.168.0.100 [...] |
(これを行わないと、server1で次のコマンドを実行したときに次のエラーが表示されます
/usr/lib/nagios/plugins/check_nrpe -H 192.168.0.101server1:
root@server1:/etc/nagios-plugins/config# /usr/lib/nagios/plugins/check_nrpe -H 192.168.0.101
CHECK_NRPE: Error - Could not complete SSL handshake.
root@server1:/etc/nagios-plugins/config#)
また、server1はNRPEサーバーにコマンドライン引数を渡すことを許可する必要があるため、同じファイル内でdont_blame_nrpeを1に設定します:
| [...] # COMMAND ARGUMENT PROCESSING # This option determines whether or not the NRPE daemon will allow clients # to specify arguments to commands that are executed. This option only works # if the daemon was configured with the --enable-command-args configure script # option. # # * ENABLING THIS OPTION IS A SECURITY RISK! * # Read the SECURITY file for information on some of the security implications # of enabling this variable. # # Values: 0=do not allow arguments, 1=allow command arguments dont_blame_nrpe=1 [...] |
(これを行わないと、Icingaウェブインターフェースで多くのリモートサービスチェックに対して次のエラーが表示され、server2の/var/log/syslogには次のエラーが表示されます:
Aug 23 14:20:20 server2 nrpe[11496]: Error: Request contained command arguments, but argument option is not enabled!
Aug 23 14:20:20 server2 nrpe[11496]: Client request was invalid, bailing out...)
最後に、server2で実行したい各サービスチェックのコマンド定義を追加する必要がありますが、すでに定義されていないものです。server2でcheck_procs、check_all_disks、check_mysql_cmdlinecredチェックを実行したいと思います。これらは/etc/nagios/nrpe.cfgに定義されていないため、今追加します(check_usersとcheck_loadチェックも実行したいですが、これらはすでに定義されています):
| [...] command[check_procs]=/usr/lib/nagios/plugins/check_procs -w 250 -c 400 command[check_all_disks]=/usr/lib/nagios/plugins/check_disk -w '20%' -c '10%' -e command[check_mysql_cmdlinecred]=/usr/lib/nagios/plugins/check_mysql -H localhost -u 'nagios' -p 'howtoforge' [...] |
(これを行わないと、Icingaウェブインターフェースで次のようなエラーが表示されます:
NRPE: Command 'check_all_disks' not defined
NRPE: Command 'check_mysql_cmdlinecred' not defined
NRPE: Command 'check_procs' not defined)
ご覧のとおり、コマンドライン引数をハードコーディングしました。なぜなら、変数を使用すること(例えば、command[check_procs]=/usr/lib/nagios/plugins/check_procs -w $ARG1$ -c $ARG2$)は私には機能しなかったからです。しかし、server1でserver2のサービスチェックを構成するときには、これらのチェックにコマンドライン引数を渡す必要があります。server2はこれを無視します。なぜなら、/etc/nagios/nrpe.cfgにコマンドライン引数をハードコーディングしているからです。しかし、引数を省略すると、Icingaウェブインターフェースで/usr/lib/nagios/plugins/check_nrpe: option requires an argument – ‘a’のようなエラーが表示されます。
ファイルを保存してNRPEサーバーを再起動します:
/etc/init.d/nagios-nrpe-server restartNRPEサーバーがリッスンしているかどうかを確認します:
netstat -tap | grep nrperoot@server2:~# netstat -tap | grep nrpe
tcp 0 0 *:nrpe *:* LISTEN 2132/nrpe
root@server2:~#server1に戻ります…
server1:
… そして、server2のNRPEサーバーに接続できるかどうかを確認します:
/usr/lib/nagios/plugins/check_nrpe -H 192.168.0.101成功した場合、出力は次のようになります:
root@server1:~# /usr/lib/nagios/plugins/check_nrpe -H 192.168.0.101
NRPE v2.12
root@server1:~#server2に戻ります:
server2:
server2のMySQLをチェックしたいと思います。NRPEデーモンを使用しているため、server2でローカルにチェックを実行できます。つまり、server1がチェックを実行するためにMySQLを外部に開放する必要はありません。したがって、localhostおよびlocalhost.localdomain用のMySQLユーザーnagiosを作成します:
mysql -u root -pGRANT USAGE ON *.* TO nagios@localhost IDENTIFIED BY 'howtoforge';
GRANT USAGE ON *.* TO [email protected] IDENTIFIED BY 'howtoforge';
FLUSH PRIVILEGES;quit;server1に戻ります…
server1:
… そして、server2のIcinga構成を作成します:
vi /etc/icinga/objects/server2_icinga.cfg| define host{ use generic-host host_name server2.example.com alias server2 address 192.168.0.101 } define service{ use generic-service host_name server2.example.com service_description PING check_command check_ping!100.0,20%!500.0,60% } define service{ use generic-service ; Name of service template to use host_name server2.example.com service_description Disk Space check_command check_nrpe!check_all_disks!20%!10% } define service{ use generic-service host_name server2.example.com service_description Current Users check_command check_nrpe!check_users!20!50 } define service{ use generic-service ; Name of service template to use host_name server2.example.com service_description Total Processes check_command check_nrpe!check_procs!250!400 } define service{ use generic-service ; Name of service template to use host_name server2.example.com service_description Current Load check_command check_nrpe!check_load!5.0!4.0!3.0!10.0!6.0!4.0 } define service{ use generic-service host_name server2.example.com service_description MySQL check_command check_nrpe!check_mysql_cmdlinecred!nagios!howtoforge } define service{ use generic-service host_name server2.example.com service_description SMTP check_command check_smtp } define service{ use generic-service host_name server2.example.com service_description POP3 check_command check_pop } define service{ use generic-service host_name server2.example.com service_description IMAP check_command check_imap } |
(前述のように、server2の/etc/nagios/nrpe.cfgにいくつかのコマンドライン引数をハードコーディングしましたが、ここで特定のチェックにコマンドライン引数を追加する必要があります。)
ご覧のとおり、いくつかのチェックにはcheck_nrpeを使用し、check_nrpeに実際のチェック(check_all_disksなど)をコマンドライン引数として渡しています。これらはserver2のNRPEサーバーによってローカルに実行されるチェックです。すべてのチェックにcheck_nrpeは必要ありません。check_pingやcheck_smtpのように外部からの接続をテストするチェックはserver1から実行できます。
server2のSSHおよびHTTPサービスをチェックするには、/etc/icinga/objects/server2_icinga.cfgに次のスタンザを追加することができます…
| [...] define service { use generic-service host_name server2.example.com service_description SSH check_command check_ssh } define service { use generic-service host_name server2.example.com service_description HTTP check_command check_http } |
… または、/etc/icinga/objects/hostgroups_icinga.cfgのhttp-serversおよびssh-serversホストグループにserver2.example.comを追加します:
vi /etc/icinga/objects/hostgroups_icinga.cfg| # 一部の一般的なホストグループ定義 # シンプルなワイルドカードホストグループ define hostgroup { hostgroup_name all alias All Servers members * } # Debian GNU/Linuxサーバーのリスト define hostgroup { hostgroup_name debian-servers alias Debian GNU/Linux Servers members localhost,server2.example.com } # ウェブサーバーのリスト define hostgroup { hostgroup_name http-servers alias HTTP servers members localhost,server2.example.com } # SSHアクセス可能なサーバーのリスト define hostgroup { hostgroup_name ssh-servers alias SSH servers members localhost,server2.example.com } |
Icingaを再起動します:
/etc/init.d/icinga restartその後、Icingaウェブインターフェースにserver2が表示されるはずです:

server2のサービスチェックは次のとおりです:

server2をホストグループに追加した場合、すべてのホストグループのサービス概要に表示されるはずです:

5 リンク
- Icinga: https://www.icinga.org/
- Icinga Documentation: http://docs.icinga.org/latest/en/
- Nagios: http://www.nagios.org/
- Debian: http://www.debian.org/
新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。