nagiosモニタ三部作-nagiosのインストールと構成(1)
最近、会社はオンライン監視システムを必要とし、多くの監視を配置する必要があり、環境と設備もほとんど異なるので、私は監視をインストールする技術ドキュメントを書いて、私の会社の運営維持に私のドキュメントに基づいて監視の配置を行うようにしました.
私のシステムはredhat 5.4で、iptablesとselinuxを閉じました.
1
、インストールyum(本機にyumがある場合は、インストールせずにこのステップを3ステップまでスキップすることができます)
2、apacheのインストール(本機がデフォルトでインストールされている場合は、このステップをスキップして、インストールされていない場合はyumインストールできます)
nagiosのインストールにはいくつかの基礎サポートキットが必要です
3、apacheを構成してnagiosをサポートする
(1)nagiosユーザの確立
(2)apache実行ユーザとグループを変更する.デフォルトはdaemonで、nagiosに変更する必要があります.これにより、インストールしたnagiosディレクトリにアクセスし、ブラウザインタフェースでnagiosを閉じたり、障害オブジェクトのアラーム情報の送信を停止したりするなど、関連するcgiコマンドを実行することができます.(nagiosを導入したとき、apacheのユーザーとグループを変更したり、問題が発生したりしなかったので、この手順は省略できます.)
(3)nagiosアクセスディレクトリ(nagiosのインストールパス/usr/local/nagios)を追加し、httpユーザー検証を使用します.次の内容をhttpd.confファイルの末尾に追加します.
4、nagiosのインストール
5、nagiosプラグインnagios-pluginのインストール
6
、nagiosの構成
ここで指定したユーザー
”nagios”
ブラウザで操作可能
nagios
サービスのクローズ、再起動など各種操作
[root@localhost etc]# sed -i 's/nagiosadmin/nagios/g' cgi.cfg ##
またはこのコマンドで変更します.
7
、nrpeの取り付け
ファイルのコピー
nrpeの構成
nrpe.cfgの構成の問題を修正し、サービス側であれば修正せず、クライアントであれば以下を修正します.
allowed_hosts=127.0.0.1
allowed_hostsでサービス都のipに加入できます
nagiosとnrpeの所属ユーザーとグループを変更する
8、nagiosを起動する
まずnagiosの構成に問題があるかどうかを確認します
問題がなければnagiosを起動します
Web認証ユーザーの作成
起動nrpeの作成
sendmailを起動し、アラームを受信
その後、httpdサービスを切断するとアラームが表示されます.解決できない問題が発生したら、連絡してください.
あるいは私の次の文章を直接閲覧します」
文章はなぜnagiosがアラームメールを発生できないのか
」、住所はhttp://dl528888.blog.51cto.com/2382721/763079
私のシステムはredhat 5.4で、iptablesとselinuxを閉じました.
1
、インストールyum(本機にyumがある場合は、インストールせずにこのステップを3ステップまでスキップすることができます)
- [root@localhost yum.repos.d]# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.i386.rpm
- root@localhost yum.repos.d]# wget http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
- [root@localhost yum.repos.d]# rpm -Uvh rpmforge-release-0.5.1-1.el5.rf.i386.rpm
- root@localhost yum.repos.d]# rpm --import RPM-GPG-KEY.dag.txt
- [root@localhost yum.repos.d]# yum install yum-fastestmirror yum-presto
2、apacheのインストール(本機がデフォルトでインストールされている場合は、このステップをスキップして、インストールされていない場合はyumインストールできます)
- [root@localhost ~]# yum -y install httpd
nagiosのインストールにはいくつかの基礎サポートキットが必要です
- [root@localhost etc]# yum -y install gd gd-devel glibc glibc-common gcc
3、apacheを構成してnagiosをサポートする
(1)nagiosユーザの確立
- [root@localhost ~]# useradd nagios
- [root@localhost etc]# /usr/sbin/groupadd nagcmd nagcmd , web
- [root@localhost etc]# /usr/sbin/usermod -a -G nagcmd nagios nagios nagcmd
- [root@localhost etc]# /usr/sbin/usermod -a -G nagcmd apache apache nagcmd
- [root@localhost etc]# /usr/sbin/usermod -a -G apache nagios nagios apache
- [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ファイルの末尾に追加します.
- ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
- <Directory "/usr/local/nagios/sbin">
- Options ExecCGI
- AllowOverride None
- Order allow,deny
- Allow from all
- AuthName "Nagios Access"
- AuthType Basic
- AuthUserFile /usr/local/nagios/etc/htpasswd
- Require valid-user
- Directory>
- Alias /nagios /usr/local/nagios/share
- <Directory "/usr/local/nagios/share">
- Options None
- AllowOverride None
- Order allow,deny
- Allow from all
- AuthName "Nagios Access"
- AuthType Basic
- AuthUserFile /usr/local/nagios/etc/htpasswd
- Require valid-user
- Directory>
4、nagiosのインストール
- [root@localhost tmp]# tar zxvf nagios-3.3.1.tar.gz
- [root@localhost nagios]# ./configure --prefix=/usr/local/nagios -with-command-group=nagcmd
- [root@localhost nagios]# make all
- [root@localhost nagios]# make install
- [root@localhost nagios]# make install-init
- [root@localhost nagios]# make install-config
- [root@localhost nagios]# make install-commandmode
- [root@localhost nagios]# make install-webconf
5、nagiosプラグインnagios-pluginのインストール
- [root@localhost nagios]#cd /tmp
- [root@localhost tmp]# tar zxvf nagios-plugins-1.4.15.tar.gz
- [root@localhost nagios-plugins-1.4.15]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
- [root@localhost nagios-plugins-1.4.15]# make
- [root@localhost nagios-plugins-1.4.15]# make install
6
、nagiosの構成
- [root@localhost nagios-plugins-1.4.15]# cd /usr/local/
- [root@localhost local]# chown -R nagios:nagios nagios/
- [root@localhost local]# chown -R nagios:nagios nagios/*
- [root@localhost local]# cd nagios/etc/
- [root@localhost etc]# vim nagios.cfg ### nagios.cfg , :
- cfg_file=/usr/local/nagios/etc/hosts.cfg #
- cfg_file=/usr/local/nagios/etc/hostgroups.cfg #
- cfg_file=/usr/local/nagios/etc/contacts.cfg #
- cfg_file=/usr/local/nagios/etc/contactgroups.cfg #
- cfg_file=/usr/local/nagios/etc/services.cfg ##
- cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg #
- cfg_file=/usr/local/nagios/etc/objects/commands.cfg #
- cgi.cfg , :
- [root@localhost etc]# vim cgi.cfg
- # ,
- authorized_for_system_information=nagios
- authorized_for_configuration_information= nagios
- authorized_for_system_commands= nagios
- authorized_for_all_services= nagios
- authorized_for_all_hosts= nagios
- authorized_for_all_service_commands= nagios
- authorized_for_all_host_commands= nagios
ここで指定したユーザー
”nagios”
ブラウザで操作可能
nagios
サービスのクローズ、再起動など各種操作
[root@localhost etc]# sed -i 's/nagiosadmin/nagios/g' cgi.cfg ##
またはこのコマンドで変更します.
- (1)、 hosts.cfg
- define host{
- host_name web1## web1, hostname
- alias Nagios Server ## Server
- address 192.168.10.223## ip
- check_command check-host-alive ## ,
- , 。
- check_interval 5 ##
- retry_interval 1 ##
- max_check_attempts 5 ##
- check_period 24x7 ##
- process_perf_data 0
- retain_nonstatus_information 0
- contact_groups admin ### ,
- notification_interval 30 ##
- notification_period 24x7 ##
- notification_options d,u,r #### , w warning,u unknown,c critial,r recovery( ); w,c,r
- }
- (2)、 hostgroups.cfg
- define hostgroup {
- hostgroup_name Nagios-Example ##
- alias Nagios Example ##
- members web1 ## , hosts.cfg hostname ,
- }
- (3)、 contacts.cfg
- define contact{
- contact_name nagiosadmin #
- alias Nagios Admin #
- service_notification_period 24x7 #
- host_notification_period 24x7 #
- service_notification_options w,u,c,r #
- host_notification_options d,u,r #
- service_notification_commands notify-service-by-email #
- host_notification_commands notify-host-by-email #
- email [email protected] #
- }
- (4)、 contactgroups.cfg
- define contactgroup{
- contactgroup_name admin #
- alias Nagios Administrators #
- members nagiosadmin # , contacts.cfg contact_name
-
- }
- (5)、 services.cfg
- define service {
- host_name web1 # hosts.cfg host-name
- service_description check-host-alive #
- check_period 24x7 #
- max_check_attempts 4 #
- normal_check_interval 3 #
- retry_check_interval 2 #
- contact_groups admin #
- notification_interval 10 #
- notification_period 24x7 #
- notification_options w,u,c,r # ,
- check_command check-host-alive #
- }
- define service {
- host_name web1
- service_description PING
- check_period 24x7
- max_check_attempts 4
- normal_check_interval 3
- retry_check_interval 2
- contact_groups admin
- notification_interval 10
- notification_period 24x7
- notification_options w,u,c,r
- check_command check_ping!100.0,20%!500.0,60%
- }
- define service {
- host_name web1
- service_description Root Partition
- check_period 24x7
- max_check_attempts 4
- normal_check_interval 3
- retry_check_interval 2
- contact_groups admin
- notification_interval 10
- notification_period 24x7
- notification_options w,u,c,r
- check_command check_local_disk!20%!10%!/
- }
- define service {
- host_name web1
- service_description Current Users
- check_period 24x7
- max_check_attempts 4
- normal_check_interval 3
- retry_check_interval 2
- contact_groups admin
- notification_interval 10
- notification_period 24x7
- notification_options w,u,c,r
- check_command check_local_users!20!50
- }
- define service {
- host_name web1
- service_description Total Processes
- check_period 24x7
- max_check_attempts 4
- normal_check_interval 3
- retry_check_interval 2
- contact_groups admin
- notification_interval 10
- notification_period 24x7
- notification_options w,u,c,r
- check_command check_local_procs!250!400!RSZDT
- }
- define service {
- host_name web1
- service_description Current Load
- check_period 24x7
- max_check_attempts 4
- normal_check_interval 3
- retry_check_interval 2
- contact_groups admin
- notification_interval 10
- notification_period 24x7
- notification_options w,u,c,r
- check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
- }
- define service {
- host_name web1
- service_description Swap Usage
- check_period 24x7
- max_check_attempts 4
- normal_check_interval 3
- retry_check_interval 2
- contact_groups admin
- notification_interval 10
- notification_period 24x7
- notification_options w,u,c,r
- check_command check_local_swap!20!10
- }
- define service {
- host_name web1
- service_description SSH
- check_period 24x7
- max_check_attempts 4
- normal_check_interval 3
- retry_check_interval 2
- contact_groups admin
- notification_interval 10
- notification_period 24x7
- notifications_enabled 0
- notification_options w,u,c,r
- check_command check_ssh
- }
- define service {
- host_name web1
- service_description HTTP
- check_period 24x7
- max_check_attempts 4
- normal_check_interval 3
- retry_check_interval 2
- contact_groups admin
- notification_interval 10
- notification_period 24x7
- notifications_enabled 0
- notification_options w,u,c,r
- check_command check_http
- }
7
、nrpeの取り付け
- [root@localhost etc]# cd /tmp/
- [root@localhost tmp]# tar zxvf nrpe-2.12.tar.gz
- [root@localhost tmp]# cd nrpe-2.12
- [root@localhost nrpe-2.12]# ./configure --prefix=/usr/local/nrpe
- [root@localhost nrpe-2.12]# make
- [root@localhost nrpe-2.12]# make install
ファイルのコピー
- [root@localhost nrpe-2.12]# cp /usr/local/nrpe/libexec/check_nrpe /usr/local/nagios/libexec
- [root@localhost nrpe-2.12]# cp /usr/local/nagios/libexec/check_disk /usr/local/nrpe/libexec
- [root@localhost nrpe-2.12]# cp /usr/local/nagios/libexec/check_load /usr/local/nrpe/libexec
- [root@localhost nrpe-2.12]# cp /usr/local/nagios/libexec/check_ping /usr/local/nrpe/libexec
- [root@localhost nrpe-2.12]# cp /usr/local/nagios/libexec/check_procs /usr/local/nrpe/libexec
nrpeの構成
- [root@localhost nrpe-2.12]# mkdir /usr/local/nrpe/etc
- [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に加入できます
- [root@localhost nrpe-2.12]# /usr/local/nrpe/bin/nrpe -c /usr/local/nrpe/etc/nrpe.cfg -d
- [root@localhost nrpe-2.12]# ps -ef|grep nrpe
- nagios 4465 1 0 21:02 ? 00:00:00 /usr/local/nrpe/bin/nrpe -c /usr/local/nrpe/etc/nrpe.cfg -d
- root 4467 12877 0 21:02 pts/2 00:00:00 grep nrpe
- [root@localhost nrpe-2.12]# lsof -i:5666
- COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
- nrpe 4465 nagios 4u IPv4 81685 TCP *:5666 (LISTEN)
nagiosとnrpeの所属ユーザーとグループを変更する
- [root@localhost local]# chown -R nagios:nagios /usr/local/nagios/*
- [root@localhost local]# chown -R nagios:nagios /usr/local/nrpe/*
8、nagiosを起動する
まずnagiosの構成に問題があるかどうかを確認します
- [root@localhost etc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
-
- Nagios Core 3.3.1
- Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
- Copyright (c) 1999-2009 Ethan Galstad
- Last Modified: 07-25-2011
- License: GPL
-
- Website: http://www.nagios.org
- Reading configuration data...
- Read main config file okay...
- Processing object config file '/usr/local/nagios/etc/objects/commands.cfg'...
- Processing object config file '/usr/local/nagios/etc/objects/timeperiods.cfg'...
- Processing object config file '/usr/local/nagios/etc/hosts.cfg'...
- Processing object config file '/usr/local/nagios/etc/hostgroups.cfg'...
- Processing object config file '/usr/local/nagios/etc/contacts.cfg'...
- Processing object config file '/usr/local/nagios/etc/contactgroups.cfg'...
- Processing object config file '/usr/local/nagios/etc/services.cfg'...
- Read object config files okay...
- Running pre-flight check on configuration data...
-
- Checking services...
- Checked 9 services.
- Checking hosts...
- Checked 1 hosts.
- Checking host groups...
- Checked 1 host groups.
- Checking service groups...
- Checked 0 service groups.
- Checking contacts...
- Checked 2 contacts.
- Checking contact groups...
- Checked 1 contact groups.
- Checking service escalations...
- Checked 0 service escalations.
- Checking service dependencies...
- Checked 0 service dependencies.
- Checking host escalations...
- Checked 0 host escalations.
- Checking host dependencies...
- Checked 0 host dependencies.
- Checking commands...
- Checked 24 commands.
- Checking time periods...
- Checked 5 time periods.
- Checking for circular paths between hosts...
- Checking for circular host and service dependencies...
- 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を起動します
- [root@localhost etc]# chkconfig --add nagios nagios
- [root@localhost etc]# chkconfig nagios on
- [root@localhost etc]# service nagios start nagios
Web認証ユーザーの作成
- [root@localhost etc]# htpasswd -c /usr/local/nagios/etc/htpasswd nagios
- New password:
- Re-type new password:
- Adding password for user nagios
起動nrpeの作成
- [root@localhost etc]#echo "/usr/local/nrpe/bin/nrpe -c /usr/local/nrpe/etc/nrpe.cfg -d" >>/etc/rc.local
sendmailを起動し、アラームを受信
- [root@localhost etc]#service sendmail start
その後、httpdサービスを切断するとアラームが表示されます.解決できない問題が発生したら、連絡してください.
あるいは私の次の文章を直接閲覧します」
文章はなぜnagiosがアラームメールを発生できないのか
」、住所はhttp://dl528888.blog.51cto.com/2382721/763079