nagios部署安装

一.支持PHP的apachehe,和nagios安装依赖包。

#yum –y install httpd php gd gcc gcc-g++ mysql mysql-devel

 

二.下载安装包

http://www.nagios.org/download

 

 

三. 安装

   1.  建用户和组

[root@localhost~]# groupadd nagios
[root@localhost~]# useradd -g nagios -G nagios -m -s /sbin/nologin nagios

 

2.解压安装文件

 

[root @localhost ~]# mkdir /usr/src/nagios/
[root @localhost ~]# tar zxvf nagios-3.3.1.tar.gz -C /usr/src/nagios/
[root @localhost ~]# tar zxvf
nagios-plugins-1.4.15.tar.gz -C/usr/src/nagios/
[root @localhost ~]# tar zxvf nrpe-2.12.tar.gz -C /usr/src/nagios/

 

3安装 nagios-3.3.1.tar.gz

[root @localhost nagios]#cd
/usr/src/nagios/nagios
[root @localhost nagios]# ./configure --prefix=/usr/local/nagios --with-command-group=nagios
[root @localhost nagios]# make all
[root @localhost nagios]# make install
[root @localhost nagios]# make install-init
[root @localhost nagios]# make install-commandmode
[root @localhost nagios]# make install-config

注意如果报错:

/usr/bin/install: omitting directory `includes/rss/extlib'

/usr/bin/install: omitting directory `includes/rss/htdocs'

/usr/bin/install: omitting directory `includes/rss/scripts'

make[1]: *** [install] Error 1

make[1]: Leaving directory `/usr/src/nagios/nagios/html'

make: *** [install] Error 2

 

措施:

[root@localhost nagios]# sed -i 's/for file in includes\/rss\/\*\;/for file in includes\/rss\/\*\.\*\;/g' ./html/Makefile

[root@localhost nagios]# sed -i 's/for file in includes\/rss\/extlib\/\*\;/for file in includes\/rss\/extlib\/\*\.\*\;/g' ./html/Makefile

执行这两句代码。

重新make install

[root@localhost nagios]# make install

 

 

4.安装nagios-plugins-1.4.15.tar.gz

[root @localhost nagios]# cd/usr/src/nagios/nagios-plugins-1.4.15/
[root @localhost nagios-plugins-1.4.15]# ./configure --with-nagios-user=nagios--with-nagios-group=nagios --prefix=/usr/local/nagios/
[root @localhost nagios-plugins-1.4.15]#make && make install

 

5.安装nrpe-2.12.tar.gz

[root @localhost nagios-plugins-1.4.15]# cd /usr/src/nagios/nrpe-2.12/
[root @localhost nrpe-2.12]# ./configure --prefix=/usr/local/nagios/  
[root @localhost nrpe-2.12]# make all
[root @localhost nrpe-2.12]# make install-plugin

6.设置Apache开机启动

[root @monitor ~]# vi /etc/rc.d/rc.local
#增加如下一行
/usr/local/apache/bin/apachectlstart

 

四.配置WEB访问

[root @localhost nrpe-2.12]# vi /etc/httpd/conf/httpd.conf
#修改apache 运行用户
     User nagios
     Group nagios
 
 #支持PHP  添加 index.php
 DirectoryIndex index.php index.html index.html.var
 
 
  #在最后加入nagios web访问部分
 
  ScriptAlias/nagios/cgi-bin
"/usr/local/nagios/sbin/"
Alias/nagios
"/usr/local/nagios/share/"
<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>
<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>

配置web访问用户密码

[root@localhostnrpe-2.12]# htpasswd -c /usr/local/nagios/etc/htpasswd nagiosadmin     #密码输入
[root @localhost nrpe-2.12]# service httpd start

在浏览器输入http://IP/nagios  出现如图

          image2012-4-17+15%3A38%3A6.png?version=1&modificationDate=1334652633000

出现web访问配置正确.

 

五.配置nagios

说明:服务器分三个组,linuxserver,windowsserver,networkserver(如交换机,路由器)。

  配置实验说明.

