189 8069 5689

Nagios远程监控

1.添加用户

创新互联成立与2013年,是专业互联网技术服务公司,拥有项目成都网站设计、成都网站制作网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元安丘做网站,已为上家服务,为安丘各地企业和个人服务,联系电话:13518219792

[root@server3 ~]# useradd nagios
2.安装nagios-plugins

[root@server3 ~]# tar zxf nagios-plugins-2.0.3.tar.gz
[root@server3 nagios-plugins-2.0.3]# ./configure --with-nagios-user=nagios --with
     --with-apt-get-command:
              --with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s
               --with-ping-command: /bin/ping -n -U -w %d -c %d %s
                       --with-ipv6: yes
                      --with-MySQL: /usr/bin/mysql_config
                    --with-openssl: yes
                     --with-gnutls: no
               --enable-extra-opts: yes
                       --with-perl: /usr/bin/perl
             --enable-perl-modules: no
                     --with-cgiurl: /nagios/cgi-bin
               --with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin
                   --enable-libtap: no
[root@server3 nagios-plugins-2.0.3]# make && make install

[root@server3 nagios]# pwd
/usr/local/nagios
[root@server3 nagios]# chown -R nagios.nagios *

3.安装 NRPE

[root@server3 ~]# tar zxf nrpe-2.15.tar.gz

[root@server3 nrpe-2.15]# ./configure

General Options:
 -------------------------
 NRPE port:    5666
 NRPE user:    nagios
 NRPE group:   nagios
 Nagios user:  nagios
 Nagios group: nagios

[root@server3 nrpe-2.15]# make all

4.安装插件、daemon和示例配置文件

#安装nrpe-plugin插件
[root@server3 nrpe-2.15]# make install-plugin

#安装nrpe daemon

[root@server3 nrpe-2.15]# make install-daemon
#安装daemon配置文件

[root@server3 nrpe-2.15]# make install-daemon-config

#安装xinetd脚本,NRPE daemon是作为xinetd下的一个服务来运行的,所以先安装好xinetd

[root@server3 nrpe-2.15]# yum install -y xinetd 

[root@server3 nrpe-2.15]# make install-xinetd

4.修改配置文件

[root@server3 nrpe-2.15]# vim /etc/xinetd.d/nrpe   #添加nagios服务端的地址

    only_from       = 172.25.16.2        #nagios 主机 ip 地址

[root@server3 ~]# vim /usr/local/nagios/etc/nrpe.cfg

    allowed_hosts=172.25.16.2    #允许监测主机的IP

5.编辑/etc/services文件,增加NRPE服务

nrpe            5666/tcp                 #nrpe

6.重启服务

[root@server3 nrpe-2.15]# /etc/init.d/xinetd restart

[root@server3 nrpe-2.15]# netstat -antlp | grep 5666   #NRPE已经启动
tcp        0      0 :::5666                     :::*                        LISTEN      22872/xinetd    

#在监控主机上

1.安装NRPE,只需要check_nrpe插件,可直接从被监测端copy

[root@server3 libexec]# scp check_nrpe 172.25.16.2:/usr/local/nagios/libexec/

[root@server2 libexec]# chown nagios.nagios check_nrpe
[root@server2 libexec]# ll check_nrpe
-rwxr-xr-x. 1 nagios nagios 76769 Aug 29 23:36 check_nrpe
[root@server2 libexec]# ./check_nrpe -H 172.25.16.3  #输出nrpe的版本,说明监测机check_nrpe与被监测主机运行的nrpe daemon之间建立联系
NRPE v2.15
[root@server2 libexec]# vim /usr/local/nagios/etc/objects/commands.cfg

    # 'check_nrpe'
    define command{
            command_name    check_nrpe
            command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c "$ARG1$"  #-c后面的参数是传给被监测端nrpe daemon要执行的监测命令,这些命令在nrpe.cfg中要求已经定义

       }
[root@server3 ~]# grep -v '^#' /usr/local/nagios/etc/nrpe.cfg | sed '/^$/d'
log_facility=daemon
pid_file=/var/run/nrpe.pid
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=172.25.16.2
 dont_blame_nrpe=0
allow_bash_command_substitution=0
debug=0
command_timeout=60
connection_timeout=300
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200 

[root@server2 libexec]# vim /usr/local/nagios/etc/objects/services.cfg  #在这个里面定义的服务命令完全根据在被监控端nrpe.cfg中内置命令定义的,如上面命令所示

define service{
        use generic-service
        host_name server3.example.com
        service_description CPU Load
        check_command check_nrpe!check_load
        }
define service{
        use generic-service
        host_name server3.example.com
        service_description Current Users
        check_command check_nrpe!check_users
}

define service{
        use generic-service
        host_name server3.example.com
        service_description  / Free Space
        check_command check_nrpe!check_disk
}
define service{
        use generic-service
        host_name server3.example.com
        service_description Total Processes
        check_command  check_nrpe!check_total_procs
}

define service{
        use generic-service
        host_name server3.example.com
        service_description  Zombie Processes
        check_command check_nrpe!check_zombie_procs
}

#监测是否有语法错误并测试

[root@server2 libexec]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[root@server2 objects]#/usr/local/nagios/libexec/check_nrpe -H 172.25.16.3 -c check_load

OK - load average: 0.08, 0.02, 0.01|load1=0.080;15.000;30.000;0; load5=0.020;10.000;25.000;0; load15=0.010;5.000;20.000;0;

[root@server2 objects]# /usr/local/nagios/libexec/check_nrpe -H 172.25.16.3 -c check_users
USERS OK - 1 users currently logged in |users=1;5;10;0


当前标题:Nagios远程监控
分享URL:http://cdxtjz.cn/article/ijooho.html

其他资讯