我的Nagios的艰辛.....网络监控之神(一)
本贴原创,转载请注明出处
神仙的blog
www.6xuan.com
或者
extmail 站
或者
哎哟妈妈 ,
哎哟妈妈游戏频道
网上的
资料 太多太多了!看的我头晕眼花!nagios真的很强大,对于监控的windows/linux/switch/printer都能很好的表示,并且可以对其中的服务进行监控。nagios最强大的就是报警功能,e
mail /msn/飞信/网络电话。开源就是好啊!!就好像我配置mail
邮件
系统 一般!!
过程是艰辛的, 结果是美好的!
我就他妈半个技术的命,!人家都下班了,一个人在公司搞到11点多!!!
现在才慢慢上手!!边做边临时小记!!
2008-7-17
终于废墟中拔出一条缝!临时小记!
第一。先看基本的nagios安装!
下载 nagios-3.0.3.tar.gz -----------------------主程序
nagios-plugins-1.4.12.tar.gz------------------插件
nagios-nrpe_2.8.1.orig.tar.gz -------------监控
Linux 需要
nsclient++0.3.3 ------------------监控windows需要
官方文档
http://nagios-cn.sourcefor ge.net ... ml#monitoring-linux
英文的!
开始安装
1。
yum install gcc
yum install glibc glibc-commonyum install gd gd-devel
2。自己编译安装apache2.0。安装哪里随便,(我这里是自己编译的httpd,么有用系统自带的)
3。安装nagios-3.0.3.tar.gz
=======================
/usr/sbin/useradd nagios
passwd nagios 输入密码
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -G nagcmd nagios
/usr/sbin/usermod -G nagcmd apache
=====================
tar xzf nagios-3.0.3.tar.gz
=======================
cd nagios-3.0.3
=======================
./configure --with-command-group=nagcmd (不用跟参数,默认安装在/usr/local/nagios)
================
make all
==================
make install
================
make install-init
=======================
make install-config
=====================
make install-commandmode
===============================
vi /usr/local/nagios/etc/objects/contacts.cfg
更改email地址nagiosadmin的联系人定义信息中的EMail信息为你的EMail信息以接收报警内容。
=================================
make install-webconf
=====================
/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
输入密码(这一步很重要)
========================================================
2。译并安装Nagios插件
nagios-plugins-1.4.12.tar.gz
tar xzf nagios-plugins-1.4.12.tar.gz
cd nagios-plugins-1.4.12
============================
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
============================
chkconfig --add nagios
chkconfig nagios on
=====================
验证Nagios的样例配置文件
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
================================
如果没有报错,可以启动Nagios服务
service nagios start
=========================================
3。编辑apache 的httpd.conf最后面添加:
ScriptAlias /nagios/
cgi -bin "/usr/local/nagios/sbin"
<Directory "/usr/local/nagios/sbin">
# SSLRequireSSL
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
=========================================
4。在验证下/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
没有出错的话!
重新启动nagios和apache
========================
5。关于selinux,如果selinux是关闭状态,可以忽略这部!如果selinux开启!
那么如果是SELinux处于强制安全模式时需要做getenforce令SELinux处于容许模式setenforce 0如果要永久性更变它,
需要更改/etc/selinux/config里的设置并重启系统。
不关闭SELinux或是永久性变更它的方法是让CGI模块在SELinux下指定强制目标模式:
chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
chcon -R -t httpd_sys_content_t /usr/local/nagios/share/
6。登陆web接口!
http://localhost/nagios输入你刚才设置的用户名密码!ok了!看到界面了吧
ps: 如果遇到问题!!!!如果遇到关于cgi什么权限问题!察看下/usr/local/nagios的属主组权限,包括里面的内容,尤其是/usr /local/nagios/etc/htpasswd.users这个文件的权限!都应该是nagios:nagios另外尝试编辑vi /usr/local/nagios/etc/cgi.cfg把use_authentication=1修改为 use_authentication=0如果出现页面无法显示之类的,去访问bbs.itnms.net里面的
http://www.itnms.net/discuz/forumdisplay.php?fid=10&pageD4 有关于基本的错误的解决方
刚才我们配置完了之后,可以监控本机,也可以监控第一台win服务器(里面自带的windows.cfg),现在我们监控第一台linux服务器!至于为什么要用nrpe,请参考官方文档,这里我就不多说了!
1。被监控端(被监控的服务器)安装nagios-nrpe_2.8.1.orig.tar.gz和插件nagios-plugins-1.4.12.tar.gz
安装过程
====================
useradd nagios
passwd nagios
tar -zxvf nagios-plugins-1.4.12.tar.gz
cd nagios-plugins-1.4.12
./configure
make
make install
=======================
这一步完成后会在/usr/local/nagios/下生成两个目录libexec和share
======================================
chown nagios.nagios /usr/local/nagios
然后
tar -zxvf nagios-nrpe_2.8.1.orig.tar.gz
cd nagios-nrpe_2.8.1
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
========================================================
vi /usr/local/nagios/etc/nrpe.cfg
将allowed_hosts=127.0.0.1
修改成你的nagios服务器的ip
=======================================
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
启动nrpe
================================================
netstat -an|grep 5666
察看是否在5666端口上监听
注意:防火墙 释放端口5666,很重要
===================================
/usr/local/nagios/libexec/check_nrpe -H localhost
察看是否能返回nrpv版本号,返回则正常!
=============================================
vi /usr/local/nagios/etcnrpe.cfg
可以看到里面监控对象
# The following examples use hardcoded command arguments...
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/hda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
=============================================================
我们为了监控swap
在nrpe.cfg中添加
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
===================================================
然后再启动nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d
这样子,在监控端算是设置完了!!!
2。我们来设置nagios服务器端的设置!
安装nagios-nrpe_2.8.1.orig.tar.gz
这里安装过程比上面再被监控服务安装少两部
=========================================
tar -zxvf nagios-nrpe_2.8.1.orig.tar.gz
cd nagios-nrpe_2.8.1
./configure
make all
make install-plugin
================================
然后我们测试下连通性
/usr/local/nagios/libexec/check_nrpe -H 被监控端ip
如果返回nrpe版本号,那么正常!
如果返回拒绝连接!那么telnet ip 5666看是否正常
======================================================
配置:
=================================
由于nrpe外构组件,所以必须在commands.cfg中定义(我这里的nagios版本是3.0.3和2。x的版本有些不一样)
[
[email protected] etc]# 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$
}
========================================================
[
[email protected] etc]# vi /usr/local/nagios/etc/nagios.cfg
中间添加
cfg_file=/usr/local/nagios/etc/objects/aiyo-mailserver.cfg
最后面的 aiyo-mailserver.cfg你们可以自己改,或者Linux1.cfg也可以!
=================================================
新建aiyo-mailserver.cfg
[
[email protected] etc]# vi /usr/local/nagios/etc/objects/aiyo-mailserver.cfg
添加
define host{
use linux-server
host_name aiyo-mailserver
alias aiyo-mailserver
address 210.51.47.213
}
define service{
use generic-service
host_name aiyo-mailserver
service_description HTTP
check_command check_http
}
define service{
use generic-service
host_name aiyo-mailserver
service_description FTP
check_command check_ftp
define service{
use generic-service
host_name aiyo-mailserver
service_description SSH
check_command check_ssh
}
define service{
use generic-service
host_name aiyo-mailserver
service_description SMTP
check_command check_smtp
}
define service{
use generic-service
host_name aiyo-mailserver
service_description POP3
check_command check_pop
}
define service{
use generic-service
host_name aiyo-mailserver
service_description check-swap
check_command check_nrpe!check_swap
}
define service{
use generic-service
host_name aiyo-mailserver
service_description check-load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name aiyo-mailserver
service_description check-disk
check_command check_nrpe!check_had1
define service{
use generic-service
host_name aiyo-mailserver
service_description zombie_procs
check_command check_nrpe!check_zombie_procs
}
define service{
use generic-service
host_name aiyo-mailserver
service_description check-users
check_command check_nrpe!check_users
}
define service{
use generic-service
host_name aiyo-mailserver
service_description total_procs
check_command check_nrpe!check_total_procs
}
保存,退出!
这个里面定义了对象和服务!
注意:
define host{
use linux-server
这个你要能在commands.cfg找到!如果是3.0.x版本,应该就对的
!如果是2。x版本,不一样定了!
=====================================================
我们来运行
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
检测下是不是都正确!
================================================
正确的话,那么我们重新启动nagios
那么在web页面里面就会出现!!
但是页面显示disk一项可能出现红色警告信息!因为linux下如果我的硬盘是sad1,那么写had1就没用了!
如果是scsi磁盘,一定是sad1,
所以请修改nrpe.cfg
添加
command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/sda1
然后再nagios服务器端,重新修改check-disk这个参数
define service{
use generic-service
host_name aiyo-mailserver
service_description check-disk
check_command check_nrpe!check_sda1
}