nagiosモニタ三部作-nagiosのインストールと構成(1)


最近、会社はオンライン監視システムを必要とし、多くの監視を配置する必要があり、環境と設備もほとんど異なるので、私は監視をインストールする技術ドキュメントを書いて、私の会社の運営維持に私のドキュメントに基づいて監視の配置を行うようにしました.
私のシステムはredhat 5.4で、iptablesとselinuxを閉じました.
1
、インストールyum(本機にyumがある場合は、インストールせずにこのステップを3ステップまでスキップすることができます)
   
   
   
   
  1. [root@localhost yum.repos.d]# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.i386.rpm  
  2. root@localhost yum.repos.d]# wget http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt  
  3. [root@localhost yum.repos.d]# rpm -Uvh rpmforge-release-0.5.1-1.el5.rf.i386.rpm   
  4. root@localhost yum.repos.d]# rpm --import RPM-GPG-KEY.dag.txt  
  5. [root@localhost yum.repos.d]# yum install yum-fastestmirror yum-presto   

2、apacheのインストール(本機がデフォルトでインストールされている場合は、このステップをスキップして、インストールされていない場合はyumインストールできます)
   
   
   
   
  1. [root@localhost ~]# yum -y install httpd 

nagiosのインストールにはいくつかの基礎サポートキットが必要です
   
   
   
   
  1. [root@localhost etc]# yum -y install gd gd-devel glibc glibc-common gcc 

3、apacheを構成してnagiosをサポートする
(1)nagiosユーザの確立
   
   
   
   
  1. [root@localhost ~]# useradd nagios  
  2. [root@localhost etc]# /usr/sbin/groupadd nagcmd   nagcmd , web  
  3. [root@localhost etc]# /usr/sbin/usermod -a -G nagcmd nagios nagios nagcmd  
  4. [root@localhost etc]# /usr/sbin/usermod -a -G nagcmd apache apache nagcmd  
  5. [root@localhost etc]# /usr/sbin/usermod -a -G apache nagios nagios apache  
  6. [root@localhost etc]# /usr/sbin/usermod -a -G nagios apache apache nagios  

(2)apache実行ユーザとグループを変更する.デフォルトはdaemonで、nagiosに変更する必要があります.これにより、インストールしたnagiosディレクトリにアクセスし、ブラウザインタフェースでnagiosを閉じたり、障害オブジェクトのアラーム情報の送信を停止したりするなど、関連するcgiコマンドを実行することができます.(nagiosを導入したとき、apacheのユーザーとグループを変更したり、問題が発生したりしなかったので、この手順は省略できます.)
(3)nagiosアクセスディレクトリ(nagiosのインストールパス/usr/local/nagios)を追加し、httpユーザー検証を使用します.次の内容をhttpd.confファイルの末尾に追加します.
   
   
   
   
  1. ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin  
  2. <Directory "/usr/local/nagios/sbin"> 
  3. Options ExecCGI  
  4. AllowOverride None  
  5. Order allow,deny  
  6. Allow from all  
  7. AuthName "Nagios Access"  
  8. AuthType Basic  
  9. AuthUserFile /usr/local/nagios/etc/htpasswd  
  10. Require valid-user  
  11. Directory> 
  12. Alias /nagios /usr/local/nagios/share  
  13. <Directory "/usr/local/nagios/share"> 
  14. Options None  
  15. AllowOverride None  
  16. Order allow,deny  
  17. Allow from all  
  18. AuthName "Nagios Access"  
  19. AuthType Basic  
  20. AuthUserFile /usr/local/nagios/etc/htpasswd  
  21. Require valid-user  
  22. Directory> 

4、nagiosのインストール
   
   
   
   
  1. [root@localhost tmp]# tar zxvf nagios-3.3.1.tar.gz   
  2. [root@localhost nagios]# ./configure --prefix=/usr/local/nagios -with-command-group=nagcmd 
  3. [root@localhost nagios]# make all  
  4. [root@localhost nagios]# make install  
  5. [root@localhost nagios]# make install-init  
  6. [root@localhost nagios]# make install-config  
  7. [root@localhost nagios]# make install-commandmode  
  8. [root@localhost nagios]# make install-webconf  

5、nagiosプラグインnagios-pluginのインストール
   
   
   
   
  1. [root@localhost nagios]#cd /tmp  
  2. [root@localhost tmp]# tar zxvf nagios-plugins-1.4.15.tar.gz   
  3. [root@localhost nagios-plugins-1.4.15]# ./configure  --with-nagios-user=nagios --with-nagios-group=nagios   
  4. [root@localhost nagios-plugins-1.4.15]# make  
  5. [root@localhost nagios-plugins-1.4.15]# make install  

