安装nagios3.2.1总结

1.先介绍一下什么叫nagios
Nagios简介
Nagios是一个用来监视系统和网络的开源应用软件,它通常运行于一个主服务器上,这个服务器运行 Liunx 或 Unix 操作系统。Nagios 利用其众多的插件实现对本机和远端服务的监控,当被监控对象出现异常,Nagios 就会及时给管理人员告警。它是一个基于TCP/IP协议的软件包,包含有nagios主程序和它的各个插件,配置非常灵活,可以监视的项目很多,也可以通过自定义 shell 脚本进行监控服务,非常适合各类企业的网络应用。
Nagios功能非常强大,它可以监控服务和主机,但是他自身并不包括这部分功能的代码,所有的监控、检测功能都是有插件来完成的。再说报警功能,如果监控系统发现问题不能报警那就没有意义了,所以报警也是nagios很重要的功能之一。但是,同样的,nagios自身也没有报警部分的代码,甚至没有插件,而是交给用户或者其他相关开源项目组去完成。nagios安装,是指基本平台,也就是nagios软件包的安装。它是监控体系的框架,也是所有监控的基础。
打开nagios官方的文档,会发现nagios基本上没有什么依赖包,只要求系统是linux或者其他nagios支持的系统。不过如果你没有安装apache(http服务),那么你就没有那么直观的界面来查看监控信息了,所以apache姑且算是一个前提条件。
Nagios 系统的特点主要有下面几点:
监控主机资源和网络服务
允许用户通过设计实现简单的插件来监控自己特定的服务
当被监控对象出现问题时,会及时通知管理人员
事先定义事件处理程序,当对象出现问题时自动调用对应的处理程序
通过 web 页面来监视对象状态,警告提示和日志文件。
ndoutils
ndoutils是将Nagios的配置及监控信息存储到数据库里,NPC通过调用ndo所存储的数据来展现Nagios的信息。
NPC
NPC(Nagios Plugin for Cacti)是一个Cacti插件,安装后可以在Cacti界面里使用Nagios的功能
PHP必须安装PDO 和 JSON扩展。由于NPC使用了Ext JS,如果没有JSON扩展,NPC的界面不会出来,只能看到一个空白页面。初始化PHP环境 需要用phpize命令,所以也要安装 php-devel。ndoutils需要用到mysql的mysql-lib及mysql-inc,因此需要安装mysql-devel。由于刚装系统的时候已经装过了.这个软件本节就不用安装.
2.安装需要的软件
yum -y install httpd //安装Apache
yum -y install gcc //安装开发工具
yum -y install gd gd-devel //安装GD库和开发库
yum -y install php //安装PHP
建立一个nagcmd组 将用户nagios(需要建立)和apache添加到组中用于从Web接口执行外部命令:
[root@localhost ~]#useradd nagios
[root@localhost ~]#passwd nagios
Changing passwordfor user nagios.
New UNIX password:
Retype new UNIXpassword:
passwd: allauthentication tokens updated successfully.
[root@localhost ~]#groupadd nagcmd
[root@localhost ~]#usermod -G nagcmd nagios
[root@localhost ~]#usermod -G nagcmd apache
[root@localhost ~]#tail -1 /etc/group
nagcmd:x:501:nagios,apache
下载安装Nagios软件包和插件包,有两种方式可以实现:
2、直接使用wget命令下载到服务器。
Wget:
Wget http://downloads.sourceforge.net/project/nagios/nagios-3.x/nagios-3.2.1/nagios-3.2.1.tar.gz?r=http%3A%2F%2Fwww.nagios.org%2Fdownload%2Fcore%2Fthanks%2F&ts=1282635348&mirror=cdnetworks-kr-2
Wget http://downloads.sourceforge.net/project/nagiosplug/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz?r=http%3A%2F%2Fwww.nagios.org%2Fdownload%2Fplugins%2F&ts=1282636582&mirror=cdnetworks-kr-2
成功下载两个Nagios的tar包:
nagios-3.2.1.tar.gz
nagios-plugins-1.4.15.tar.gz
展开tar包:
tar -zxvf nagios-3.2.1.tar.gz
tar -zxvf nagios-plugins-1.4.15.tar.gz
进入nagios安装目录开始编译安装nagios软件
cd nagios-3.2.1
./configure --with-command-group=nagcmd ***编译Nagios程序包源码
make all
make install
make install-init **生成init启动脚本
make install-config **设置相应的目录权限
make install-commandmode **生成模板配置文件
make install-webconf **生成apache配置文件
使用htpasswd 命令创建nagios的Web接口访问用户名和密码。
[root@NagiosTestetc]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Newpassword:
Re-type newpassword:
[root@NagiosTest~]# cat /usr/local/nagios/etc/htpasswd.users
nagiosadmin:5DV3J8lr7mUJ6 **密码已经加密了

