Naigos に関するトラブルシューティング

ソフトウエア

<景品表示法に基づく表記> 本サイトのコンテンツには、商品プロモーションが含まれている場合があります。

Nagiosをエラーやアラートが表示される!どうやって対応するの?

この疑問に回答します。

システム監視を行うにはNagiosを利用するのが便利です。導入する時しか設定を行わないので、すぐに対応方法を忘れてしまいます。改めてまとめていきます。

システム監視 Nagios とは

Nagios(ナギオス)とは、オープンソース統合監視ツールのことです。サーバー(リソース・サービス)、ネットワークなどの稼働状況を監視し、異常時に通知を行うことができます。

NaigosのURLにアクセスしても画面が表示されない

事象

NagiosのURLにアクセスしても画面が表示されない。

対応方法

対応方法です。

  • ファイアーウォール(Firewalld)設定を確認
  • Apacheのアクセス制限設定を確認

ファイアーウォール(Firewalld)設定を確認

ファイアーウォール(Firewalld)によりアクセス制限がされている可能性があります。サービスを停止するか、アクセスできるように設定を行います。

Firewalldを停止する場合

# systemctl stop firewalld
# systemctl disabled firewalld

Firewalldを設定する場合

# firewall-cmd --add-service=http --permanent
# firewall-cmd --reload

Apacheのアクセス制限設定を確認

ApacheのNaigosに関する設定を確認します。すべてのアクセス元を許可する場合

# vi /etc/httpd/conf.d/nagios.conf
<Directory "/usr/lib64/nagios/cgi-bin/">

 Require all granted ← すべてのアクセス元を許可する

</Directory>
      
<Directory "/usr/share/nagios/html">

 Require all granted ← すべてのアクセス元を許可する

</Directory>

ユーザー名とパスワード入力が表示さログインできない

事象

初期設定では、NagiosのURLにアクセスすると、ユーザー名とパスワード入力(ベーシック認証)が表示されます。

ユーザー名もパスワードもわからないので、そのまま進めるとエラーが表示される

Unauthorized

This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn’t understand how to supply the credentials required.

対応方法

対応方法です。

  • Apacheのベーシック認証を無効化する
  • Apacheのベーシック認証を設定する

Apacheのベーシック認証を無効化する

Nagiosの初期設定は、Apacheの設定にアクセス制限が導入されています。コメントアウトしベーシック認証を解除します。修正箇所が2カ所あるので、忘れずに両方ともコメントアウトしてください。

# vi /etc/httpd/conf.d/nagios.conf
<Directory "/usr/lib64/nagios/cgi-bin/">
   ~ 中略 ~
<IfVersion >= 2.3>
#         AuthName "Nagios Access" ← コメントアウト
#         AuthType Basic ← コメントアウト
#         AuthUserFile /etc/nagios/passwd ← コメントアウト
#         Require valid-user ← コメントアウト
</IfVersion>
   ~ 中略 ~
</Directory>
      
<Directory "/usr/share/nagios/html">
  ~ 中略 ~
<IfVersion >= 2.3>
#         AuthName "Nagios Access" ← コメントアウト
#         AuthType Basic ← コメントアウト
#         AuthUserFile /etc/nagios/passwd ← コメントアウト
#         Require valid-user ← コメントアウト
</IfVersion>
  ~ 中略 ~
</Directory>

設定を変更後にサービスを起動します。

# systemctl reload httpd

Apacheのベーシック認証を設定する

Nagiosにアクセスする時に利用する、ユーザーのパスワードを登録します。

# htpasswd /etc/nagios/passwd nagiosadmin
New password:     ← パスワードを設定
Re-type new password:
Adding password for user nagiosadmin

Hosts,Services などの一覧が表示されない

事象

Nagiosの Hosts , Services , Host Groups , Services Groups など一覧にエラーが表示される。

Nagiosアクセス制御によるエラー
Nagiosアクセス制御によるエラー
It appears as though you do not have permission to view information for any of the hosts you requested…
If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.

対応方法

対応方法です。

  • use_authentication パラメーターを変更

use_authentication パラメーターを変更

Nagiosの初期設定は、アクセス制限が導入されているので解除します。

# vi /etc/nagios/cgi.conf
use_authentication=0 ← 「0」に変更
# systemctl reload nagios

サービス監視にエラーが表示(No such file or directory)

事象

Services一覧を表示すると、「CRITICAL」と赤色で表示され「failed. errno is 2: No such file or directory」と表示されている。

サービス監視にエラーが表示
サービス監視にエラーが表示

対応方法

対応方法です。

  • Nagiosプラグイン のインストール

Nagiosプラグイン のインストール

Nagiosは各モジュールがプラグイン化(check_ping,check_http,check_sshなど)されています。対象のプラグインをインストールしてください。

# dnf --enablerepo=epel -y install nagios-plugins-ping
# dnf --enablerepo=epel -y install nagios-plugins-disk
# dnf --enablerepo=epel -y install nagios-plugins-users
# dnf --enablerepo=epel -y install nagios-plugins-procs
# dnf --enablerepo=epel -y install nagios-plugins-load
# dnf --enablerepo=epel -y install nagios-plugins-swap
# dnf --enablerepo=epel -y install nagios-plugins-ssh
# dnf --enablerepo=epel -y install nagios-plugins-http
# dnf --enablerepo=epel -y install nagios-plugins-mysql
 など

サービス監視にエラーが表示(not defined)

事象

Services一覧を表示すると、「UNKNOWN」と黄色で表示され「not defined 」と表示されている。

サービス監視にエラーが表
サービス監視にエラーが表

対応方法

NagiosNRPEで、コマンド名称が一致していないことが原因です。名称を再確認してください。

Nagiosの設定

# vi /etc/nagios/servers/[ホスト名].cfg

define service {
    use                     generic-service
    host_name               [ホスト名]
    service_description     disk_/
    check_command           check_nrpe!check_disk_/ ← 名称の確認(一致させる)
}

NRPEの設定

# /etc/nagios/nrpe.cfg

command[check_disk_/]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /  ← 名称の確認(一致させる)

NRPEが実行できない(not defined anywhere!)

事象

リモート監視を実行するためnrpeコマンドをcfgに記述して文法テストを実施するとエラーになる

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

Checking objects...
Error: Service check command 'check_nrpe![コマンド名]' specified in service '[コマンド名]' for host '[ホスト名]' not defined anywhere!

対応方法

対応方法は、設定ファイルにnrpeに関する記述が無いためです。

# vi /etc/nagios/objects/commands.cfg
### 追記
### nrpe
define command{
    command_name    check_nrpe
    command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

# systemctl reload nagios

NRPEが実行できない(Connection reset by peer)

事象

Services一覧を表示すると、「CRITICAL」と赤色で表示され「CHECK_NRPE: Error – Could not connect to xxx.xxx.xxx.xxx: Connection reset by peer 」と表示されている。

NRPEが実行できない
NRPEが実行できない

対応方法

Nagiosサーバーからのアクセス許可が設定されてないからです。

# vi /etc/nagios/nrpe.cfg
allowed_hosts=127.0.0.1,xxx.xxx.xxx.xxx,::1 ← NagiosサーバーのIPを登録します
# systemctl reload nrpe

関連記事 Amazonで【Nagios統合監視リファレンス】をお得に買う方法

 

 

 

以上、「Naigos に関するトラブルシューティング」という記事でした。