6
、nagiosの構成
   
   
   
   
  1. [root@localhost nagios-plugins-1.4.15]# cd /usr/local/  
  2. [root@localhost local]# chown -R nagios:nagios nagios/  
  3. [root@localhost local]# chown -R nagios:nagios nagios/*  
  4. [root@localhost local]# cd nagios/etc/  
  5. [root@localhost etc]# vim nagios.cfg    ### nagios.cfg , :  
  6. cfg_file=/usr/local/nagios/etc/hosts.cfg #  
  7. cfg_file=/usr/local/nagios/etc/hostgroups.cfg #  
  8. cfg_file=/usr/local/nagios/etc/contacts.cfg #  
  9. cfg_file=/usr/local/nagios/etc/contactgroups.cfg #  
  10. cfg_file=/usr/local/nagios/etc/services.cfg ##  
  11. cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg #  
  12. cfg_file=/usr/local/nagios/etc/objects/commands.cfg #  
  13. cgi.cfg , :  
  14. [root@localhost etc]# vim cgi.cfg  
  15. # ,  
  16. authorized_for_system_information=nagios   
  17. authorized_for_configuration_informationnagios 
  18. authorized_for_system_commandsnagios 
  19. authorized_for_all_servicesnagios 
  20. authorized_for_all_hostsnagios 
  21. authorized_for_all_service_commandsnagios 
  22. authorized_for_all_host_commandsnagios 

