Nagios监控Linux系统

简介:

 一、Nagios监控主机配置

1、安装nrpe服务

解压缩

[root@nagios ~]# tar -zxvf nrpe-2.14.tar.gz

[root@nagios ~]# cd nrpe-2.14

编译

[[root@nagios nrpe-2.14]#./configure

root@nagios nrpe-2.14]# make all

[root@nagios nrpe-2.14]# make install-plugin

只运行这一步就行了,因为只需要check_nrpe插件

 

2、编辑commands.cfg文件定义nrpe对的使用

[root@nagios ~]# vim /usr/local/nagios/etc/objects/commands.cfg

在最后面增加如下内容:

213 # 'check_nrpe ' command definition

214 define command{

215         command_name check_nrpe

216         command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

217         }

:wq

说明:

command_name check_nrpe

定义命令名称为check_nrpe,services.cfg中要使用这个名称.

command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

这是定义实际运行的插件程序.这个命令行的书写要完全按照check_nrpe这个命令的用法.不知道用法的就用check_nrpe h查看

-c后面带的$ARG1$参数是传给nrpe daemon执行的检测命令,之前说过了它必须是nrpe.cfg中所定义的那5条命令中的其中一条.services.cfg中使用check_nrpe的时候要用!带上这个参数

 

3、配置监控对象(工作站及其服务等)

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

cfg_file=/usr/local/nagios/etc/objects/localhost.cfg下添加:

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

:wq

 

4、新建linux.cfg设置要监控的内容

[root@nagios ~]# cd /usr/local/nagios/etc/object

[root@nagios ~]# vim linux.cfg

define host{

           use            linux-server

          host_name       web

          alias           web

          address         10.10.10.253

               }

 

define service{

        use                     generic-service

        host_name               web

        service_description     check-swap

                   check_command           check_nrpe!check_swap

               }

 

define service{

        use                    generic-service

        host_name              web

        service_description    check-load

       check_command           check_nrpe!check_load

               }

 

define service{

        use                    generic-service

        host_name              web

       service_description     check-disk

       check_command           check_nrpe!check_had1

              }

 

define service{

        use                    generic-service

        host_name              web

       service_description     check-users

       check_command           check_nrpe!check_users

               }

 

define service{

        use                    generic-service

        host_name              web

        service_description    otal_procs

        check_command          check_nrpe!check_total_procs

                }

 

//对以上的linux.cfg文件编辑如果有错,将会导致nagios无法启动;

 

验证Nagios 配置文件

