Billow 2011-06-04
一.建组建帐号
groupadd nagcmd
useradd apache
useradd nagios
usermod -G nagcmd nagios
usermod -G nagcmd apache
二、安装 nagios
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-commandmode
make install-config
三.配置WEB接口
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin 创建一个登录WEB的帐号
四.装nagios-plugin-1.4.13
cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
五.将nagios加入服务并启动,同时启动apache
chkconfig --add nagios
chkconfig nagios on
验证nagios的安装
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果出现下面的提示就OK了
......
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
启动nagios和apache服务
service nagios start
service httpd start
六.禁用selinux
我登录WEB页面好几次都无法通过验证,仔细看了一下说明发现是selinux的问题
setenforce 0
这么改完不需要重启系统就可生效,Getenforce可看到permissive。但一重启就又得来一次,我的CentOS上也没别的,直接disable吧
vi /etc/selinux/config
SELINUX=disabled
现在可以用http://IP/nagios来登录了,用户名nagiosadmin
七.定义联系人和联系人组
vi /usr/local/nagios/etc/objects/contacts.cfg
配置 commands.cfg
vi /usr/local/nagios/etc/objects/commands.cfg
在最后一行添加
#check nrpe
define command {
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
添加监控主机
vi /usr/local/nagios/etc/nagios.cfg
在 cfg_file=/usr/local/nagios/etc/objects/localhost.cfg 行后 增加
# Definitions for monitoring a linux machine
cfg_file=/usr/local/nagios/etc/objects/linux.cfg
新建 linux.cfg 文件,并增加内容
vi /usr/local/nagios/etc/objects/linux.cfg
加入下面内容
define host{
use linux-server
host_name nagiosTest
alias nagiosTest
address 192.168.8.209
}
define service{
use generic-service
host_name nagiosTest
service_description check-swap
check_command check_nrpe!check_swap
}
define service{
use generic-service
host_name nagiosTest
service_description check-load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name nagiosTest
service_description check-disk
check_command check_nrpe!check_disk
}
define service{
use generic-service
host_name nagiosTest
service_description zombie_procs
check_command check_nrpe!check_zombie_procs
}
define service{
use generic-service
host_name nagiosTest
service_description check-users
check_command check_nrpe!check_users
}
define service{
use generic-service
host_name nagiosTest
service_description total_procs
check_command check_nrpe!check_total_procs
}
重启nagios
service nagios restart