nagios 安装步骤
Nagios 配置教程详解安装环境:linux rehl5.1 ,软件为nagios-3.2.0,和插件nagios-plugins-1.4.13,系统需要httpd php gcc glibc ,关闭selinux。
(一).安装nagios
1. 创建 Nagios 账户和组
# useradd -m nagios
#groupadd nagcmd
# usermod -a -G nagcmd nagios
#usermod -a -G nagcmd apache
2,编译安装
# tar xvf nagios-3.2.0.tar.gz
# cd nagios-3.2.0
[…]#../configure --with-command-group=nagcmd --with-nagios-user=nagios--with-nagios-group=nagios
-
# make all
# make install
# make install-init (生成init 启动脚本)
# make install-config (生成一些模板配置文件)
# make install-commandmode (设置相应的权限)
# make install-webconf
3.为 Nagios 设置 Web 验证的密码。
# chkconfig --add nagios
# chkconfig nagios on
(二)安装Nagios的插件 nagios-plugin
# tar xvf nagios-plugins-1.4.13.tar.gz
# cd nagios-plugins-1.4.13
# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios
--with-nagios-group=nagios
# make && make install
(三)配置nagios,
这时,你的/usr/local/nagios/下应该有下面几个文件
drwxrwxr-x2 nagios nagios 4096 02-14 15:35 bin
drwxrwxr-x3 nagios nagios 4096 02-14 15:35 etc
drwxrwxr-x2 nagios nagios 4096 02-14 15:35 libexec
drwxrwxr-x2 nagios nagios 4096 02-13 00:52 sbin
drwxrwxr-x 10 nagios nagios 4096 02-14 14:15 share
drwxrwxr-x5 nagios nagios 4096 02-14 16:36 var
1. 主配置文件nagios.cfg的配置。
cfg_file=/usr/local/nagios/etc/objects/commands.cfg (命令定义文件)
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg(联系人信息定义文件)
cfg_file=/usr/local/nagios/etc/objects/contactgroups.cfg (添加此行联系人组定义文件)
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg(添加此行主机定义文件)
cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg (添加此行主机组定义文件)
cfg_file=/usr/local/nagios/etc/objects/services.cfg(添加此行服务定义文件)
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg (时间周期定义文件)
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
# Definitions for monitoring the local (Linux) host
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg(确定这行没有注释)
因为localhost.cfg文件里面有一些配置文件,我当时做完后,一直出错,然后移除了此文件,然后建立一个空的localhost.cfg文件,位置和nagios配置文件相符
然后修改权限为-rwxrwxrwx 1 nagios nagios 1 2011-02-14 localhost.cfg
如果没有cfg文件,请自己新建。
2. 文件的配置
我建立了三个主机,分别为lt-21188、lt-21187、nagios,节省空间,只贴出一个,其他复制修改一下即可。
主机定义文件的配置
# vi objects/hosts.cfg
define host{
host_name lt-21188
alias lt-21188
address 192.168.21.188
check_command check-host-alive
check_interval 5
retry_interval 1
max_check_attempts 5
check_period 24x7
process_perf_data 0
retain_nonstatus_information 0
contact_groups sagroup
notification_interval 30
notification_period 24x7
notification_options d,u,r
}
主机组的配置viobjects/hostgroups.cfg
define hostgroup {
hostgroup_nameEnterprise manger
alias Enterprise manger
members lt-21188,lt-21187
}
联系人的配置
vi objects/contacts.cfg
define contact{
contact_name nagiosadmin
use generic-contact
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 15010306527@139.com }
联系人组的配置
vi objects/contactgroups.cfg
define contactgroup {
contactgroup_name sagroup
alias system administrator group
members nagiosadmin
}
服务器的配置
vi objects/services.cfg
define service {
host_name lt-21188
service_description check-host-alive
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups sagroup
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check-host-alive}
ok,主要的几个cfg文件已经配置完毕。
(四)检查下配置文件夹并启动
使用 /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg这个命令,如果出现
Total Warnings: 0
Total Errors: 0
说明一切ok。
启动 httpd 和nagios 两个服务,登陆http://localhost/nagios,应该就没问题了。
(五)出现的问题,
错误 1 :
细节决定结果,完成后,web页面所以主机处于DOWN状态,但是可以ping通,看log发现错误:
Warning: Return code of 127 for check of host 'lt-21188' was out of bounds. Make sure the plugin you're trying to run actually exists
后来查看/usr/local/nagios/下面所以文件的权限,然后还是出这个错,发现/usr/local/nagios/libexec文件夹下面插件少了很多,觉得是nagios-plugins安装问题,重新编译安装一次,问题解决。
错误 2 :
在使用“../libexec/check_nrpe -H 192.168.1.12 -c check_disk”检查check_disk的时候出错:
NRPE: Command ‘check_disk’ not defined,经检查,发现 /usr/local/nagios/etc/nrpe.cfg配置信息由问题,正确的命令为:
command=/usr/local/nagios/libexec/check_disk-w 200% -c 10% -p /dev/hda1
以上部分参考与--赵舜东和官方http://nagios-cn.sourceforge.net/nagios-cn/ 的步骤。
页:
[1]