1、host -n -u -p -t -c 使用方式:check_nrpe -H 主机名 -p NRPE端口 -c NRPE命令名 Options:选项: = The address of the host running the NRPE daemon 主机,运行着NRPE守护进程的远程被监测主机名,并且该主机名必须在host里定义过。 port = The port on which the daemon is running (default=5666) 端口,被监测的远程主机上运行NRPE的端口,默认是5666,如果是默认就不用指定。 command = The name of the c
2、ommand that the remote daemon should run 命令,这些命令名必须是被监测主机上NRPE守护进程运行着的。查看监控服务器是否能和远程Linux 192.168.1.3正常通信。能正常通信返回 NRPE的版本号rootKCentOS5C #/usr/local/nagios/libexec/check_nrpe H 192.168.1.32.在command.cfg命令定义文件中添加NRPE命令。rootKCentOS5C # vi /usr/local/nagios/etc/objects/commands.cfg添加如下NRPE功能命令# NRPE Com
3、manddefine command command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ 这里要说明几点:(1)这里定义的命令名就叫作nrpe。(2)$USER1$/check_nrpe会通过引用resource.cfg获得/usr/local/nagios/libexec/check_nrpe这个绝对路径。(3)-H $HOSTADDRESS$ 用来获得指定被监测主机的IP地址,$HOSTADDRESS$变量会通过定义主机名查找到host段中的IP地址。(4)-c $ARG1$
4、用来指定被监测主机上NRPE守护进程运行着的NRPE命令名。3.在Nagios监控服务器上然后按照NRPE命令定义来添加NRPE远程监控服务:#vi /usr/local/nagios/etc/objects/localhost.cfg在localhost.cfg 添加 define host define servicedefine hostuse linux-serverhost_name mylinuxalias mylinux address 192.168.1.3 ;远程Linux服务器的地址define service use generic-service host_name m
5、ylinux service_description check-swap /对下面操作的描述 check_command check_nrpe!check_swap /执行检测交换分区命令,监控swap service_description check-loadcheck_load /监控负载 service_description check-diskcheck_disk /监控硬盘 service_description check-userscheck_users /监控用户(使用)情况 service_description total_procscheck_total_procs
6、 /监控进程运行如下命令。如果没有错误就可以重启Nagios 服务# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg重启 Nagios Service 使配置生效# service nagios reload监控主机和被监控主机如果启动Iptables防火墙的话,测试的时候可以停止iptables服务 Service iptables stop 正真的使用中,需要开启Iptables,同时配置防火墙是Iptables 的5666端口开放。防火墙配置方法:/sbin/iptables -A FORWARD -i e
7、th0 -p tcp -dport 5666 -j ACCEPT (三)在被监控主机上安装Nagios-plugins插件程序:(下载地址1.添加Nagios用户# useradd nagios安装软件包:yum -y install gcc openssl-devel openssl2.下载插件#mkdir /downloads3.准备好Nagios-plugins和NRPE源代码包# lltotal 2008-rw- 1 root root 928 Oct 3 10:33 anaconda-ks.cfg-rw-r-r- 1 root root 22760 Oct 3 10:33 insta
8、ll.log-rw-r-r- 1 root root 2888 Oct 3 10:33 install.log.syslog-rw-r-r- 1 root root 1693979 Sep 30 22:51 nagios-plugins-1.4.15.tar.gzNagios-plugins插件程序包-rw-r-r- 1 root root 305019 Sep 30 22:58 nrpe-2.13.tar.gzNRPE扩展插件功能包4.解压Nagios-plugins压缩包# tar -zxvf nagios-plugins-1.4.15.tar.gz5.进入Nagios-plugins插件
9、包目录# cd nagios-plugins-1.4.156.预配置Nagios-plugins的安装路径# ./configure -prefix=/usr/local/nagios如提示出错请安装以下软件包:yum install gccyum install glibc glibc-commonyum install gd gd-develyum -y install openssl openssl-devel预配置完成后会反馈信息并生成Makefileconfig.status: creating po/Makefile -with-apt-get-command: -with-pin
10、g6-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: no -with-openssl: -with-gnutls: -with-perl: /usr/bin/perl -enable-perl-modules: -with-cgiurl: /nagios/cgi-bin -with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin7.编译Nagios-plugin
11、s插件程序# make8.安装Nagios-plugins插件程序# make install9.查看Nagios-plugins插件程序的安装# ll /usr/local/nagios/total 8drwxr-xr-x 2 root root 4096 Oct 7 01:02 libexecdrwxr-xr-x 3 root root 4096 Oct 7 01:02 share10.递归更改Nagios主路径的属主# chown nagios.nagios /usr/local/nagios/# chown -R nagios.nagios /usr/local/nagios/libe
12、xec11.检查Nagios主路径的属性# ll /usr/local/ | grep nagiosdrwxr-xr-x 4 nagios nagios 4096 Oct 7 01:02 nagiosrootKCentOS5A # ll /usr/local/nagios/drwxr-xr-x 2 nagios nagios 4096 Oct 7 01:drwxr-xr-x 3 nagios nagios 4096 Oct 7 01:(四)再在被监控主机上安装NRPE扩展插件程序:(下载地址:1.下载插件原因缺少openssl-devel包,解决办法安装:yum install xinetd
13、2.解压NRPE的压缩包# tar -zxvf nrpe-2.13.tar.gz# cd nrpe-2.13 3.预配置NRPE安装程序# ./configure (-enable-ssl -with-ssl-lib=/lib/) 预配置完毕后会反馈提示信息以及建立Makefileconfigure: creating ./config.status creating Makefile creating src/Makefile creating subst creating include/config.h* Configuration summary for nrpe 2.9 08-13-
14、2007 *: General Options: - NRPE port: 5666 NRPE user: nagios NRPE group: Nagios user: Nagios group:Review the options above for accuracy. If they look okay,type make all to compile the NRPE daemon and client.最后提示继续使用“make all”命令来对NRPE守护程序以及客户端程序进行编译。4.对NRPE程序进行编译# make all编译成功后会反馈提示信息* Compile finis
15、hed *If the NRPE daemon and client compiled without any errors, youcan continue with the installation or upgrade process.Read the PDF documentation (NRPE.pdf) for information on the nextsteps you should take to complete the installation or upgrade.在NRPE的包目录中有一份NRPE.pdf的手册,接下来就可以参考那份手册进行后续的操作了。安装NRPE
16、插件程序,守护程序以及模板守护程序配置文件。Install the NRPE plugin (for testing), daemon, and sample daemon config file.5.安装NRPE插件程序# make install-plugin6.安装NRPE守护程序# make install-daemon7.安装NRPE守护程序配置文件# make install-daemon-config8.检查NRPE程序的安装total 16drwxrwxr-x 2 nagios nagios 4096 Oct 7 01:16 bin16 etc15 libexec9. 安装Xi
17、netd 相关配置文件# make install-xinetd10.相关文件的修改#vim /usr/local/nagios/etc/nrpe.cfg allowed_host=192.168.1.2 127.0.0.1 /允许192.168.1.2对其监控(不同地址间加空格)# vi /etc/services 文件作如下修改:nrpe 5666/tcp # NRPE# service xinetd restart替代:(如发现异常,或者更改了配置,用此方法重启下nrpe进程,也许可解决)# ps aux | grep nrpe# kill nagios的进程号#/usr/local/n
18、agios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d#tail /var/log/messages(查看nrpe日志,是否成功)#killall -9 nrpe(五)在被监测主机上配置并运行NRPE1.配置NRPE的主配置文件usr/local/nagios/etc/nrpe.cfg 配置文件默认就可以了。2.找到NRPE运行的执行程序# ll /usr/local/nagios/bin/nrpe-rwxrwxr-x 1 nagios nagios 93420 Oct 7 01:16 /usr/local/nagios/bin/nrpe3.了解
19、NRPE的执行程序的使用方式# /usr/local/nagios/bin/nrpe -h nrpe -n -c mode运行方法:nrpe -c NRPE配置文件路径 运行模式可用选项 -n = Do not use SSL 不使用SSL方式,一般都使用SSL。 = Name of config file to use 指定NRPE配置文件路径,这个NRPE主配置文件就是nrpe.cfg。 = One of the following two operating modes: 指定NRPE的运行方式,一共有2种可用的NRPE运行方式: -i = Run as a service under
20、inetd or xinetd 以超级守护进程inetd或xinetd方式运行NRPE,要通过这种方式运行的话还要安装和配置xinetd,一般不用。 -d = Run as a standalone daemon 以独立守护进程方式运行NRPE,一般常用这种运行方式。4.运行NRPE守护进程# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d测试NEPE本地是否正常启动#/usr/local/nagios/libexec/check_nrpe H localhost如果正确的话,回返回NRPE的版本号Error could not complete ssl hanshake如果配置没有问题的话,输入如下命令。查看配置是否配好# netstat -at | grep nrpetcp 0 0 *:nrpe *:* LISTEN5.查看系统日志检查NRPE运行情况:# tail /var/log/messagesOct 7 01:45:10 KCentOS5A nrpe21659: Starting up daemon说明已经顺利启动了NRPE守护进程。 Listening for connections on port 5666说明已经启动了5666端口为NRPE的监听端口。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1