ここで指定したユーザー
”nagios”
ブラウザで操作可能
nagios
サービスのクローズ、再起動など各種操作
[root@localhost etc]# sed -i 's/nagiosadmin/nagios/g' cgi.cfg ##
またはこのコマンドで変更します.
   
   
   
   
  1. (1)、 hosts.cfg  
  2. define host{  
  3. host_name                               web1##  web1, hostname  
  4. alias Nagios                            Server  ## Server  
  5. address                                 192.168.10.223## ip  
  6. check_command                           check-host-alive ## ,  
  7. , 。  
  8. check_interval                          5  ##  
  9. retry_interval                          1 ##  
  10. max_check_attempts                      5 ##  
  11. check_period                            24x7 ##  
  12. process_perf_data                       0  
  13. retain_nonstatus_information            0  
  14. contact_groups                          admin       ### ,  
  15. notification_interval                   30    ##  
  16. notification_period                     24x7  ##  
  17. notification_options                    d,u,r    #### , w warning,u unknown,c critial,r recovery( ); w,c,r  
  18. }  
  19. (2)、 hostgroups.cfg  
  20. define hostgroup {  
  21. hostgroup_name                          Nagios-Example  ##  
  22. alias Nagios                            Example         ##  
  23. members                                 web1            ## , hosts.cfg hostname ,  
  24. }  
  25. (3)、 contacts.cfg  
  26. define contact{  
  27. contact_name                            nagiosadmin                 #  
  28. alias                                   Nagios Admin                #  
  29. service_notification_period             24x7                        #  
  30. host_notification_period                24x7                        #  
  31. service_notification_options            w,u,c,r                     #  
  32. host_notification_options               d,u,r                       #  
  33. service_notification_commands           notify-service-by-email     #  
  34. host_notification_commands              notify-host-by-email        #  
  35. email                                   [email protected]            #  
  36. }  
  37. (4)、 contactgroups.cfg  
  38. define contactgroup{  
  39. contactgroup_name               admin                       #  
  40. alias                           Nagios Administrators       #  
  41. members                         nagiosadmin                 # , contacts.cfg contact_name   
  42.  
  43. }  
  44. (5)、  services.cfg  
  45. define service {  
  46. host_name                 web1                # hosts.cfg host-name  
  47. service_description          check-host-alive #  
  48. check_period                 24x7     #  
  49. max_check_attempts           4 #  
  50. normal_check_interval           3 #  
  51. retry_check_interval            2 #  
  52. contact_groups               admin #  
  53. notification_interval           10 #  
  54. notification_period             24x7 #  
  55. notification_options            w,u,c,r # ,  
  56. check_command                check-host-alive #  
  57. }  
  58. define service {  
  59. host_name                web1   
  60. service_description             PING  
  61. check_period                 24x7   
  62. max_check_attempts           4   
  63. normal_check_interval           3  
  64. retry_check_interval            2  
  65. contact_groups               admin   
  66. notification_interval           10  
  67. notification_period             24x7   
  68. notification_options            w,u,c,r  
  69. check_command                check_ping!100.0,20%!500.0,60%  
  70. }  
  71. define service {  
  72. host_name                web1   
  73. service_description             Root Partition  
  74. check_period                 24x7   
  75. max_check_attempts           4   
  76. normal_check_interval           3  
  77. retry_check_interval            2  
  78. contact_groups               admin   
  79. notification_interval           10  
  80. notification_period             24x7   
  81. notification_options            w,u,c,r  
  82. check_command                check_local_disk!20%!10%!/  
  83. }  
  84. define service {  
  85. host_name                web1   
  86. service_description             Current Users  
  87. check_period                 24x7   
  88. max_check_attempts           4   
  89. normal_check_interval           3  
  90. retry_check_interval            2  
  91. contact_groups               admin   
  92. notification_interval           10  
  93. notification_period             24x7   
  94. notification_options            w,u,c,r  
  95. check_command                check_local_users!20!50  
  96. }  
  97. define service {  
  98. host_name                web1   
  99. service_description             Total Processes  
  100. check_period                 24x7   
  101. max_check_attempts           4   
  102. normal_check_interval           3  
  103. retry_check_interval            2  
  104. contact_groups               admin   
  105. notification_interval           10  
  106. notification_period             24x7   
  107. notification_options            w,u,c,r  
  108. check_command                check_local_procs!250!400!RSZDT  
  109. }  
  110. define service {  
  111. host_name                web1   
  112. service_description             Current Load  
  113. check_period                 24x7   
  114. max_check_attempts           4   
  115. normal_check_interval           3  
  116. retry_check_interval            2  
  117. contact_groups               admin   
  118. notification_interval           10  
  119. notification_period             24x7   
  120. notification_options            w,u,c,r  
  121. check_command                check_local_load!5.0,4.0,3.0!10.0,6.0,4.0  
  122. }  
  123. define service {  
  124. host_name                web1   
  125. service_description             Swap Usage  
  126. check_period                 24x7   
  127. max_check_attempts           4   
  128. normal_check_interval           3  
  129. retry_check_interval            2  
  130. contact_groups               admin   
  131. notification_interval           10  
  132. notification_period             24x7   
  133. notification_options            w,u,c,r  
  134. check_command                check_local_swap!20!10  
  135. }  
  136. define service {  
  137. host_name                web1   
  138. service_description             SSH  
  139. check_period                 24x7   
  140. max_check_attempts           4   
  141. normal_check_interval           3  
  142. retry_check_interval            2  
  143. contact_groups               admin   
  144. notification_interval           10  
  145. notification_period             24x7   
  146. notifications_enabled           0  
  147. notification_options            w,u,c,r  
  148. check_command                check_ssh  
  149. }  
  150. define service {  
  151. host_name                web1   
  152. service_description             HTTP  
  153. check_period                 24x7   
  154. max_check_attempts           4   
  155. normal_check_interval           3  
  156. retry_check_interval            2  
  157. contact_groups               admin   
  158. notification_interval           10  
  159. notification_period             24x7   
  160. notifications_enabled           0  
  161. notification_options            w,u,c,r  
  162. check_command                check_http  
  163. }  

7
、nrpeの取り付け
   
   
   
   
  1. [root@localhost etc]# cd /tmp/  
  2. [root@localhost tmp]# tar zxvf nrpe-2.12.tar.gz   
  3. [root@localhost tmp]# cd nrpe-2.12  
  4. [root@localhost nrpe-2.12]# ./configure --prefix=/usr/local/nrpe  
  5. [root@localhost nrpe-2.12]# make  
  6. [root@localhost nrpe-2.12]# make install  

ファイルのコピー
   
   
   
   
  1. [root@localhost nrpe-2.12]# cp /usr/local/nrpe/libexec/check_nrpe  /usr/local/nagios/libexec  
  2. [root@localhost nrpe-2.12]# cp /usr/local/nagios/libexec/check_disk  /usr/local/nrpe/libexec  
  3. [root@localhost nrpe-2.12]# cp /usr/local/nagios/libexec/check_load  /usr/local/nrpe/libexec  
  4. [root@localhost nrpe-2.12]# cp /usr/local/nagios/libexec/check_ping  /usr/local/nrpe/libexec  
  5. [root@localhost nrpe-2.12]# cp /usr/local/nagios/libexec/check_procs  /usr/local/nrpe/libexec  

nrpeの構成
   
   
   
   
  1. [root@localhost nrpe-2.12]# mkdir /usr/local/nrpe/etc  
  2. [root@localhost nrpe-2.12]# cp sample-config/nrpe.cfg /usr/local/nrpe/etc/  

