CentOS环境Nagios的安装与配置其实挺简单,来随我看看!

在上文中讲到有关cacti的安装与配置,它在网络流量性能监控以及图表绘制等方面非常的强大。但是服务器和服务本身状态的监控以及错误报警机制,则需要本文介绍的Nagios神器来实现。Nagios的功能是监控服务和主机,根据配置在服务器异常的时候提供报警功能,并提供友好的WEB界面查看当前的网络状态、通知和故障历史、日志文件……但是他自身并不包括这部分功能的代码,所有的监控、检测功能都是有插件来完成的。

一、安装环境:CentOS5.4 + Apache2 + PHP5.2,请确保已安装PHP+Apache,可参看本博有关Apache与PHP的安装教程;

  二、创建Nagios用户及用户组,命令如下:

#useradd -m nagios

--创建nagcmd组用来运行通过web接口传输过来的命令,同时添加nagios和apache

#groupadd nagcmd  


 


#usermod -a -G nagcmd nagios  


 


#usermod -a -G nagcmd apache  


 

三、下载安装Nagios及Nagios插件,过程如下:

——下载Nagios

#wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.1.tar.gz

——下载Nagios插件

#wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.14.tar.gz

——解压Nagios

#tar -zvxf nagios-3.2.1.tar.gz

#cd nagios-3.2.1

——编译

#./configure --with-command-group=nagcmd #make all

——安装Nagios,初始化脚本及配置文件,Nagios将会被安装至/usr/local/nagios #make install #make install-init #make install-config #make install-commandmode

——安装WEB界面,界面将会安装到 /usr/local/nagios/share ( http 配置文件默认添加到 /etc/httpd/conf.d/nagios.conf,如果没有则执行:#cp sample-config/httpd.conf /etc/apache2/conf.d/nagios.conf )

#make install-webconf

——创建HTTP认证用户登录Nagios,用户名nagiosadmin,密码123456

#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

——重启apache

#service httpd restart

——安装Nagios插件

#tar -zvxf nagios-plugins-1.4.14.tar.gz

#cd nagios-plugins-1.4.14

#./configure --with-nagios-user=nagios --with-nagios-group=nagios #make && make install

——配置Nagios管理员接受告警信息的邮箱,写入管理员邮箱 #vim /usr/local/nagios/etc/objects/contacts.cfg email [email protected] ; ——校验Nagios配置文件,验证配置是否有误 #/usr/local/nagios/bin/nagios -v

——启动Nagios,配置在系统启动时运行Nagios

#chkconfig --add nagios  


 


#chkconfig nagios on  


 


#chkconfig httpd on  


 

——运行Nagios

#service nagios start

四、登陆到Web界面,输入用户名密码:nagiosadmin 123456,http://localhost/nagios/

五、错误处理

1、本机监控HTTP SSH的Notifications显示警告错误,解决方法:

#vim /usr/local/nagios/etc/objects/localhost.cfg

define service{

use local-service ; Name of service template to use

host_name localhost

service_description SSH

check_command check_ssh

notifications_enabled 1 #改为1,即可

}

# Define a service to check HTTP on the local machine.

# Disable notifications for this service by default, as not all users may have HTTP enabled.

define service{

use local-service ; Name of service template to use

host_name localhost

service_description HTTP

check_command check_http

notifications_enabled 1 #改为1,即可

}

2、Nagios显示类似错误:HTTP WARNING: HTTP/1.1 403 Forbidden - 5240 bytes in 0.002 second response time。