IP

服务器OS

监控服务

192.168.20.194

监控机LINUX

Mysql,squid,ssh,ping

192.168.20.184

LINUX

Mysql,httpd,ssh,ping

192.168.20.187

windows

3389,21,ping

192.168.20.1

switch

ping

   

A. 配置联系人

先备份原配置文件

[root @localhost objects]# cd /usr/local/nagios/etc/objects/
[root @localhost objects]# tar zcvf back.tar.gz ./*
 
 
[root @localhost objects]# vi 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                           chunjian.feng@jrj.com.cn
                        #pager                          13800138000
                        }
 
                                                define contactgroup{
                        contactgroup_name       admins
                        alias                  Nagios Administrators
                        members                 nagiosadmin
                        }

 

B. 配置命令文件

[root @localhost objects]# vi commands.cfg
添加下面两个命令
 
                                    definecommand{
                        command_name    check_nrpe
                        command_line    $USER1$/check_nrpe-H $HOSTADDRESS$ -c $ARG1$
                        }
                    definecommand{
                        command_name    check_mysql
                        command_line    $USER1$/check_mysql-u $ARG1$ -p $ARG2$ -H $HOSTADDRESS$ -P $ARG3$ -d $ARG4$ $ARG5$
                        }

 

C.配置templates.cfg

[root @localhost objects]# vi templates.cfg
#清空里面的内容添加下配置
 
 
                    define host{
                        name                    generic-host
                        contact_groups          admins
                        check_command           check-host-alive
                        max_check_attempts      5
                        notification_interval   10
                        notification_period     24x7
                        notification_options    d,u,r
                        }
                    define service{
                        name                    generic-service
                        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
                        }

 

D.配置linux服务器组

我们把只带的localhost.cfg改为LINUX server的定义文件。

[root @localhost objects]# vi localhost.cfg
#清空
 
 define hostgroup{
        hostgroup_name  linux-servers
        alias          Linux Servers
        members         localhost,192.168.20.184   
        }
 
 
 define host{
         use                     generic-host                                                                                                 
         host_name               localhost
         alias                  localhost
         address                 127.0.0.1
        }
################localhost server
                        define service{
                                          host_name               localhost
                                          service_description     load average
                                          check_command           check_nrpe!check_load
                                          use                     generic-service
                                          }
 
 
                           define service{
                                          host_name               localhost
                                          service_description     total-procs
                                          check_command           check_nrpe!check_total_procs
                                          use                     generic-service
                                          }
 
                           define service{
                                          host_name               localhost
                                          service_description    freespace
                                          check_command           check_nrpe!check_disk
                                          use                     generic-service
                                          }
 
                           define service{
                                             host_name               localhost
                                               service_description     mysql
                                               check_command          check_mysql!root!123456
                                               use                    generic-service
                                               }
 
                           define service{
 
                                            use                            generic-service     
                                            host_name                       localhost
                                           service_description             PING
                                          check_command               check_ping!100.0,20%!500.0,60%
                                           }
 
 
                              define service{
                                             use                            generic-service        ; Name ofservice template to use
                                             host_name                       localhost
                                             service_description             SSH
                                            check_command               check_ssh
                                            notifications_enabled              0
                                            }
 
 
                              define service{
                                          host_name            localhost
                                          service_description  squid
                                          check_command        check_tcp!80
                                          use                     generic-service
                                          }
 
