nagios实验文档全攻略.docx
《nagios实验文档全攻略.docx》由会员分享,可在线阅读,更多相关《nagios实验文档全攻略.docx(30页珍藏版)》请在冰豆网上搜索。
nagios实验文档全攻略
一.准备阶段:
1.实验环境
包含3台主机,详细信息如下
主机名
操作系统
IP
作用
nagios-server
redhat5.2
192.168.0.111
监控机
dbpi
redhat5.2
192.168.0.100
被监控机
yahoon
xp
192.168.0.28
被监控机
注:
监控机:
安装了nagios软件的机器,对监控的数据做处理,并且提供web界面查看和管理.当然也可以对本机自身的信息进行监控.
被监控机:
安装了NRPE等客户端,根据监控机的请求执行监控,然后将结果回传给监控机.
2.nagios原理
这里引用某位仁兄的话
nagios的功能是监控服务和主机,但是他自身并不包括这部分功能的代码,所有的监控、检测功能都是有插件来完成的。
再说报警功能,如果监控系统发现问题不能报警那就没有意义了,所以报警也是nagios很重要的功能之一。
但是,同样的,nagios自身也没有报警部分的代码,甚至没有插件,而是交给用户或者其他相关开源项目组去完成。
nagios安装,是指基本平台,也就是nagios软件包的安装。
它是监控体系的框架,也是所有监控的基础。
打开nagios官方的文档,会发现nagios基本上没有什么依赖包,只要求系统是linux或者其他nagios支持的系统。
不过如果你没有安装apache(http服务),那么你就没有那么直观的界面来查看监控信息了,所以apache姑且算是一个前提条件。
关于apache的安装,网上有很多,照着安装就是了。
安装之后要检查一下是否可以正常工作。
原文链接[url]
3.Nagios定义的监控状态
nagios定义了4中监控状态,代表不同的严重级别,除了OK代表正常不用关心外,其余3种都要引起重视.如下表
状态
代码
颜色
正常
OK
绿色,
警告
WARNING
黄色,
严重
CRITICAL
红色,
未知错误
UNKOWN
深黄色
4.所用软件
nagios-2.9.tar.gz
nagios-plugins-1.4.9.tar.gz
nrpe-2.8.1.tar.gz
NSClient++-0.2.7.zip
注:
前三个的下载地址:
[url]http:
//www.nagios.org[/url],
后一个的[url]
5.总体目标
学习嘛,总要有个目标,很简单,就是看到下面这张图
具体信息如下表
主机名
要监控的服务
nagios-server
是否活动
是否开启ftp
磁盘使用情况
dbpi
是否活动
是否开启ssh
磁盘使用情况
cpu负载
swap分区使用情况
主进程数
当前登陆用户
僵尸进程数
yahoon
是否活动
是否开启80端口
是否启动W3SVC服务
cpu负载
内存使用情况
运行时间
NSClient客户端版本(NSClient是一个windows下的nagios客户端)
C盘使用情况
D盘使用情况
explorer进程运行情况
其中蓝色字体的服务是外部服务,也就是说不需要登陆被监控机,直接在外部就可以进行检查.例如我们需要检查被监控机是否打开80端口,就可以在别的一台机器上telnet被监控机的80端口即可.
绿色字体表示是内部服务,意思是必须登陆到被监控机上才能查看.因为它们属于”本地信息”(nagios将之称为LOCAL).很容易理解,你不登陆到被监控机上,如何知道当前磁盘的使用情况呢?
nagios是不是很强大,基本上对监控对象的任何信息都可以一手掌握了.而且不用登陆到目的机就可以看到那台机器私密的”本地信息”,比木马还厉害啊.但是别误会,这可不是什么木马.nagios有着十分安全的措施.
这确实是一个庞大的工程,你想想这还只是三台机器而已都已经监控这么多服务了,那要是多个几十台怎么办,不用紧张,从现在开始,跟我动手吧.
家庭作业,将所用的软件下载好,配置好监控机192.168.0.111上的apache.
二.基本安装和配置
本部分主要参考官方文档和田逸的文章<<看我出招之:
我用Nagios(技术细节)>>来修改完成.
最后达到如下的功能
监控机自身的信息,包括主机信息以及对外提供的服务
被监控机对外提供的服务
如下所有的操作都在监控机192.168.0.111上进行
1.安装nagios主程序
解压缩
tar-zxvfnagios-2.9.tar.gz
cdnagios-2.9
编译,指定安装目录为/usr/local/nagios
./configure--prefix=/usr/local/nagios
输出如下信息
***Configurationsummaryfornagios2.904-10-2007***:
GeneralOptions:
-------------------------
Nagiosexecutable:
nagios
Nagiosuser/group:
nagios,nagios
Commanduser/group:
nagios,nagios
EmbeddedPerl:
no
EventBroker:
yes
Install${prefix}:
/usr/local/nagios
Lockfile:
${prefix}/var/nagios.lock
Initdirectory:
/etc/rc.d/init.d
HostOS:
linux-gnu
WebInterfaceOptions:
------------------------
HTMLURL:
[url]http:
//localhost/nagios/[/url]
CGIURL:
[url]http:
//localhost/nagios/cgi-bin/[/url]
Traceroute(usedbyWAP):
/usr/sbin/traceroute
Reviewtheoptionsaboveforaccuracy.Iftheylookokay,
type'makeall'tocompilethemainprogramandCGIs.
makeall
输出如下信息
***Compilefinished***
IfthemainprogramandCGIscompiledwithoutanyerrors,you
cancontinuewithinstallingNagiosasfollows(type'make'
withoutanyargumentsforalistofallpossibleoptions):
makeinstall
-Thisinstallsthemainprogram,CGIs,andHTMLfiles
使用makeinstall来安装主程序,CGI和HTML文件
makeinstall-init
-Thisinstallstheinitscriptin/etc/rc.d/init.d
使用makeinstall-init在/etc/rc.d/init.d安装启动脚本
makeinstall-commandmode
-Thisinstallsandconfigurespermissionsonthe
directoryforholdingtheexternalcommandfile
使用makeinstall-commandmode来配置目录权限
makeinstall-config
-Thisinstalls*SAMPLE*configfilesin/usr/local/nagios/etc
You'llhavetomodifythesesamplefilesbeforeyoucan
useNagios.ReadtheHTMLdocumentationformoreinfo
ondoingthis.Payparticularattentiontothedocson
objectconfigurationfiles,astheydeterminewhat/how
thingsgetmonitored!
使用makeinstall-commandmode来安装示例配置文件,安装的路径是/usr/local/nagios/etc.
***SupportNotes*******************************************
IfyouhavequestionsaboutconfiguringorrunningNagios,
pleasemakesurethatyou:
-Lookatthesampleconfigfiles
-ReadtheHTMLdocumentation
-ReadtheFAQsonlineat[url]http:
//www.nagios.org/faqs[/url]
beforeyoupostaquestiontooneofthemailinglists.
Alsomakesuretoincludepertinentinformationthatcould
helpothershelpyou.Thismightinclude:
-WhatversionofNagiosyouareusing
-Whatversionofthepluginsyouareusing
-Relevantsnippetsfromyourconfigfiles
-RelevanterrormessagesfromtheNagioslogfile
FormoreinformationonobtainingsupportforNagios,visit:
[url]http:
//www.nagios.org/support/[/url]
*************************************************************
Enjoy.
很多人都不注意安装过程中的输出信息,直到makeinstall出错了才到处找人求救,而实际上输出的内容包含很多有价值的信息,例如安装路径,版本,每一步做什么,接下来的步骤等.尤其是输出的最后一屏信息,我个人建议好好的读一下.例如上面就列出了很多有价值的信息,我们只需要按照他说的做就行了.
安装
makeinstall
输出如下错误
cd./base&&makeinstall
make[1]:
Enteringdirectory`/home/yahoon/nagios/nagios-2.9/base'
makeinstall-basic
make[2]:
Enteringdirectory`/home/yahoon/nagios/nagios-2.9/base'
/usr/bin/install-c-m775-onagios-gnagios-d/usr/local/nagios/bin
/usr/bin/install:
invaliduser`nagios'非法用户nagios
make[2]:
***[install-basic]Error1
make[2]:
Leavingdirectory`/home/yahoon/nagios/nagios-2.9/base'
make[1]:
***[install]Error2
make[1]:
Leavingdirectory`/home/yahoon/nagios/nagios-2.9/base'
make:
***[install]Error2
按照文档说明增加用户,修改权限
[root@localhostnagios-2.9]#useraddnagios
[root@localhostnagios-2.9]#mkdir/usr/local/nagios
[root@localhostnagios-2.9]#chownnagios.nagios/usr/local/nagios
查看目录权限
[root@localhostnagios-2.9]#ll/usr/local
drwxr-sr-x2nagiosnagios4096Jul1011:
14nagios
看到nagios目录的权限已经被正确修改了
重新执行makeinstall输出信息如下
***Mainprogram,CGIsandHTMLfilesinstalled***
YoucancontinuewithinstallingNagiosasfollows(type'make'
withoutanyargumentsforalistofallpossibleoptions):
makeinstall-init
-Thisinstallstheinitscriptin/etc/rc.d/init.d
makeinstall-commandmode
-Thisinstallsandconfigurespermissionsonthe
directoryforholdingtheexternalcommandfile
makeinstall-config
-Thisinstalls*SAMPLE*configfilesin/usr/local/nagios/etc
You'llhavetomodifythesesamplefilesbeforeyoucan
useNagios.ReadtheHTMLdocumentationformoreinfo
ondoingthis.Payparticularattentiontothedocson
objectconfigurationfiles,astheydeterminewhat/how
thingsgetmonitored!
make[1]:
Leavingdirectory`/home/yahoon/nagios/nagios-2.9'
执行如下命令来安装脚本
makeinstall-init
执行
makeinstall-commandmode
输出信息如下
/usr/bin/install-c-m775-onagios-gnagios-d/usr/local/nagios/var/rw
chmodg+s/usr/local/nagios/var/rw
***Externalcommanddirectoryconfigured***
YoucancontinuewithinstallingNagiosasfollows(type'make'
withoutanyargumentsforalistofallpossibleoptions):
makeinstall-config
-Thisinstalls*SAMPLE*configfilesin/usr/local/nagios/etc
You'llhavetomodifythesesamplefilesbeforeyoucan
useNagios.ReadtheHTMLdocumentationformoreinfo
ondoingthis.Payparticularattentiontothedocson
objectconfigurationfiles,astheydeterminewhat/how
thingsgetmonitored!
执行
makeinstall-config
输出信息如下
/usr/bin/install-c-m775-onagios-gnagios-d/usr/local/nagios/etc
/usr/bin/install-c-m664-onagios-gnagiossample-config/nagios.cfg/usr/local/nagios/etc/nagios.cfg-sample
/usr/bin/install-c-m664-onagios-gnagiossample-config/cgi.cfg/usr/local/nagios/etc/cgi.cfg-sample
/usr/bin/install-c-m660-onagios-gnagiossample-config/resource.cfg/usr/local/nagios/etc/resource.cfg-sample
/usr/bin/install-c-m664-onagios-gnagiossample-config/template-object/localhost.cfg/usr/local/nagios/etc/localhost.cfg-sample
/usr/bin/install-c-m664-onagios-gnagiossample-config/template-object/commands.cfg/usr/local/nagios/etc/commands.cfg-sample
***Sampleconfigfileinstalled***
Remember,theseare*SAMPLE*configfiles.You'llneedtoread
thedocumentationformoreinformationonhowtoactuallydefine
services,hosts,etc.tofityourparticularneeds.
IfyouhavequestionsaboutconfiguringNagiosproperly,please:
-Lookatthesampleconfigfiles
-ReadtheHTMLdocumentation
-ReadtheFAQsonlineat[url]http:
//www.nagios.org/faqs[/url]
*BEFORE*youpostaquestiontooneofthemailinglists.
验证程序是否被正确安装。
切换目录到安装路径(这里是/usr/local/nagios),看是否存在etc、bin、sbin、share、var这五个目录,如果存在则可以表明程序被正确的安装到系统了。
后表是五个目录功能的简要说明:
bin
Nagios执行程序所在目录,nagios文件即为主程序
etc
Nagios配置文件位置,初始安装完后,只有几个*.cfg-sample文件
sbin
NagiosCgi文件所在目录,也就是执行外部命令所需文件所在的目录
Share
Nagios网页文件所在的目录
Var
Nagios日志文件、spid等文件所在的目录
var/archives
Emptydirectoryforthearchivedlogs
var/rw
Emptydirectoryfortheexternalcommandfile
2.安装插件
解压缩
tar-zxvfnagios-plugins-1.4.9.tar.gz
cdnagios-plugins-1.4.9
编译,指定路径为之前nagios的安装路径
./configure--prefix=/usr/local/nagios/
make
安装
makeinstall
ls/usr/local/nagios/libexec/
会显示安装的插件文件,即所有的插件都安装在libexec这个目录下
将apache的运行用户加到nagios组里面
从httpd.conf中过滤出当前的apache运行用户
grep^User/usr/local/apache2/conf/httpd.conf
我的是vpopmail,下面将这个用户加入nagios组
usermod-Gnagiosvpopmail
3.修改apache配置
修改apache的配置文件,增加nagios的目录,并且访问此目录需要进行身份验证
vi/usr/local/apache2/conf/httpd.conf,在最后增加如下内容
#settingfornagios20120214
ScriptAlias/nagios/cgi-bin/usr/local/nagios/sbin
OptionsExecCGI
AllowOverrideNone
Orderallow,deny
Allowfromall
AuthName"NagiosAccess"
AuthTypeBasic
AuthUserFile/usr/local/nagios/etc/htpasswd
//用于此目录访问身份验证的文件(注意:
此处注释需要去掉)
Requirevalid-user
Alias/nagios/usr/local/nagios/share
OptionsNone
AllowOverrideNone
Orderallow,deny
Allowfromall
AuthName"NagiosAccess"
AuthTypeBasic
AuthUserFile/usr/local/nagios/etc/htpasswd
//用于此目录访问身份验证的文件(注意:
此处注释需要去掉)
Requirevalid-user