1 views

実現させる機能

サーバーに不具合が起きても、気づくまでに時間がかかるのが常です。統合監視システムNagios(ナギオス)は、サーバーに不具合が起きるとメールをくれるので、不具合に気づくまでの時間を短縮できます。今回は、パッケージから簡単インストールで構築してみました。最新版でないのが欠点ですが、初心者向けの構築法ではあります。監視項目を増やすと敷居も高くなりますが・・・。

事前準備

Webサーバー構築済であること
リポジトリ導入(EPEL,RPMforge)を参照してEPELリポジトリが導入済であること

Nagios導入手順

統合監視システムNagiosをyumでインストールし、バックアップしたファイルをコピーするという単純な手順です。ついでに、Sambaを監視項目に追加すると不明のエラーが出る問題も応急手当で解消しています。

[root@ufuso ~]# yum -y install gd-devel ← 描画処理に必要なソフトをインストール
Installed:
  gd-devel.x86_64 0:2.0.35-11.el6                                    

Dependency Installed:
  fontconfig-devel.x86_64 0:2.8.0-3.el6                              
  freetype-devel.x86_64 0:2.3.11-14.el6_3.1                          
  gd.x86_64 0:2.0.35-11.el6                                          
  libX11-devel.x86_64 0:1.5.0-4.el6                                  
  libXau-devel.x86_64 0:1.0.6-4.el6                                  
  libXpm-devel.x86_64 0:3.5.10-2.el6                                 
  libjpeg-turbo-devel.x86_64 0:1.2.1-1.el6                           
  libpng-devel.x86_64 2:1.2.49-1.el6_2                               
  libxcb-devel.x86_64 0:1.8.1-1.el6                                  
  xorg-x11-proto-devel.noarch 0:7.6-25.el6                           
  zlib-devel.x86_64 0:1.2.3-29.el6                                   

Complete!
[root@ufuso ~]# yum --enablerepo=epel -y install nagios ← EPELからNagiosを
インストール
Installed:
  nagios.x86_64 0:3.4.4-1.el6                                        

Dependency Installed:
  nagios-common.x86_64 0:3.4.4-1.el6                                 

Complete!

[root@ufuso ~]# yum --enablerepo=epel -y install nagios-plugins-all ← EPELから
Nagiosのpluginをインストール
Installed:
  nagios-plugins-all.x86_64 0:1.4.16-5.el6                           

