安装条件:
#yum -y install httpd php php-mysql mysql mysql-devel mysql-server gcc glibc glibc-common gd gd-devel
添加nagios运行所而要的用户和组:
#groupadd nagcmd
#useradd -G nagcmd nagios
#passwd nagios
把apache加入到nagcmd组,以便于在通过web interface操作nagios时能够具有足够的权限
#usermod -a -G nagcmd apache
安装nagios
#tar zxf nagios-3.*.*.tar.gz
#cd nagios-3.*.*
#./configure -sysconfdir=/etc/nagios --with-command-group=nagcmd --enable-event-broker
#make all
#make install 此命令运行后会提示运行以下几个命令
#make install-init
#make install-commandmode
#make install-config
#make install-webconf
创建一个nagios web程序的用户,这个用户贴在以后通过web登陆nagios认证时所用
#htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
#service httpd start
#chkconfig --add nagios
#chkconfig nagios on
安装插件
#tar xf nagios-plugins-1.*.*.tar.gz
#cd nagios-plugins-1.*.*
#./configure --with-nagios-user=nagios --with-nagios-group=nagios
#make
#make install
#server nagios restart
配置selinux
如果系统开户了selinux服务,则默认为拒绝nagios web cgi程序的运行。可以通过下面的命令来检查系统是否开启selinux:
#getenforce
如果上面的命令的结果显示开启了selinux服务,可以通过下面的命令暂时性的将其关闭:
#setenforce 0
如果想在以后完全关闭selinux,可能编辑/etc/sysconfig/selinux,将其中的selinux后面的值“force”修改为“disable”vc sk
当然,也可以通过以下方式将nagios的cgi程序运行于selinux/targeted模式,而不用关闭selinux
#chcon -R -t httpd_sys_content_t /etc/nagios/sbin
#chcon -R -t httpd_sys_content_t /etc/nagios/share
基于nrpe监控。。。被监控端的安装:
若系统没有安装开发包组,请先安装
#yum -y groupinstall "Development Tools" "Development Libraries"
#useradd -s /sbin/nologin nagios
先安装nagios-plugins
#cd nagios-plugins1.*.*
#./configure --with-nagios-user=nagios --with-nagios-group=nagios
#make all
#make install
再安装NRPE
#cd nrpe-2.*.*
#./configure --sysconfdir=/etc/nrpe --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl ;打开enable-ssl功能,系统得先安装openssl-devel
#make all
#make install-plugin
#make install-daemon
#make install-daemon-config
启动nrpe命令为:
/usr/local/nagios/bin/nrpe -c /etc/nrpe/nrpe.cfg -d
这样服务器在运行时都要运行此命令nrpe才能运行,所以可能把nrpe做成服务让其自动运行,脚本 如下:
#vi /etc/init.d/nrped
#!/bin/bash
# chkconfig: 2345 88 12
# description: NRPE DAEMON
NRPE=/usr/local/nagios/bin/nrpe
NRPECONF=/etc/nrpe/nrpe.cfg
case "$1" in
start)
echo -n "Starting NRPE daemon......"
$NRPE -c $NRPECONF -d
echo "done...."
;;
stop)
echo -n "Stopping NRPE daemon....."
pkill -u nagios nrpe
echo "done..."
;;
restart)
$0 stop
sleep 2
$0 start
;;
*)
echo "Usage: $0 start|stop|restart"
;;
esac
exit 0
#chkconfig --add nrped
基于nrpe,监控端的配置:
#cd nrpe-2.*
#./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
安装好后在/usr/local/nagios/libexec目录下生成check_nrpe脚本文件,可以用"./check_nrpe -H 192.168.133.140"来检测,这里的ip是被监控端的ip地址。
注:对于nrpe监控方式来说,nrpe的服务端是在被监控端的,而nagios服务器成了nrpe的客户端,因为在被监控端上启动nrped服务后,监控5666端口,nagios服务连接被监控端的5666端口来实现数据的传递,所以在被监控端的防火墙上应开放5666端口
在nagios上nrpe安装好后,接下来就是一系列的配置:
定义命令:
#cd /etc/nagios/objects
#vi commands.cfg 在最后增加如下
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
定义主机:
#cd /etc/nagios/objects
#cp windows.cfg linhost.cfg 这里把localhost.cfg文件当作一个模板复制为linuhost.cfg,这个linhost.cfg文件就是用来定义我们要监控的主机对象
#vi linhost.cfg
把这个文件里的define host里的use调用的模板更改为linux-server,hostname更改为统一的名字,address 定义为要监控的主机地址。把define hostgroup内容注释掉,接下来定义服务,define service 里的内容最重要的是修改check_command,这里我们调用的命令是check_nrpe,所以格式为“check_command check_nrpe!check_users”这里的check_users是与被监控端的nrpe的配置文件/etc/nrpe/nrpe.cfg的“command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10”中括号定义的,在被监控端写了几行命令,在linhost.cfg的定义服务里就应该定义几个,“check_command check_nrpe!check_users”这里的“!”号,表示叹号的内容是被/etc/nagios/objects里的commands.cfg里定义的“$ARG1$”调用的。
linhost.cfg编辑好后,就得启用此文件,所以vi /etc/nagios/nagios.cfg,在相应位置增添“cfg_file=/etc/nagios/objects/linhost.cfg”,再验证配置文件的正确性,用下面的命令
#/usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg
再重新启动服务
#service nagios restart