接下来开始编译安装nagios的插件。
cdnagios-plugins-1.4.15
./configure--with-nagios-user=nagios --with-nagios-group=nagios
make
make install
将nagios加到服务列表中并使之在系统启动时自动启动
chkconfig --add nagios
chkconfig nagios on
chkconfig --list nagios
nagios 0:off 1:off 2:on 3:on 4:on 5:on 6:off

验证配置文件,如果没有报错说明安装正确。
[root@NagiosTestnagios-plugins-1.4.15]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Nagios Core3.2.1
Copyright(c) 2009-2010 Nagios Core Development Team and Community Contributors
Copyright (c)1999-2009 Ethan Galstad
LastModified: 03-09-2010
License:GPL
Website:http://www.nagios.org
Readingconfiguration data...
Read main config file okay...
Processingobject config file '/usr/local/nagios/etc/objects/commands.cfg'...
Processingobject config file '/usr/local/nagios/etc/objects/contacts.cfg'...
Processingobject config file '/usr/local/nagios/etc/objects/timeperiods.cfg'...
Processingobject config file '/usr/local/nagios/etc/objects/templates.cfg'...
Processingobject config file '/usr/local/nagios/etc/objects/localhost.cfg'...
Read object config files okay...
Runningpre-flight check on configuration data...
Checkingservices...
Checked 8 services.
Checkinghosts...
Checked 1 hosts.
Checkinghost groups...
Checked 1 host groups.
Checkingservice groups...
Checked 0 service groups.
Checkingcontacts...
Checked 1 contacts.
Checkingcontact groups...
Checked 1 contact groups.
Checkingservice escalations...
Checked 0 service escalations.
Checkingservice dependencies...
Checked 0 service dependencies.
Checkinghost escalations...
Checked 0 host escalations.
Checkinghost dependencies...
Checked 0 host dependencies.
Checkingcommands...
Checked 24 commands.
Checkingtime periods...
Checked 5 time periods.
Checkingfor circular paths between hosts...
Checkingfor circular host and service dependencies...
Checkingglobal event handlers...
Checkingobsessive compulsive processor commands...
Checkingmisc settings...
Total Warnings: 0
Total Errors: 0
Things lookokay - No serious problems were detected during the pre-flight check
重启apache服务和启动nagios服务
[root@NagiosTestnagios-plugins-1.4.15]# service httpd restart
Stoppinghttpd: [OK]
Startinghttpd: [OK]
[root@NagiosTestnagios-plugins-1.4.15]# service nagios start
Startingnagios: done.
这样已经完成nagios的安装。
Web接口访问:http://localhost/nagios/ (或http://ipaddress/nagios/ )




以上是最基本的nagios的安装方法,但是里面的nagios.cfg配置文件选项非常多,如果要把nagios玩的很溜,这需要专研的精神,希望自己写的nagios能帮助网友们。
本文转自zh888 51CTO博客,原文链接:http://blog.51cto.com/zh888/568521,如需转载请自行联系原作者