Dependency Installed:
  fping.x86_64 0:2.4b2-10.el6                                        
  lm_sensors.x86_64 0:3.1.1-17.el6                                   
  nagios-plugins.x86_64 0:1.4.16-5.el6                               
  nagios-plugins-breeze.x86_64 0:1.4.16-5.el6                        
  nagios-plugins-by_ssh.x86_64 0:1.4.16-5.el6                        
  nagios-plugins-cluster.x86_64 0:1.4.16-5.el6                       
  nagios-plugins-dhcp.x86_64 0:1.4.16-5.el6                          
  nagios-plugins-dig.x86_64 0:1.4.16-5.el6                           
  nagios-plugins-disk.x86_64 0:1.4.16-5.el6                          
  nagios-plugins-disk_smb.x86_64 0:1.4.16-5.el6                      
  nagios-plugins-dns.x86_64 0:1.4.16-5.el6                           
  nagios-plugins-dummy.x86_64 0:1.4.16-5.el6                         
  nagios-plugins-file_age.x86_64 0:1.4.16-5.el6                      
  nagios-plugins-flexlm.x86_64 0:1.4.16-5.el6                        
  nagios-plugins-fping.x86_64 0:1.4.16-5.el6                         
  nagios-plugins-game.x86_64 0:1.4.16-5.el6                          
  nagios-plugins-hpjd.x86_64 0:1.4.16-5.el6                          
  nagios-plugins-http.x86_64 0:1.4.16-5.el6                          
  nagios-plugins-icmp.x86_64 0:1.4.16-5.el6                          
  nagios-plugins-ide_smart.x86_64 0:1.4.16-5.el6                     
  nagios-plugins-ircd.x86_64 0:1.4.16-5.el6                          
  nagios-plugins-ldap.x86_64 0:1.4.16-5.el6                          
  nagios-plugins-load.x86_64 0:1.4.16-5.el6                          
  nagios-plugins-log.x86_64 0:1.4.16-5.el6                           
  nagios-plugins-mailq.x86_64 0:1.4.16-5.el6                         
  nagios-plugins-mrtg.x86_64 0:1.4.16-5.el6                          
  nagios-plugins-mrtgtraf.x86_64 0:1.4.16-5.el6                      
  nagios-plugins-mysql.x86_64 0:1.4.16-5.el6                         
  nagios-plugins-nagios.x86_64 0:1.4.16-5.el6                        
  nagios-plugins-nt.x86_64 0:1.4.16-5.el6                            
  nagios-plugins-ntp.x86_64 0:1.4.16-5.el6                           
  nagios-plugins-ntp-perl.x86_64 0:1.4.16-5.el6                      
  nagios-plugins-nwstat.x86_64 0:1.4.16-5.el6                        
  nagios-plugins-oracle.x86_64 0:1.4.16-5.el6                        
  nagios-plugins-overcr.x86_64 0:1.4.16-5.el6                        
  nagios-plugins-perl.x86_64 0:1.4.16-5.el6                          
  nagios-plugins-pgsql.x86_64 0:1.4.16-5.el6                         
  nagios-plugins-ping.x86_64 0:1.4.16-5.el6                          
  nagios-plugins-procs.x86_64 0:1.4.16-5.el6                         
  nagios-plugins-real.x86_64 0:1.4.16-5.el6                          
  nagios-plugins-rpc.x86_64 0:1.4.16-5.el6                           
  nagios-plugins-sensors.x86_64 0:1.4.16-5.el6                       
  nagios-plugins-smtp.x86_64 0:1.4.16-5.el6                          
  nagios-plugins-snmp.x86_64 0:1.4.16-5.el6                          
  nagios-plugins-ssh.x86_64 0:1.4.16-5.el6                           
  nagios-plugins-swap.x86_64 0:1.4.16-5.el6                          
  nagios-plugins-tcp.x86_64 0:1.4.16-5.el6                           
  nagios-plugins-time.x86_64 0:1.4.16-5.el6                          
  nagios-plugins-ups.x86_64 0:1.4.16-5.el6                           
  nagios-plugins-users.x86_64 0:1.4.16-5.el6                         
  nagios-plugins-wave.x86_64 0:1.4.16-5.el6                          
  net-snmp-utils.x86_64 1:5.5-44.el6                                 
  postgresql-libs.x86_64 0:8.4.13-1.el6_3                            
  qstat.x86_64 0:2.11-9.20080912svn311.el6                           

Complete!


[root@ufuso ~]#  vi /etc/nagios/objects/contacts.cfg ← contacts.cfgの設定
###############################################################################
#
# CONTACTS
#
###############################################################################
###############################################################################

# Just one contact defined by default - the Nagios admin (that's you)
# This contact definition inherits a lot of default values from the 'generic-contact'
# template which is defined elsewhere.

define contact{
        contact_name                    nagiosadmin             ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias                           Nagios Admin            ; Full name of user

        email                           ufuso@gmail.com     ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
        } ← Nagiosからのメールを受け取るアドレスに変更。「ufuso@gmail.com」は例示

[root@ufuso ~]#   vi /etc/nagios/nagios.cfg ← nagios.cfgの編集
# DATE FORMAT OPTION
# This option determines how short dates are displayed. Valid options
# include:
#       us              (MM-DD-YYYY HH:MM:SS)
#       euro            (DD-MM-YYYY HH:MM:SS)
#       iso8601         (YYYY-MM-DD HH:MM:SS)
#       strict-iso8601  (YYYY-MM-DDTHH:MM:SS)
#

date_format=iso8601 ← 日付表示をusをiso8601に変更

[root@ufuso ~]# htpasswd /etc/nagios/passwd nagiosadmin  ← Nagios管理ユーザー(nagiosadmin)
のパスワード作成
New password:  ← nagiosadminのパスワード作成入力(表示されない)
Re-type new password:  ← 作成したパスワード再入力(表示されない)
Updating password for user nagiosadmin

[root@ufuso ~]# /etc/rc.d/init.d/nagios start ← nagios起動
Starting nagios: done.

[root@ufuso ~]# chkconfig nagios on ← 自動起動の設定

■起動エラーがでる場合の処理手順

[root@ufuso ~]# /usr/sbin/nagios -v /etc/nagios/nagios.cfg ← エラーの内容を確認
Nagios Core 3.4.1
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 05-11-2012
License: GPL

Website: http://www.nagios.org
Reading configuration data...
   Read main config file okay...