nrpe.cfgの構成の問題を修正し、サービス側であれば修正せず、クライアントであれば以下を修正します.
allowed_hosts=127.0.0.1
allowed_hostsでサービス都のipに加入できます
   
   
   
   
  1. [root@localhost nrpe-2.12]# /usr/local/nrpe/bin/nrpe -c /usr/local/nrpe/etc/nrpe.cfg -d
  2. [root@localhost nrpe-2.12]# ps -ef|grep nrpe
  3. nagios 4465 1 0 21:02 ? 00:00:00 /usr/local/nrpe/bin/nrpe -c /usr/local/nrpe/etc/nrpe.cfg -d
  4. root 4467 12877 0 21:02 pts/2 00:00:00 grep nrpe
  5. [root@localhost nrpe-2.12]# lsof -i:5666
  6. COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
  7. nrpe 4465 nagios 4u IPv4 81685 TCP *:5666 (LISTEN)

nagiosとnrpeの所属ユーザーとグループを変更する
   
   
   
   
  1. [root@localhost local]# chown -R nagios:nagios /usr/local/nagios/*
  2. [root@localhost local]# chown -R nagios:nagios /usr/local/nrpe/*

8、nagiosを起動する
まずnagiosの構成に問題があるかどうかを確認します
   
   
   
   
  1. [root@localhost etc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
  2. Nagios Core 3.3.1
  3. Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
  4. Copyright (c) 1999-2009 Ethan Galstad
  5. Last Modified: 07-25-2011
  6. License: GPL
  7. Website: http://www.nagios.org
  8. Reading configuration data...
  9. Read main config file okay...
  10. Processing object config file '/usr/local/nagios/etc/objects/commands.cfg'...
  11. Processing object config file '/usr/local/nagios/etc/objects/timeperiods.cfg'...
  12. Processing object config file '/usr/local/nagios/etc/hosts.cfg'...
  13. Processing object config file '/usr/local/nagios/etc/hostgroups.cfg'...
  14. Processing object config file '/usr/local/nagios/etc/contacts.cfg'...
  15. Processing object config file '/usr/local/nagios/etc/contactgroups.cfg'...
  16. Processing object config file '/usr/local/nagios/etc/services.cfg'...
  17. Read object config files okay...
  18. Running pre-flight check on configuration data...
  19. Checking services...
  20. Checked 9 services.
  21. Checking hosts...
  22. Checked 1 hosts.
  23. Checking host groups...
  24. Checked 1 host groups.
  25. Checking service groups...
  26. Checked 0 service groups.
  27. Checking contacts...
  28. Checked 2 contacts.
  29. Checking contact groups...
  30. Checked 1 contact groups.
  31. Checking service escalations...
  32. Checked 0 service escalations.
  33. Checking service dependencies...
  34. Checked 0 service dependencies.
  35. Checking host escalations...
  36. Checked 0 host escalations.
  37. Checking host dependencies...
  38. Checked 0 host dependencies.
  39. Checking commands...
  40. Checked 24 commands.
  41. Checking time periods...
  42. Checked 5 time periods.
  43. Checking for circular paths between hosts...
  44. Checking for circular host and service dependencies...
  45. Checking global event handlers...
  46. Checking obsessive compulsive processor commands...
  47. Checking misc settings...
  48. Total Warnings: 0
  49. Total Errors: 0
  50. Things look okay - No serious problems were detected during the pre-flight check

問題がなければnagiosを起動します
   
   
   
   
  1.  [root@localhost etc]# chkconfig --add nagios  nagios  
  2. [root@localhost etc]# chkconfig nagios on      
  3. [root@localhost etc]# service nagios start     nagios  

Web認証ユーザーの作成
   
   
   
   
  1. [root@localhost etc]# htpasswd -c /usr/local/nagios/etc/htpasswd nagios  
  2. New password:   
  3. Re-type new password:   
  4. Adding password for user nagios  

起動nrpeの作成
   
   
   
   
  1. [root@localhost etc]#echo "/usr/local/nrpe/bin/nrpe -c /usr/local/nrpe/etc/nrpe.cfg -d" >>/etc/rc.local

sendmailを起動し、アラームを受信
   
   
   
   
  1. [root@localhost etc]#service sendmail start

その後、httpdサービスを切断するとアラームが表示されます.解決できない問題が発生したら、連絡してください.
あるいは私の次の文章を直接閲覧します」
文章はなぜnagiosがアラームメールを発生できないのか
」、住所はhttp://dl528888.blog.51cto.com/2382721/763079