Nagios 编译安装配置
安装配置Nagios监控端1、安装前的准备工作(1)解决安装Nagios的依赖关系:Nagios基本组件的运行依赖于httpd、gcc和gd。可以通过以下命令来检查nagios所依赖的rpm包是否已经完全安装:# yum -y install httpd gcc glibc glibc-common gd gd-devel php php-mysql mysql mysql-devel mysql-server(2)添加nagios运行所需要的用户和组:# groupaddnagcmd# useradd -G nagcmd nagios# passwd nagios把apache加入到nagcmd组,以便于在通过web Interface操作nagios时能够具有足够的权限:# usermod -a -G nagcmd apache2、编译安装nagios:# tar zxf nagios-3.3.1.tar.gz# cd nagios-3.3.1# ./configure –with-command-group=nagcmd –enable-event-broker# make all# make install# make install-init# make install-commandmode# make install-config在httpd的配置文件目录(conf.d)中创建Nagios的Web程序配置文件:# make install-webconf创建一个登录nagios web程序的用户,这个用户帐号在以后通过web登录nagios认证时所用:# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin以上过程配置结束以后需要重新启动httpd:# service httpd restart3、编译、安装nagios-pluginsnagios的所有监控工作都是通过插件完成的,因此,在启动nagios之前还需要为其安装官方提供的插件。# tar zxf nagios-plugins-1.4.15.tar.gz# cd nagios-plugins-1.4.15# ./configure –with-nagios-user=nagios –with-nagios-group=nagios# make# make install4、配置并启动Nagios(1)把nagios添加为系统服务并将之加入到自动启动服务队列:# chkconfig –add nagios# chkconfig nagios on(2)检查其主配置文件的语法是否正确:# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg(3)如果上面的语法检查没有问题,接下来就可以正式启动nagios服务了:# service nagios start(4)通过web界面查看nagios:http://your_nagios_IP/nagios被监控端(基于NRPE监控远程Linux主机)1、安装配置被监控端1)先添加nagios用户# useradd -s /sbin/nologin nagios2)NRPE依赖于nagios-plugins,因此,需要先安装之# tar zxf nagios-plugins-1.4.15.tar.gz# cd nagios-plugins-1.4.15# ./configure –with-nagios-user=nagios –with-nagios-group=nagios# make all# make instal3)安装NRPE# tar -zxvf nrpe-2.12.tar.gz# cd nrpe-2.12.tar.gz# ./configure –with-nrpe-user=nagios \–with-nrpe-group=nagios \–with-nagios-user=nagios \–with-nagios-group=nagios \–enable-command-args \–enable-ssl# make all# make install-plugin# make install-daemon# make install-daemon-config4)配置NRPE# vim /usr/local/nagios/etc/nrpe.conflog_facility=daemonpid_file=/var/run/nrpe.pidserver_address=192.168.210.12server_port=5666nrpe_user=nagiosnrpe_group=nagiosallowed_hosts=192.168.210.11command_timeout=60connection_timeout=300debug=05)启动NRPE# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d为了便于NRPE服务的启动,可以将如下内容定义为/etc/init.d/nrped脚本:#!/bin/bash# chkconfig: 2345 88 12# description: NRPE DAEMONNRPE=/usr/local/nagios/bin/nrpeNRPECONF=/usr/local/nagios/etc/nrpe.cfgcase “$1″ instart)echo -n “Starting NRPE daemon…”$NRPE -c $NRPECONF -decho ” done.”;;stop)echo -n “Stopping NRPE daemon…”pkill -u nagios nrpeecho ” done.”;;restart)$0 stopsleep 2$0 start;;*)echo “Usage: $0 start|stop|restart”;;esacexit 0
6)配置允许远程主机监控的对象在被监控端,可以通过NRPE监控的服务或资源需要通过nrpe.conf文件使用命令进行定义:command=/usr/local/nagios/libexec/check_users -w 5 -c 10command=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20command=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1command=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda3command=/usr/local/nagios/libexec/check_disk -w 40% -c 20% -p /dev/shmcommand=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Zcommand=/usr/local/nagios/libexec/check_procs -w 150 -c 200command=/usr/local/nagios/libexec/check_diskdisk.sh配置监控端1)安装NRPE# tar -zxvf nrpe-2.12.tar.gz# cd nrpe-2.12.tar.gz# ./configure –with-nrpe-user=nagios \–with-nrpe-group=nagios \–with-nagios-user=nagios \–with-nagios-group=nagios \–enable-command-args \–enable-ssl# make all# make install-plugin2)定义如何监控远程主机及服务:nagios.cfg主配置文件加一行:cfg_file=/usr/local/nagios/etc/objects/192.168.210.12.cfg192.168.210.12.cfg内容如下:define host{use linux-serverhost_name 192.168.210.12alias 0.12address 192.168.210.12}
define service{use generic-servicehost_name 192.168.210.12service_description check_pingcheck_command check_ping!100.0,20%!200.0,50%max_check_attempts 5normal_check_interval 1}
define service{use generic-servicehost_name 192.168.210.12service_description check_sshcheck_command check_sshmax_check_attempts 5normal_check_interval 1notification_interval 60}
define service{use generic-servicehost_name 192.168.210.12service_description check_httpcheck_command check_httpmax_check_attempts 5normal_check_interval 1contact_groups commonnotifications_enabled1notification_period 24×7notification_options w,u,c,r}define service{use generic-servicehost_name 192.168.210.12service_description check_loadcheck_command check_nrpe!check_loadmax_check_attempts 5normal_check_interval 1}define service{use generic-servicehost_name 192.168.210.12service_description check_disk_sda1check_command check_nrpe!check_sda1max_check_attempts 5normal_check_interval 1}
页:
[1]