Processing object config file '/etc/nagios/objects/commands.cfg'...
Processing object config file '/etc/nagios/objects/contacts.cfg'...
Processing object config file '/etc/nagios/objects/timeperiods.cfg'...
Processing object config file '/etc/nagios/objects/templates.cfg'...
Processing object config file '/etc/nagios/objects/localhost.cfg'...
Error: Unexpected start of object definition in file '/etc/nagios/objects/localhost.cfg'
 on line 164.  Make sure you close preceding objects before starting a new one.
 ← localhost.cfgの164行目がエラー箇所だとわかる。
   Error processing object config files!


***> 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.

監視サービスの追加

(1)NTP

[root@ufuso ~]# vi /etc/nagios/objects/commands.cfg ← commands.cfg編集
以下を最終行へ追加

# 'check_ntp' command definition
define command{
        command_name    check_ntp
        command_line    $USER1$/check_ntp -H $ARG1$ -w $ARG2$ -c $ARG3$
        }

[root@ufuso ~]# vi /etc/nagios/objects/localhost.cfg ← localhost.cfg編集
以下を最終行へ追加

define service{
        use                             generic-service
        host_name                       localhost
        service_description             NTP
        check_command                   check_ntp!210.173.160.27!1!2 ← 外部NTPサーバー
(「210.173.160.27」は例示)と時間が1秒ずれていたら警告、2秒ずれていたら異常とする
        }

[root@ufuso ~]# /etc/rc.d/init.d/nagios restart ← Nagios再起動
Running configuration check...done
Stopping nagios: done.
Starting nagios: done.

(2)clamdClam AntiVirus導入済の場合のみ

[root@ufuso ~]# vi /etc/nagios/objects/commands.cfg ← commands.cfg編集
以下を最終行へ追加

# 'check_clamd' command definition
define command{
        command_name    check_clamd
        command_line    $USER1$/check_clamd -H $ARG1$
        }

[root@ufuso ~]# vi /etc/nagios/objects/localhost.cfg ← localhost.cfg編集
以下を最終行へ追加

define service{
        use                             generic-service
        host_name                       localhost
        service_description             clamd
        check_command                   check_clamd!/var/run/clamav/clamd.sock ←
 /var/run/clamav/clamd.sockはclamd.confのLocalSocketオプションで指定した値
        }

[root@ufuso ~]# /etc/rc.d/init.d/nagios restart ← Nagios再起動
Running configuration check...done
Stopping nagios: done.
Starting nagios: done.

(3)DNSBIND導入済の場合のみ

[root@ufuso ~]# vi /etc/nagios/objects/commands.cfg ← commands.cfg編集
以下を最終行へ追加

# 'check_dig' command definition
define command{
        command_name    check_dig
        command_line    $USER1$/check_dig -H $HOSTADDRESS$ -l $ARG1$
        }

[root@ufuso ~]# vi /etc/nagios/objects/localhost.cfg ← localhost.cfg編集
以下を最終行へ追加

define service{
        use                             generic-service
        host_name                       localhost
        service_description             DNS
        check_command                   check_dig!ufuso.dip.jp ← 名前解決ホスト名に自ドメイン
名を指定
        }

[root@ufuso ~]# /etc/rc.d/init.d/nagios restart ← Nagios再起動
Running configuration check...done
Stopping nagios: done.
Starting nagios: done.

(4)SMTPメールサーバー導入済の場合のみ

[root@ufuso ~]# vi /etc/nagios/objects/localhost.cfg ← localhost.cfg編集
以下を最終行へ追加

define service{
        use                             generic-service
        host_name                       localhost
        service_description             SMTP
        check_command                   check_smtp
        }

[root@ufuso ~]# /etc/rc.d/init.d/nagios restart ← Nagios再起動
Running configuration check...done
Stopping nagios: done.
Starting nagios: done.

(5)POPメールサーバー導入済の場合のみ

[root@ufuso ~]# vi /etc/nagios/objects/commands.cfg ← commands.cfg編集
# 'check_pop' command definition
define command{
        command_name    check_pop
        command_line    $USER1$/check_pop -H $HOSTADDRESS$ $ARG1$ -s quit← 「-s quit」追加
        }
※「-s quit」はDovecotがpop3-login:Abortedlogin:rip=::ffff:127.0.0.1,lip=::ffff:127.0.0.1, 
securedというエラーメッセージをログに出力しないようにする対処

[root@ufuso ~]# vi /etc/nagios/objects/localhost.cfg ← localhost.cfg編集
以下を最終行へ追加