###################################192.168.20.184
 
              
                         definehost{
                                 use                    generic-host                                                                                                                  
                                 host_name               192.168.20.184
                                 alias                  192.168.20.184
                                 address                 192.168.20.184
                                   }
 
                           define service{
                                    host_name               192.168.20.184
                                    service_description     load average
                                    check_command           check_nrpe!check_load
                                     use                     generic-service
                                      }
                               define service{
                                          host_name               192.168.20.184
                                          service_description     total-procs
                                          check_command           check_nrpe!check_total_procs
                                          use                     generic-service
                                          }
 
                           define service{
                                          host_name               192.168.20.184
                                          service_description    freespace
                                          check_command           check_nrpe!check_disk
                                          use                     generic-service
                                          }
 
                           define service{
                                             host_name               192.168.20.184
                                               service_description     mysql
                                               check_command          check_mysql!root!123456
                                               use                    generic-service
                                               }
 
                           define service{
 
                                            use                            generic-service     
                                            host_name                       192.168.20.184
                                           service_description             PING
                                          check_command               check_ping!100.0,20%!500.0,60%
                                           }
 
 
                              define service{
                                             use                            generic-service        ; Name ofservice template to use
                                             host_name                      192.168.20.184
                                             service_description             SSH
                                            check_command               check_ssh
                                            notifications_enabled              0
                                            }
 
 
                              define service{
                                 use                            generic-service      
                                  host_name                        192.168.20.184
                                 service_description             HTTP
                                 check_command               check_http
                                 notifications_enabled              0
                                    }  
 

 

注:windows 和switch类似的定义。我们分别用自带的windows.cfg,switch.cfg文件配置。

E.开启nagios进程

[root @monitor ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors:   0
 
 
[root @monitor ~]# /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
[root @monitor ~]#echo "/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg" >> /etc/rc.d/rc.local

 

 

 

六.配置linux客户端

A.建立用户和安装客户端。

[root@LNMP4 ~]# yum install bc
Useradd nagios
tar-zxvf nagios-plugins-1.4.14.tar.gz
cdnagios-plugins-1.4.14
./configure--with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios
make&&makeinstall
 
tar-zxvf nrpe-2.12.tar.gz
cdnrpe-2.12
./configure--prefix=/usr/local/nagios
makeall
makeinstall-plugin
makeinstall-daemon
makeinstall-daemon-config
chown-R nagios.nagios/usr/local/nagios
 

 

B.配置被监控机

vim/usr/local/pmediasrv/nagios/etc/nrpe.cfg
 allowed_hosts=127.0.0.1,192.168.20.194  #监控机的IP和本机IP
 
command[check_load]=/usr/local/pmediasrv/nagios/libexec/check_load-w 15,10,5 -c 30,25,20
command[check_total_procs]=/usr/local/pmediasrv/nagios/libexec/check_procs-w 150 -c 200
command[check_disk]=/usr/local/nagios/libexec/check_disk-w 20% -c 10%
 

启动客户端进程:

/usr/local/pmediasrv/nagios/bin/nrpe-c/usr/local/pmediasrv/nagios/etc/nrpe.cfg –d

 

七.配置windows 客户端。

下载客户端地址:

http://files.nsclient.org/x-0.3.x_STABLE/NSClient%2B%2B-0.3.7-Win32.msi   32位

http://files.nsclient.org/x-0.3.x_STABLE/NSClient%2B%2B-0.3.7-x64.msi      64位

 

下载安装好。配置,在安装目录下编辑NSC.ini

[modules]
FileLogger.dll
CheckSystem.dll
CheckDisk.dll
NSClientListener.dll
NRPEListener.dll
SysTray.dll
CheckEventLog.dll
CheckHelpers.dll
;CheckWMI.dll
; RemoteConfiguration IS AN EXTREM EARLY IDEA
SO DONT USE FOR PRODUCTION ENVIROMNEMTS!
;RemoteConfiguration.dll
; NSCA Agent is anewbeta module use with care!
NSCAAgent.dll
; LUA script module used to write your own
"check deamon"(sort of) early beta.
LUAScript.dll
; Script to check external scripts and/or
internal aliases, early beta.
CheckExternalScripts.dll
; Check other hosts through NRPE extreme beta
and probably a bit dangerous! :)
NRPEClient.dll
; Extreamly early beta of a task-schedule
checker
CheckTaskSched.dll
 
 
 
最后配置
allowed_hosts=127.0.0.1/32,192.168.20.194  允许192.168.20.194
port=12489         监听端口
 

注:重新启动客户端

 

转载于:https://my.oschina.net/u/214948/blog/89507

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值