nagios安裝、配置、PNP與飛信報警

一、創建nagios用戶和用戶組

[root@localhost ~]#useradd -s /sbin/nologin nagios

[root@localhost ~]#mkdir /usr/local/nagios

[root@localhost ~]#chown -R nagios.nagios /usr/local/nagios

二、開啓系統sendmail服務

[root@localhost ~]#service sendmail start

三、編譯安裝nagios

[root@localhost ~]# tar -zxvf  nagios-3.2.0.tar.gz

[root@localhost ~]# cd nagios-3.2.0

[root@localhost nagios-3.2.0]#./configure --prefix=/usr/local/nagios

#指定nagios的安裝目錄,這裏指定nagios安裝到/usr/local/nagios目錄

[root@localhost nagios-3.2.0]#make all

[root@localhost nagios-3.2.0]#make install

# make install用來安裝nagios的主程序,CGI和HTML文件

[root@localhost nagios-3.2.0]# make install-init

#通過make install-init命令可以在/etc/rc.d/init.d目錄下創建nagios啓動腳本

[root@localhost nagios-3.2.0]# make install-commandmode

#通過make install-commandmode命令來配置目錄權限

[root@localhost nagios-3.2.0]# make install-config

#make install-cofig命令用來安裝nagios示例配置文件,這裏安裝的路徑是/usr/local/nagios/etc

nagios安裝完成後,目錄對應的功能說明如下:

bin:可執行程序所在目錄

etc:配置文件所在目錄

sbin:cgi文件所在目錄,也就是執行外部命令所需文件所在目錄

share:網頁文件所在目錄

libexec:外部插件所在目錄

var:日誌文件,lock等文件所在目錄

var/archives:日誌自動歸檔目錄

var/rw:用來存放外部命令文件的目錄

四、安裝nagios的插件

以nagios-plugins-1.4.14爲例,插件版本與nagios版本關係並不大。

[root@localhost nagios]#tar -zxvf  nagios-plugins-1.4.14.tar.gz

[root@localhost nagios]#cd  nagios-plugins-1.4.14

[root@localhost nagios-plugins-1.4.14]#./configure --prefix=/usr/local/nagios

[root@localhost nagios-plugins-1.4.14]# make

[root@localhost nagios-plugins-1.4.14]# make install

查看/usr/local/nagios/libexec,會看到新增很多的插件。

五、安裝Nagios中文化插件

下載地址:http://sourceforge.net/projects/nagios-cn/files/

此處切忌版本要與nagios的版本對應。

[root@localhost ~]#tar jxvf nagios-cn-3.2.0.tar.bz2

[root@localhost nagios-cn-3.2.0]#cd nagios-cn-3.2.0

[root@localhost nagios-cn-3.2.0]#./configure

[root@localhost nagios-cn-3.2.0]#make all

[root@localhost nagios-cn-3.2.0]#make install

六、配置httpd和php

修改httpd的配置文件/etc/httpd/conf/httpd.conf

找到如下兩行

User apache

Group apache

#如果找不到,請通過搜索nobody尋找

修改爲

User nagios

Group nagios

然後找到

DirectoryIndex index.html index.html.var

修改爲

DirectoryIndex index.html index.html.var index.php

再在其下增加如下行

AddType application/x-httpd-php .php

在配置文件末尾增加如下信息:

#setting for nagios

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"

        <Directory "/usr/local/nagios/sbin">

            AuthType Basic

            Options ExecCGI

            AllowOverride None

            Order allow,deny

            Allow from all

            AuthName "Nagios Access"

AuthUserFile /usr/local/nagios/etc/htpasswd

            Require valid-user

        </Directory>

Alias /nagios "/usr/local/nagios/share"

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

            AuthType Basic

            Options None

            AllowOverride None

            Order allow,deny

            Allow from all

            AuthName "nagios Access"

AuthUserFile /usr/local/nagios/etc/htpasswd

            Require valid-user

        </Directory>

保存配置文件

七、新增驗證文件

[root@localhost]# /usr/bin/htpasswd -c /usr/local/nagios/etc/htpasswd yilei

New password: (輸入密碼)

Re-type new password: (再輸入一次密碼)

Adding password for useryilei

在/usr/local/nagios/etc下就會新增一個htpasswd驗證文件。

八、驗證

[root@localhost]#service httpd restart

[root@localhost]#service nagios start

通過瀏覽器輸入http://ip/nagios/

輸入用戶名/密碼,就可以看到nagios的管理界面啦。此時看到的界面中沒有任何監控機的信息。

九、配置聯繫人

1、修改contacts.cfg(聯繫人配置文件)

define contact{

       contact_name                    yilei           ; Short name of user

       use                             generic-contact         ; Inherit default values from generic-contact templ

ate (defined above)

       alias                           yilei Admin             ; Full name of user

       email                           [email protected]  ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

       pager                           158********

       }

聯繫人組

define contactgroup{

       contactgroup_name       admins

       alias                   Nagios Administrators

       members                 yilei

       }

十.配置主機和服務

1.添加主機

Vim  hosts.cfg

define host{

     use                     linux-server

     host_name                ftp

     alias                    yilei-ftp

     address                 192.168.0.8

     }

define host{

     use                     linux-server

     host_name                ceshi

     alias                    yilei-web2

     address                 192.168.0.122

     }

define host{

       use                     linux-server

       host_name                 web

       alias                    gonpo-web

       address                 gp.gonpo.cn

     check_interval                     5

     retry_interval                     1

     max_check_attempts                 5

     check_period                     24x7

     process_perf_data                 0

     retain_nonstatus_information      0

     contact_groups                  admins

     notification_interval            30

     notification_period             24x7

     notification_options            d,u,r

      }

define hostgroup{

hostgroup_name  sa-servers

alias           sa servers

members         ftp,web1,ceshi

}

2.添加服務

Vim services.cfg

efine service{

       use                             local-service

       host_name                       ftp

       service_description             PING

       check_command                   check_ping!100.0,20%!500.0,60%

       }

define service{

       use                             local-service

       host_name                       web

       service_description             SSH

       check_command                   check_ssh

       }

define service{

       use                             local-service

       host_name                       web

       service_description             HTTP

       check_command                   check_http

       }

define service{

       use                             local-service

       host_name                       weibo

       service_description             check_load

       check_command                   nrpe!check_load

      }

2、修改cgi.cfg

default_user_name=yilei    ;將用戶名修改爲nagios界面登錄的用戶名

3.修改nagios.cfg

添加

cfg_file=/usr/local/nagios//etc/objects/hosts.cfg

cfg_file=/usr/local/nagios//etc/objects/services.cfg

3、使用命令:/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg檢查配置是否有誤

7、重啓nagios:service nagios restart


詳細演示:http://www.idoule.com/index.html



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章