define service{
        use                             generic-service
        host_name                       localhost
        service_description             POP
        check_command                   check_pop
        }

[root@ufuso ~]# /etc/rc.d/init.d/nagios restart ← Nagios再起動
Running configuration check...done
Stopping nagios: done.
Starting nagios: done.

(6)IMAPメールサーバー導入済の場合のみ

[root@ufuso ~]# vi /etc/nagios/objects/commands.cfg ← commands.cfg編集
# 'check_imap' command definition
define command{
        command_name    check_imap
        command_line    $USER1$/check_imap -H $HOSTADDRESS$ -s "A2 logout"← 「-s "A2 logout"」追加
        }
※「-s "A2 logout"」はDovecotがimap-login: Aborted login: rip=::ffff:127.0.0.1,
 lip=::ffff:127.0.0.1, securedというエラーメッセージをログに出力しないようにする対処

[root@ufuso ~]# vi /etc/nagios/objects/localhost.cfg ← localhost.cfg編集
以下を最終行へ追加

define service{
        use                             generic-service
        host_name                       localhost
        service_description             IMAP
        check_command                   check_imap
        }

[root@ufuso ~]# /etc/rc.d/init.d/nagios restart ← Nagios再起動
Running configuration check...done
Stopping nagios: done.
Starting nagios: done.

(7)amavisdamavisd導入済の場合のみ

[root@ufuso ~]# vi /etc/nagios/objects/commands.cfg ← commands.cfg編集
以下を最終行へ追加

# 'check_amavisd' command definition
define command{
        command_name    check_amavisd
        command_line    $USER1$/check_tcp -H $HOSTADDRESS$ -p 10024
        }

[root@ufuso ~]# vi /etc/nagios/objects/localhost.cfg ← localhost.cfg編集
以下を最終行へ追加

define service{
        use                             generic-service
        host_name                       localhost
        service_description             amavisd
        check_command                   check_amavisd
        }

[root@ufuso ~]# /etc/rc.d/init.d/nagios restart ← Nagios再起動
Running configuration check...done
Stopping nagios: done.
Starting nagios: done.

(8)spamdSpamAssassin導入済の場合のみ

[root@ufuso ~]# vi /etc/nagios/objects/commands.cfg ← commands.cfg編集
以下を最終行へ追加

# 'check_spamd' command definition
define command{
        command_name    check_spamd
        command_line    $USER1$/check_tcp -H $HOSTADDRESS$ -p 783
        }

[root@ufuso ~]# vi /etc/nagios/objects/localhost.cfg ← localhost.cfg編集
以下を最終行へ追加

define service{
        use                             generic-service
        host_name                       localhost
        service_description             spamd
        check_command                   check_spamd
        }

[root@ufuso ~]# /etc/rc.d/init.d/nagios restart ← Nagios再起動
Running configuration check...done
Stopping nagios: done.
Starting nagios: done.

(9)SambaSamba導入済の場合のみ

[root@ufuso ~]# yum install samba-client ← 監視に必要なのでインストール
Setting up Install Process
Package samba-client-3.6.9-151.el6.x86_64 already installed and latest version
Nothing to do ← 既にインストール済

[root@ufuso ~]#  vi /usr/lib64/nagios/plugins/check_disk_smb ← check_disk_smbの編集
my $smbclient= "/usr/bin/smbclient" ; ← smbclientコマンドパス設定

[root@ufuso ~]# echo 192.168.24.240 ufuso.dip.jp >> /etc/samba/lmhosts ← lmhosts
へSambaサーバーのIPアドレス(例示「192.168.24.240」)/ホスト名(例示
「ufuso.dip.jp」)を追加
※SambaサーバーIPアドレスにループバックアドレス(127.0.0.1)は指定できない

[root@ufuso ~]# vi /etc/nagios/objects/commands.cfg ← commands.cfg編集
以下を最終行へ追加

# 'check_disk_smb' command definition
define command{
        command_name    check_disk_smb
        command_line    $USER1$/check_disk_smb -H $ARG1$ -s $ARG2$ -W $ARG3$ -u $ARG4$ -p $ARG5$
        }

[root@ufuso ~]# vi /etc/nagios/objects/localhost.cfg ← localhost.cfg編集
以下を最終行へ追加

define service{
        use                             generic-service
        host_name                       localhost
        service_description             Samba
        check_command                   check_disk_smb!ufuso.dip.jp!public!workgroup!user!password
        } ← 「ufuso.dip.jp」はSambaサーバーホスト名の例示、「public」はSamba
