Nagios 配置教程详解
安装环境: linux rehl5.1 ,软件为 nagios-3.2.0 ,和插件 nagios-plugins-1.4.13 ,系统需要 httpd php gcc glibc ,关闭 selinux 。
( 一 ). 安装 nagios
1. 创建 Nagios 账户和组
[root@UnixHot src]# useradd -m nagios
[root@UnixHot src]#groupadd nagcmd
[root@UnixHot src]# usermod -a -G nagcmd nagios
[root@UnixHot src]#usermod -a -G nagcmd apache
2,编译安装
[root@UnixHot src]# tar xvf nagios-3.2.0.tar.gz
[root@UnixHot src]# cd nagios-3.2.0
[…]#../configure --with-command-group=nagcmd --with-nagios-user=nagios --with-nagios-group=nagios
-
[root@UnixHot nagios-3.2.0]# make all
[root@UnixHot nagios-3.2.0]# make install
[root@UnixHot nagios-3.2.0]# make install-init (生成 init 启动脚本)
[root@UnixHot nagios-3.2.0]# make install-config (生成一些模板配置文件)
[root@UnixHot nagios-3.2.0]# make install-commandmode (设置相应的权限)
[root@UnixHot nagios-3.2.0]# make install-webconf
3.为 Nagios 设置 Web 验证的密码。
[root@UnixHot ~]# chkconfig --add nagios
[root@UnixHot ~]# chkconfig nagios on
(二)安装 Nagios 的插件 nagios-plugin
[root@UnixHot src]# tar xvf nagios-plugins-1.4.13.tar.gz
[root@UnixHot src]# cd nagios-plugins-1.4.13
[root@UnixHot nagios-plugins-1.4.13]# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios
--with-nagios-group=nagios
[root@UnixHot nagios-plugins-1.4.13]# make && make install
(三)配置 nagios,
这时,你的 /usr/local/nagios/下应该有下面几个文件
drwxrwxr-x 2 nagios nagios 4096 02-14 15:35 bin
drwxrwxr-x 3 nagios nagios 4096 02-14 15:35 etc
drwxrwxr-x 2 nagios nagios 4096 02-14 15:35 libexec
drwxrwxr-x 2 nagios nagios 4096 02-13 00:52 sbin
drwxrwxr-x 10 nagios nagios 4096 02-14 14:15 share
drwxrwxr-x 5 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,节省空间,只贴出一个,其他复制修改一下即可。
主机定义文件的配置
[root@UnixHot etc]# 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
}
主机组的配置 vi objects/hostgroups.cfg
define hostgroup {
hostgroup_name Enterprise 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[check_disk]=/usr/local/nagios/libexec/check_disk -w 200% -c 10% -p /dev/hda1
以上部分参考与--赵舜东和官方http://nagios-cn.sourceforge.net/nagios-cn/ 的步骤。
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com