NRPE监控远程主机——nagios扩展 NRPE简介: NRPE是监控软件nagios的一个扩展,它被用于被监控的服务器上,向nagios监控平台提供该服务器的一些本地的情况。例如,cpu负载、内存使用、硬盘使用等等。NRPE可以称为nagios的for linux 客户端。
NRPE的基本机构: nagios监控主机设置: 1.编译安装nrpe软件包:
执行/usr/local/nagios/libexec/check_nrpe -H 192.168.10.2检查连接是否正常:
在/usr/local/nagios/etc/objects/commands.cfg 模版中添加如下内容: define command { command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ }
这是定义实际运行的插件程序.这个命令行的书写要完全按照check_nrpe这个命令的用法.不知道用法的就用check_nrpe –h查看; -c后面带的$ARG1$参数是传给nrpe daemon执行的检测命令,之前说过了它必须是nrpe.cfg中所定义的5条命令中的其中一条。 eg:要监控mysql主机192.168.10.2的SWAP分区,需要在mysql主机的nrpe.cfg添加如下内容:
重启xinetd服务:
在监控主机上执行:
如果这里没有定义好,在服务器端监测时会报错误:NRPE command ‘check_swap’ not defined。 在nagios监控主机的/usr/local/nagios/etc/objects/services.cfg文件中添加对应的所要监控的资源:
define service { use generic-service host_name mysqlhost service_description Swap check_command check_nrpe!check_swap }
等被监控端nrpe安装完成后使用此命令检查配置文件是否有错:
远程被控机主机设置: 这里以http://wenzhongxiang.blog./6370734/1259339实验前提为基础进行操作: 在被监控端安装nagios-plugins和nrpe插件: 1.创建nagios用户:
2.编译安装nagios-plugins插件上: [iyunv@mysql ~]#cd nagios-plugins-1.4.15
3.安装xinetd软件包:
4.编译安装nrpe软件包:
执行过程需要按照先后顺序:
注解信息: make install-daemon ——安装守护进程 make install-daemon-config ——安装配置文件 make install-xinetd ——安装xinetd脚本
5.配置nrpe,添加nrpe 服务: 在/etc/xinetd.d/nrpe配置文件的 only_from = 127.0.0.1 后添加nagios监控主机的地址192.168.10.1,中间以空格分隔: 修改内容如下:
修改后的配置文件总览:
6.编辑/etc/services文件,增加NRPE服务模块: vi /etc/services nrpe 5666/tcp #nrpe Service jiankong(nrpe的监控端口)
7.在配置文件/usr/local/nagios/etc/nrpe.cfg 的第214行取消其注解的“#”号: command[check_disk]=/usr/local/nagios/libexec/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
8.重启xinetd服务,查看NRPE是否已经启动(显示5666端口已在监听表示服务正常,并确保防火墙允许此端口进入):
/usr/local/nagios/libexec/check_nrpe –h的使用方法 NRPE daemon只运行nrpe.cfg中所定义的命令!
9.重新加载nagios.cfg配置文件: 通过浏览器访问nagios的web页面,查看新添加的swap资源的监控情况:
注解信息: 在services.cfg中使用check_nrpe的时候要带上“!”参数: 在/usr/local/nagios/etc/objects/services.cfg 添加如下内容:
define service { use local-service host_name mysqlhost service_groups mysqlgroup service_description SWAP check_command check_nrpe!check_swap contact_groups admins notification_interval 10 notification_period 24x7 notification_options w,u,r,c } define service { use local-service host_name mysqlhost service_groups mysqlgroup service_description CPUload check_command check_nrpe!check_load contact_groups admins notification_interval 10 notification_period 24x7 notification_options w,u,r,c } define service { use local-service host_name mysqlhost service_groups mysqlgroup service_description Free Space check_command check_nrpe!check_disk contact_groups admins notification_interval 10 notification_period 24x7 notification_options w,u,r,c } define service { use local-service host_name mysqlhost service_groups mysqlgroup service_description TotalProcesses check_command check_nrpe!check_total_procs contact_groups admins notification_interval 10 notification_period 24x7 notification_options w,u,r,c }
define service { use local-service ——使用的模板 host_name mysqlhost ——被监控主机名,该主机名必须是linux且运行着nrpe,而且必须是hosts.cfg中定义的 service_groups mysqlgroup service_description ZombieProcesses ——监控项目的描述 check_command check_nrpe!check_zombie_procs ——监控命令是check_nrpe,在commands.cfg中定义,check_disk参数是nrpe.cfg中定义的 contact_groups admins notification_interval 10 ——通知间隔 notification_period 24x7 ——通知周期设置 notification_options w,u,r,c ——定义状态报警设置 }
通过访问http://192.168.10.1/nagios来查看监控信息,显示信息如下:
nagios通过邮件发送报警信息: nagios除了丰富的监控功能外,报警功能相当的强大(常见的报警方法有:邮件和短信): 邮件报警的配置在/usr/local/nagios/etc/object/contact.cfg的配置文件中的email后添加管理员的邮箱: 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 root@localhost.localdomain #报警邮箱,以root为例。 }
截图如下:
注解:
在commands.cfg文件中要定义发邮件的命令默认就存在。 在hosts.cfg和services.cfg文件添加有关发通知的联系人信息和间隔等。 nagios利用本地的sendmail或postfix邮件服务器发送邮件,只要启动本地服务器的sendmail或postfix就可以了。
整个nagios部署到此告一段落,不足之处,请谅解。
|