共有名の例示、「workgroup」はSambaワークグループ名の例示、「user」はSambaユーザー
名の例示、「password」はSambaユーザーパスワードの例示。Sambaで設定したとおり入力
のこと

[root@ufuso ~]# /etc/rc.d/init.d/nagios restart ← Nagios再起動
Running configuration check...done
Stopping nagios: done.
Starting nagios: done.

■Samba監視ができない不具合対応

[root@ufuso ~]# vi /usr/share/perl5/Getopt/Long.pm ← Long.pmファイルの487行目
当たりを表示
    # Process argument list
    my $goon = 1;
    while ( $goon && @$argv > 0 ) {

        # Get next argument.
        $opt = shift (@$argv) || ''; ← || ''(which is 2 | (pipe characters) and
 2 ' (single quotes)を追記
        print STDERR ("=> arg "", $opt, ""n") if $debug;

[root@ufuso ~]# /etc/rc.d/init.d/nagios restart ← Nagios再起動
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.

(10)MySQLMySQL導入済の場合のみ

[root@ufuso ~]# vi /etc/nagios/objects/commands.cfg ← commands.cfg編集
以下を最終行へ追加

# 'check_mysql' command definition
define command{
        command_name    check_mysql
        command_line    $USER1$/check_mysql -H $HOSTADDRESS$ -u $ARG1$ -p $ARG2$
        }

[root@ufuso ~]# vi /etc/nagios/objects/localhost.cfg ← localhost.cfg編集
以下を最終行へ追加

define service{
        use                             generic-service
        host_name                       localhost
        service_description             MySQL
        check_command                   check_mysql!root!password
        } ← 「password」はMySQLのrootユーザーパスワードの例示
[root@ufuso ~]# /etc/rc.d/init.d/nagios restart ← Nagios再起動
Running configuration check...done
Stopping nagios: done.
Starting nagios: done.

(11)メモリ空き状況監視を追加する

[root@ufuso ~]# wget https://www.nagios-plugins.org/download/nagios-plugins-1.4.16.tar.gz
 ← Nagios-Pluginsのダウンロード
※最新版のURLはダウンロードページで確認すること
`nagios-plugins-1.4.16.tar.gz' に保存中

100%[===========================>] 2,087,089    910K/s 時間 2.2s    

2013-04-21 09:31:49 (910 KB/s) - `nagios-plugins-1.4.16.tar.gz' へ保存完了 [2087089/2087089]

[root@ufuso  ~]# tar zxvf nagios-plugins-1.4.16.tar.gz ← Nagios-Pluginsの展開

[root@ufuso ~]# cp nagios-plugins-1.4.16/contrib/check_mem.pl /usr/lib64/nagios/plugins/
 ← check_mem.plをpluginsフォルダにコピー

[root@ufuso ~]# vi /usr/lib64/nagios/plugins/check_mem.pl
 ← check_mem.plの編集
# This the unix command string that brings Perl the data
#$command_line = `vmstat | tail -1 | awk '{print \$4,\$5}'`; ← 行頭に#を付加
して無効化
$command_line = `free | head -3 | tail -1 | awk '{print \$3,\$4}'`; ← 追記

[root@ufuso ~]# vi /etc/nagios/objects/commands.cfg ← commands.cfg編集
以下を最終行へ追加

# 'check_mem' command definition
define command{
        command_name    check_mem
        command_line    $USER1$/check_mem.pl -f -w $ARG1$ -c $ARG2$
        }

[root@ufuso ~]# vi /etc/nagios/objects/localhost.cfg ← localhost.cfg編集
以下を最終行へ追加

define service{
        use                             generic-service
        host_name                       localhost
        service_description             Memory Free
        check_command                   check_mem!20!10 ← 空きメモリ量が20%で
警告、10%で異常とする
        }

[root@ufuso ~]# /etc/rc.d/init.d/nagios restart ← Nagios再起動
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.

[root@ufuso ~]# rm -rf nagios-plugins-1.4.16 ← 展開したフォルダの削除

[root@ufuso ~]# rm -f nagios-plugins-1.4.16.tar.gz ← ダウンロードしたファイル
の削除

http://サーバー名/nagios/へアクセスし、「サービス」で追加したサービスが表示されることを確認。
我が家では18項目を監視しています。黄色のWarningがあるので、定期的にメールが飛んできます。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください