天天看點

Nagios3.3.1配置文檔

               Nagios3.3.1 安裝文檔

##安裝php apache sendmail

yum install  httpd gd gd-devel php php-devel sendmail –y

service sendmail start

添加使用者群組,把使用者加入組

usermod nagios

passwd nagios

groupadd nagcmd

usermod  -g  nagcmd nagios

usermod  -G  nagcmd apache

##安裝nagios

wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.3.1.tar.gz

tar xvf nagios-3.3.1.tar.gz

cd nagios

./configure --prefix=/usr/local/nagios  --with-command-group=nagcmd

make all

      
make install

      
make install-init   

      
make install-config

      

make install-commandmode

make install-webconf

###檢測配置檔案

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

#### 設定管理者密碼

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

####安裝插件

wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz

tar xvf nagios-plugins-1.4.16.tar.gz

cd nagios-plugins-1.4.16

./configure --with-nagios-user=nagios --with-nagios-group=nagcmd

make

make install

Wget http://nagios.manubulon.com/nagios-snmp-plugins.1.1.1.tgz

tar xzf nagios-snmp-plugins.1.1.1.tgz

cd nagios_plugins

安裝perl 安裝子產品cpanm

wget --no-check-certificate http://bit.ly/cpanm

chmod u+x cpanm

mv cpanm /usr/bin

##安裝所需子產品,此處所需時間較長

cpanm  Crypt::DES Digest::MD5 Digest::SHA1 Digest::HMAC  Net::SNMP

. /install.sh

### 添加,設定服務

chkconfig --add nagios

chkconfig –level 35 httpd on

chkconfig –level 35 nagios on

###關閉SELINUX或者配置SELINUX安全上下文 建議關閉SELINUX

Setenforce 0

vim /etc/sysconfig/selinux 

SELINUX=disabled

chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/

chcon -R -t httpd_sys_content_t /usr/local/nagios/share/

chown –r nagios:nagcmd /usr/local/nagios

service httpd restart

service nagios start

##配置nagios

##contacts.cfg  報警聯系人配置

配置警報發送目标郵箱

vim contacts.cfg

email  [email protected]

##commands.cfg  監控指令定義

##templates.cfg   主機,服務模闆配

##tempaltes.cfg參數:

service_description                            #監控頁面顯示的服務名字

check_period            24x7                  監控周期設定            

max_check_attempts      4                     最大檢測嘗試次數

normal_check_interval   3                       正常檢測間隔時間

retry_check_interval    2                        重試檢測間隔時間

contact_groups          admins                  報警聯系組

notification_interval   10                         通知間隔                        

notification_period     24x7                      通知周期設定

notification_options    w,u,c,r                    定義什麼狀态時報警

## 添加監控指令 監控記憶體和交換分區使用情況

vim  commands.cfg

define command{

command_name check_snmp_memory

command_line $USER1$/check_snmp_mem.pl  –H $HOSTADDRESS$  -C public –w 90,5 –c 100,99

##添加被監控主機:

echo  cfg_file=/usr/local/nagios/etc/objects/web-123.cfg >>nagios.cfg

vim /usr/local/nagios/etc/objects/web-123.cfg

define host{

        use             windows-server      ##定義使用的模闆

        host_name       web-123              ##定義主機名為web-123

        alias           web-123-web       ##主機名稱

        address         192.168.1.2      ##主機IP位址

        hostgroups      linuxweb          ##将該主機歸到linuxweb這個組,如果要歸到多個組裡,用逗号分隔組名

}

define hostgroup{

        hostgroup_name  linuxweb

        alias           linux web servers

        members       web-123   #設定該組的成員,需要是在host中定義的主機名,多個成員請用逗号分隔

##這樣就定義了一個linuxweb組,将主機歸為一個組有兩種方法,一種是我們這種在主機的定義中去設定,另外一種是在組的設定中定義members。如下define hostgroup{

        alias           linuxweb

        members       web-123  ###設定該組的成員,需要是在host中定義的主機名,多個成員請用逗号分隔

        alias           linux web server

define service{

        use                            generic-service #使用的模闆,此處使用通用模闆        

hostgroup_name               linuxweb  ###将linuxweb所有成員都添加該服務

host_name                       web-123          #主機名

        service_description                check_snmp_memory     #監控頁面顯示的名字

        check_command                  check_snmp_memory     #監控服務指令

        ###關于監控參數,可在模闆定義,也可以在此處單獨定義。優先主機配置檔案中定義的參數。

service nagios restart

關于nagios-snmp-plugins插件的用法和功在http://nagios.manubulon.com/ 有詳細介紹。

到此處還沒有全部完畢。應根據實際更改

正常檢測時間

錯誤重複檢測時間

最大檢測次數

什麼狀态才報警

郵件報警頻率

計劃用perl來寫一個網頁,來添加主機和服務。