[root@nagios ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

 

5、重启

[root@nagios ~]#service nagios restart

[root@nagios ~]#service httpd restart

 

6、测试无法访问,检查一下IPtables是否关闭。

[root@nagios ~]# service iptables status

添加nrpe 5666端口:

[root@nagios ~]# vim /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 5666 -j ACCEPT

[root@nagios ~]# service iptables restart

 

测试一下监控机使用check_nrpe与被监控机运行的nrpedaemon之间的通信.

[root@nagios ~]# /usr/local/nagios/libexec/check_nrpe -H 10.10.10.253    //被监控制端IP地址

NRPE v2.14

 

二、Linux被监控主机配置

1、增加用户

[root@web ~]# useradd nagios

[root@web ~]# passwd nagios

 

2、安装nagios插件

解压缩

[root@web ~]# tar -zxvf nagios-plugins-1.4.16.tar.gz

[root@web ~]# cd nagios-plugins-1.4.16

编译安装

[root@web nagios-plugins-1.4.16]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios

[root@web nagios-plugins-1.4.16]# make;make install

 

这一步完成后会在/usr/local/nagios/下生成两个目录libexecshare

[root@web ~]# ls /usr/local/nagios/

include  libexec  share

 

改变目录权限使nagios用户能够访问

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

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

 

3、安装nrpe服务

解压缩

[root@web ~]# tar -zxvf nrpe-2.14.tar.gz

[root@web ~]# cd nrpe-2.14

编译

[root@web nrpe-2.14]#./configure

输出如下

*** Configuration summary for nrpe 2.8.1 05-10-2007 ***:

 General Options:

 -------------------------

 NRPE port:    5666

 NRPE user:    nagios

 NRPE group:   nagios

 Nagios user:  nagios

 Nagios group: nagios

Review the options above for accuracy.  If they look okay,

type 'make all' to compile the NRPE daemon and client.

可以看到NRPE的端口是5666,下一步是make all

[root@web nrpe-2.14]# make all

输出如下

*** Compile finished ***

If the NRPE daemon and client compiled without any errors, you

can continue with the installation or upgrade process.

Read the PDF documentation (NRPE.pdf) for information on the next

steps you should take to complete the installation or upgrade.

接下来安装NPRE插件,daemon和示例配置文件

 

安装check_nrpe这个插件

[root@web nrpe-2.14]# make install-plugin

之前说过监控机需要安装check_nrpe这个插件,被监控机并不需要,我们在这里安装它是为了测试的目的

安装deamon

[root@web nrpe-2.14]# make install-daemon

安装配置文件

[root@web nrpe-2.14]# make install-daemon-config

 

现在再查看nagios目录就会发现有5个目录

[root@web nrpe-2.14]# ls /usr/local/nagios/

bin  etc  include  libexec  share

按照安装文档的说明,是将NRPE deamon作为xinetd下的一个服务运行的.在这样的情况下xinetd就必须要先安装好,不过一般系统已经默认装了

 

4、安装xinetd脚本

[root@web nrpe-2.14]# make install-xinetd

输出如下

/usr/bin/install -c -m 644 sample-config/nrpe.xinetd /etc/xinetd.d/nrpe

可以看到创建了这个文件/etc/xinetd.d/nrpe

编辑这个脚本

[root@web ~]# vim /etc/xinetd.d/nrpe

# default: on

# description: NRPE (Nagios Remote Plugin Executor)

service nrpe

{

        flags           = REUSE

        socket_type     = stream

        port            = 5666

        wait            = no

        user            = nagios

        group           = nagios

        server          = /usr/local/nagios/bin/nrpe

        server_args     = -c /usr/local/nagios/etc/nrpe.cfg --inetd

        log_on_failure  += USERID

        disable         = no

        only_from       = 127.0.0.1    //在后面增加监控主机的地址10.10.10.254,以空格间隔

}

改后

     only_from       = 127.0.0.1,10.10.10.254

          

配置nrpe信息

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

81 allowed_hosts=127.0.0.1,10.10.10.254    //允许10.10.10.254服务器端对其监控

 

5启动NRPE

[root@web ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

//检测nrep配置文件的正确性

#netstat -an | grep 5666    //是否监听5666用于nrpe通信的端口

 

6、测试无法访问,检查一下IPtables是否关闭。

[root@web ~]# service iptables status

添加nrpe 5666端口:

[root@web ~]# vim /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 5666 -j ACCEPT

[root@web ~]# service iptables restart

 

7、在服务端监控端执行检测工作站nrpe信息

[root@nagios ~]# /usr/local/nagios/libexec/check_nrpe -H 10.10.10.253

NRPE v2.14

 

8、查看nrpe进程

[root@localhost ~]# ps -elf |grep nrpe

[root@web ~]#  ps -elf |grep nrpe

5 S nagios  1480 1 0 80  0 - 9708 poll_s Mar14 ? 00:00:00 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

0 S root    1611 1437  0  80   0 - 25809 pipe_w 00:40 pts/0   00:00:00 grep nrpe

 

9、登录到WEB界面

输入用户名密码:nagiosadmin  123456

http://localhost/nagios

Services

nrpe 提示Connection refused by host

centos6.3 x64上安装nagiosnrpe服务,当nrpe顺利安装完成之后,执行/usr/local/nagios/libexec/check_nrpe -H localhost,提示Connection refused by host

解决方法:

启动NRPE

[root@web ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

然后执行,netstat -an | grep 5666

显示:tcp        0      0 127.0.0.1:5666              0.0.0.0:*                   LISTEN

则启动成功。

然后再执行:/usr/local/nagios/libexec/check_nrpe -H localhost

返回:NRPE v2.14





本文转自 yhw85 51CTO博客,原文链接:http://blog.51cto.com/yanghuawu/1156793,如需转载请自行联系原作者

相关文章
|
5天前
|
Ubuntu 安全 Linux
《Linux 简易速速上手小册》第1章: Linux 系统基础(2024 最新版)
《Linux 简易速速上手小册》第1章: Linux 系统基础(2024 最新版)
37 1
|
1天前
|
监控 安全 Linux
Linux系统之安装ServerBee服务器监控工具
【4月更文挑战第22天】Linux系统之安装ServerBee服务器监控工具
29 2
|
1天前
|
缓存 Linux
linux系统缓存机制
linux系统缓存机制
|
1天前
|
存储 Linux Android开发
RK3568 Android/Linux 系统动态更换 U-Boot/Kernel Logo
RK3568 Android/Linux 系统动态更换 U-Boot/Kernel Logo
12 0
|
1天前
|
Linux 开发工具 Android开发
Docker系列(1)安装Linux系统编译Android源码
Docker系列(1)安装Linux系统编译Android源码
3 0
|
2天前
|
资源调度 JavaScript Ubuntu
Linux系统之部署briefing视频聊天系统
【4月更文挑战第21天】Linux系统之部署briefing视频聊天系统
37 2
|
3天前
|
Linux Perl
Linux系统替换字符串常用命令
请注意,`sed`命令可以非常强大,可以根据不同的需求使用不同的选项和正则表达式来进行更复杂的字符串替换操作。
16 0
|
8天前
|
运维 网络协议 Unix
18.系统知识-Linux常用命令
18.系统知识-Linux常用命令
|
8天前
|
监控 Linux
linux监控指定进程
请注意,以上步骤提供了一种基本的方式来监控指定进程。根据你的需求,你可以选择使用不同的工具和参数来获取更详细的进程信息。
14 0
|
8天前
|
监控 Linux 网络安全
linux中启动rpc.rstat监控
请注意,rpc.rstatd服务通常用于收集远程系统的性能统计信息,例如CPU利用率、内存使用等。在使用rpc.rstatd服务之前,你应该确保了解其功能、用法和安全性,并根据需要进行适当的配置和调整。
8 0