- 浏览: 1137766 次
文章分类
最新评论
-
chenhailong:
嘿嘿,没事其实IT这样怎么干也不能成为富翁,就是穷打工的。说是 ...
80后IT跳槽男的故事!你的那? -
denger:
cxh116 写道好人 转帖不留名原文:http://www. ...
程序员的黄金时代 -
cxh116:
好人 转帖不留名
程序员的黄金时代 -
ruby_windy:
500多页的书,我也是这几天刚看到完.乔布斯是半个神,活的像人 ...
看完乔布斯传,说说感受
Nagios 安装 部署 说明
Nagios是一个用来监控主机、服务和网络的开放源码软件,可以在发生故障时发送报警短信和邮件,只要Nagios监控的对象发生故障,系统就会自动发送短信到手机上。所以应用十分广泛。
Nagiosisanopensourcehost,serviceand.networkmonitoringprogram.Whousesit?Lotsofpeople,includingmanybigcompaniesandorganizations。
一.相关包的下载:
可以先下载到windows在通过mount挂载到redhat上,也可以通过wget直接下载:
下载地址:http://www.nagios.org/download
NagiosCoreOSSconsistsofvariousOpenSourcecomponentsthatprovidethefoundationforrock-solidITinfrastructuremonitoring.Downloadallthecomponentsyouneedtogetstarted.
Step1-GetNagiosCore
Required.Containsthecoremonitoringapplicationandwebinterface.
#./wgethttp://ncu.dl.sourceforge.net/project/nagios/nagios-3.x/nagis-3.2.1/nagios-3.2.1.tar.gz
Step2-GetNagiosPlugins
AlsoRequired.Allowsyoutomonitorservices,applications,metrics,andmore.
#./wgethttp://ncu.dl.sourceforge.net/project/nagiosplug/nagiosplug/.4.14/nagios-plugins-1.4.14.tar.gz
Step3-GetNagiosAddons
TrickoutyourNagiosinstallbyextendingitscapabilitieswithhundredsofcommunity-contributedaddons.
#./wgethttp://ncu.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-212/nrpe-2.12.tar.gz
#./wgethttp://ncu.dl.sourceforge.net/project/nagios/nsca-2.x/nsca-27.2/nsca-2.7.2.tar.gz
#./wgethttp://ncu.dl.sourceforge.net/project/nagios/ndoutils-1.x/ndutils-1.4b9/ndoutils-1.4b9.tar.gz
NRPEallowsyoutoremotelyexecuteNagiospluginsonotherLinux/Unixmachines.Thisallowsyoutomonitorremotemachinemetrics(diskusage,CPUload,etc.).NRPEcanalsocommunicatewithWindowsagentaddonslikeNSClient++,soyoucancheckmetricsonremoteWindowsmachinesaswell.
NSCAallowsyoutointegratepassivealertsandchecksfromremotemachinesandapplicationswithNagios.Usefulforprocessingsecurityalerts,aswellasdeployingredundantanddistributedNagiossetups.
NDOUtilsallowsyoutoexportcurrentandhistoricaldatafromoneormoreNagiosinstancestoaMySQLdatabase.Experimental/betaatthispointintime,butseveralcommunityaddonsusethisasoneoftheirdatasources.
监控windows需要NSClient,下载:
http://sourceforge.net/projects/nscplus/
windows上客户端的配置请参考blog:
HowToMonitorRemoteWindowsMachineUsingNagiosonLinux
http://blog.csdn.net/tianlesoftware/archive/2010/03/25/5417814.aspx
监控Linux,需要安装NRPE包和plugins程序。
Web服务器:
httpd-2.2.15.tar.gz
#wgethttp://apache.freelamp.com/httpd/httpd-2.2.15.tar.gz
二.Nagios安装
2.1linux下软件安装步骤
1)解压:Tarzxvf*.gz
2)运行:./configure,会生成makefile文件。
3)编译:./makeall
4)安装软件:./makeinstall,
2.2安装顺序:
1).安装Nagios
./configure
......
Creatingsampleconfigfilesinsample-config/...
***Configurationsummaryfornagios3.2.103-09-2010***:
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
Checkresultdirectory:${prefix}/var/spool/checkresults
Initdirectory:/etc/rc.d/init.d
Apacheconf.ddirectory:/etc/httpd/conf.d
Mailprogram:/bin/mail
HostOS:linux-gnu
WebInterfaceOptions:
------------------------
HTMLURL:http://localhost/nagios/
CGIURL:http://localhost/nagios/cgi-bin/
Traceroute(usedbyWAP):/bin/traceroute
Reviewtheoptionsaboveforaccuracy.Iftheylookokay,
type'makeall'tocompilethemainprogramandCGIs.
--创建用户和组
#groupaddnagios
#useradd-gnagiosnagios
#passwdnagios
[root@Davenagios-3.2.1]#cd./base
[root@Davebase]#pwd
/nagios/nagios-3.2.1/base
[root@Davebase]#./makeall
IfthemainprogramandCGIscompiledwithoutanyerrors,you
cancontinuewithinstallingNagiosasfollows(type'make'
withoutanyargumentsforalistofallpossibleoptions):
makeinstall
-Thisinstallsthemainprogram,CGIs,andHTMLfiles
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!
makeinstall-webconf
-ThisinstallstheApacheconfigfilefortheNagios
webinterface
根据上面的提示,在makeinstall的时候我们要分别执行:
makeinstall
makeinstall-init
makeinstall-commandmode
makeinstall-config
makeinstall-webconf
验证程序是否被正确安装。切换目录到安装路径(这里是/usr/local/nagios),看是否存在etc、bin、sbin、share、var这五个目录,如果存在则可以表明程序被正确的安装到系统了。
五个目录功能的简要说明:
bin |
Nagios执行程序所在目录,这个目录只有一个文件nagios |
etc |
Nagios配置文件位置,初始安装完后,只有几个*.cfg-sample文件 |
sbin |
NagiosCgi文件所在目录,也就是执行外部命令所需文件所在的目录 |
Share |
Nagios网页文件所在的目录 |
Var |
Nagios日志文件、spid等文件所在的目录 |
|
|
2).插件安装:
./configure
Make
Makeinstall
安装完成后,将在目录/usr/local/nagios生成目录libexec目录(里面有很多文件)。
3).安装web服务器apache
Web服务不是nagios所必须的,但是如果nagios没有web,只有通过查看nagios的日志来判断状态。
在unix/linux世界,apache是web服务器的首选对象,其下载网站为www.apache.org。建议下载源码。因为我们不需要很复杂的web功能,因此简单的执行一下几个步骤就可以正确的把apache安装到系统:
1、解包、配置:tarzxvfhttpd-*.tar.gz;./configure–prefix=/usr/local/apache。
2、编译安装:make;makeinstall。
安装完成后,执行命令./usr/local/apache/bin/apachectl–t检查一下apache是否正确安装
4)-GetNagiosAddons。在待监控的机子上安装NRPEforlinux.NSClientforwindows这个在后面配置的时候有说明
./configure
Make
Makeinstall
三.Nagios配置前的准备
最主要的工作是创建nagios用户及其属组,让nagios的运行用户为nagios而不是root。再把目录/usr/local/nagios的属主设置为nagios,以保证系统的安全。Nagios可以以root用户运行,但并不推荐这样做。用下面的步骤来完成上述过程:
1、添加系统帐户nagios,在安装Nagios的时候,已经做过这一步.
--创建用户和组
#groupaddnagios
#useradd-gnagiosnagios
#passwdnagios
在实际的运用场景,nagios用户并没有必要作为系统用户来登录linux系统,因此可以不必设置nagios的用户密码,甚至可以把nagios用户的登录shell设置成/bin/false。
2、更改目录属组:chown–Rnagios.nagios/usr/local/nagios。请注意,有的unix/linux的版本用户和属组分隔符号不是“.”,可能会是这样的形式chown-Rnagios:nagios/usr/local/nagios。
3、sendmail。我们需要使用sendmail来发送故障报警信息,所以这个包必须能够正常工作。现在一般的Linux系统都自带了sendmail,我们只需要启动sendmail即可。
4、手机短信发送工具。
如果公司有发送短信的平台,那么直接调用就可以了,如果没有,我们可以让手机接收邮件,或者使用飞信来发送。
四.Nagios的配置
4.1Apache配置:
AsampleApacheconfigfilesnippetiscreatedwhenyouruntheconfigurescript-youcanfindthesampleconfigfile(namedhttpd.conf)inthesample-config/subdirectoryoftheNagiosdistribution.YouwillneedtoaddthecontentsofthisfiletoyourApacheconfigurationfilesbeforeyoucanaccesstheNagioswebinterface.TheinstructionsfoundbelowdetailhowtomanuallyaddtheappropriateconfigurationentriestoApache.
ConfigureAliasesandDirectoryOptionsForTheWebInterface
Firstyou'llneedtocreateappropriateentriesfortheNagioswebinterface(HTMLandCGIs)inyourwebserverconfigfile.Addthefollowingsnippettoyourwebserverconfigurationfile(i.e.httpd.conf),changingittomatchanydirectorydifferencesonyoursystem.
ScriptAlias/nagios/cgi-bin/usr/local/nagios/sbin
<Directory"/usr/local/nagios/sbin">
OptionsExecCGI
AllowOverrideNone
Orderallow,deny
Allowfromall
AuthName"NagiosAccess"
AuthTypeBasic
AuthUserFile/usr/local/nagios/etc/htpasswd.users
Requirevalid-user
</Directory>
Alias/nagios/usr/local/nagios/share
<Directory"/usr/local/nagios/share">
OptionsNone
AllowOverrideNone
Orderallow,deny
Allowfromall
AuthName"NagiosAccess"
AuthTypeBasic
AuthUserFile/usr/local/nagios/etc/htpasswd.users
Requirevalid-user
</Directory>
Note:ThedefaultNagiosinstallationexpectstofindtheHTMLfilesandCGIsathttp://yourmachine/nagios/andhttp://yourmachine/nagios/cgi-bin/,respectively.Theselocationscanbechangedusingthe--with-htmurland--with-cgiurloptionsintheconfigurescript.
Important!IfyouareinstallingNagiosonamulti-usersystem,youmaywantuseCGIWraptoprovideadditionalsecuritybetweentheCGIsandtheexternalcommandfile.IfyoudecidetouseCGIWrap,theScriptAliasyou'llendupusingwillmostlikelybedifferentfromthatmentionedabove.Moreinformationondoingthiscanbefoundhere.
RestartTheWebServer
Onceyou'vefinishededitingtheApacheconfigurationfile,you'llneedtorestartthewebserverwithacommandlikethis...
/etc/rc.d/init.d/httpdrestart
ConfigureWebAuthentication
Onceyouhaveinstalledthewebinterfaceproperly,you'llneedtospecifywhocanaccesstheNagioswebinterface.
Ifyouhaven'tdonesoalready,you'llneedtoaddtheappropriateentriestoyourwebserverconfigfiletoenablebasicauthenticationfortheCGIandHTMLportionsoftheNagioswebinterface.Instructionsfordoingsocanbefoundhere.
Nowthatyou'veconfiguredyourwebservertorequireauthenticationfortheNagioswebinterface,you'llneedtospecifywhohasaccess.ThisisdonebyusingthehtpasswdcommandsuppliedwithApache.
Runningthefollowingcommandwillcreateanewfilecalledhtpasswd.usersinthe/usr/local/nagios/etcdirectory.Itwillalsocreateanusername/passwordentryfornagiosadmin.Youwillbeaskedtoprovideapasswordthatwillbeusedwhennagiosadminauthenticatestothewebserver.
htpasswd-c/usr/local/nagios/etc/htpasswd.usersnagiosadmin
Continueaddingmoreusersuntilyou'vecreatedanaccountforeveryoneyouwanttoaccesstheCGIs.Usethefollowingcommandtoaddadditionalusers,replacing<username>withtheactualusernameyouwanttoadd.Notethatthe-coptionisnotused,sinceyoualreadycreatedtheinitialfile.
htpasswd/usr/local/nagios/etc/htpasswd.users<username>
Okay,soyou'redonewiththefirstpartofwhatneedstobedone.AtthispointyoushouldbepromptedforausernameandpasswordifyoupointyourwebbrowsertotheNagioswebinterface.Ifyouhaveproblemsgettinguserauthenticationtoworkatthispoint,readyourwebserverdocumentationformoreinfo.
VerifyYourChanges
Don'tforgettocheckandseeifthechangesyoumadetoApachework.Youshouldbeabletopointyourwebbrowserathttp://yourmachine/nagios/andgetthewebinterfaceforNagios.TheCGIsmaynotdisplayanyinformation,butthiswillberemediedonceyouconfigureeverythingandstartNagios.
Theinformationfrom:SettingUpTheWebInterface
http://nagios.sourceforge.net/docs/2_0/installweb.html
4.2Nagios的配置文件
Nagios在安装完会默认生成一些简单的配置文件,但是如果要满足我们需求我们还需要自己添加一些文件。
Objectsarealltheelementsthatareinvolvedinthemonitoringandnotificationlogic.Typesofobjects
include:
Services
ServiceGroups
Hosts
HostGroups
Contacts
ContactGroups
Commands
TimePeriods
NotificationEscalations
NotificationandExecutionDependencies
1)/usr/local/nagios/etc/nagios.cfg。--Nagios的主要配置文件
#Youcanspecifyindividualobjectconfigfilesasshownbelow:
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/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
#Definitionsformonitoringthelocal(Linux)host
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
#DefinitionsformonitoringaWindowsmachine
cfg_file=/usr/local/nagios/etc/objects/windows.cfg
#Definitionsformonitoringarouter/switch
#cfg_file=/usr/local/nagios/etc/objects/switch.cfg
#Definitionsformonitoringanetworkprinter
#cfg_file=/usr/local/nagios/etc/objects/printer.cfg
里面还有与是否发送警告的相关配置参数.默认都是启动的。
先注释掉相关的控制文件,在修改对应的的文件。
Nagios的配置修改之后要
[root@Daveobjects]#servicenagiosrestart
#配置机器启动时自动启动Nagios
#chkconfignagioson
2)/usr/local/nagios/etc/cgi.cfg
cgi.cfg内容如下:
main_config_file=/usr/local/nagios/etc/nagios.cfg
physical_html_path=/usr/local/nagios/share
url_html_path=/nagios
use_authentication=1
authorized_for_system_information=nagiosadmin
authorized_for_configuration_information=nagiosadmin
authorized_for_system_commands=nagiosadmin
authorized_for_all_services=nagiosadmin
authorized_for_all_hosts=nagiosadmin
authorized_for_all_service_commands=nagiosadmin
authorized_for_all_host_commands=nagiosadmin
#authorized_for_read_only=user1,user2
如果有多个用户,用逗号隔开,这些用户就是在apache配置中添加的:
htpasswd-c/usr/local/nagios/etc/htpasswd.usersnagiosadmin
3)/usr/local/nagios/etc/objects/timeperiods.cfg
definetimeperiod{
timeperiod_name24x7
alias24HoursADay,7DaysAWeek
sunday00:00-24:00
monday00:00-24:00
tuesday00:00-24:00
wednesday00:00-24:00
thursday00:00-24:00
friday00:00-24:00
saturday00:00-24:00
}
definetimeperiod{
timeperiod_namenone
aliasNoTimeIsAGoodTime
}
definetimeperiod{
nameus-holidays
timeperiod_nameus-holidays
aliasU.S.Holidays
january100:00-00:00;NewYears
monday-1may00:00-00:00;MemorialDay(lastMondayinMay)
july400:00-00:00;IndependenceDay
monday1september00:00-00:00;LaborDay(firstMondayinSeptember)
thursday-1november00:00-00:00;Thanksgiving(lastThursdayinNovember)
december2500:00-00:00;Christmas
}
definetimeperiod{
timeperiod_name24x7_sans_holidays
alias24x7SansHolidays
useus-holidays;Getholidayexceptionsfromothertimeperiod
sunday00:00-24:00
monday00:00-24:00
tuesday00:00-24:00
wednesday00:00-24:00
thursday00:00-24:00
friday00:00-24:00
saturday00:00-24:00
}
4)/usr/local/nagios/etc/objects/Commands.cfg
该文件保存了写如发送邮件的命令,可以根据自己的需求进行扩展。
#'notify-host-by-email'commanddefinition
definecommand{
command_namenotify-host-by-email
command_line/usr/bin/printf"%b""*****Nagios*****/n/nNotification
Type:$NOTIFICATIONTYPE$/nHost:$HOSTNAME$/nState:$HOSTSTATE$/nAddress:$HOSTA
DDRESS$/nInfo:$HOSTOUTPUT$/n/nDate/Time:$LONGDATETIME$/n"|/bin/mail-s"**$
NOTIFICATIONTYPE$HostAlert:$HOSTNAME$is$HOSTSTATE$**"$CONTACTEMAIL$
}
#'notify-service-by-email'commanddefinition
definecommand{
command_namenotify-service-by-email
command_line/usr/bin/printf"%b""*****Nagios*****/n/nNotification
Type:$NOTIFICATIONTYPE$/n/nService:$SERVICEDESC$/nHost:$HOSTALIAS$/nAddress:
$HOSTADDRESS$/nState:$SERVICESTATE$/n/nDate/Time:$LONGDATETIME$/n/nAdditional
Info:/n/n$SERVICEOUTPUT$"|/bin/mail-s"**$NOTIFICATIONTYPE$ServiceAlert:
$HOSTALIAS$/$SERVICEDESC$is$SERVICESTATE$**"$CONTACTEMAIL$
5)/usr/local/nagios/etc/objects/contacts.cfg文件,该文件保存是接收报警联系人的信息
definecontact{
contact_nameDave
usegeneric-contact
aliasDave
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
emailtianlesoftware@vip.qq.com
}
definecontact{
contact_namenagiosadmin
usegeneric-contact
aliasNagiosAdmin
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
emailtianlesoftware@qq.com
}
definecontactgroup{
contactgroup_nameadmins
aliasNagiosAdministrators
membersnagiosadmin,Dave
}
上面的文件定义了2个联系人,如果有更多联系人的话,照这个格式在后面追加即可。在contactgroup里,多个成员之间用逗号做分界符,如果有更多的联系组,就依相同的格式在文件中追加余下的组。
Table1.Servicenotificationoptions
Notifyontransition |
Option |
WARNINGservicestates |
w |
UNKNOWNservicestates |
u |
CRITICALservicestates |
c |
ServiceRECOVERYstates |
r |
SendNOservicenotifications |
n |
Table2.Hostnotificationoptions
Notifyontransition |
Option |
DOWNhoststates |
d |
UNREACHABLEhoststates |
u |
HOSTRECOVERIES(returntoUPstate) |
r |
SendNOhostnotifications |
n |
7)/usr/local/nagios/etc/objects/windows.cfg监控windows的客户端及监控配置文件
这些文件的参数可以可以参考templates.cfg文件。Windows和Linux的格式有些出入,这点要注意。
definehost{
use windows-server
host_name 192.168.1.80
alias MyWindowsServer
address 192.168.1.80
check_period 24x7
check_interval 5
retry_interval 1
max_check_attempts 10
check_command check-host-alive
notification_period 24x7
notification_interval 30
notification_options d,u,r
contact_groups admins
hostgroups windows-servers
}
definehost{
usewindows-server
host_name10.85.10.80
aliasMyWindows
address10.85.10.80
check_period 24x7
check_interval 5
retry_interval 1
max_check_attempts 10
check_command check-host-alive
notification_period 24x7
notification_interval 30
notification_options d,u,r
contact_groups admins
hostgroups windows-servers
}
definehostgroup{
hostgroup_name windows-servers ;Thenameofthehostgroup
alias WindowsServers ;Longnameofthegroup
members10.85.10.80,192.168.1.80
}
defineservice{
use generic-service
host_name 10.85.10.80
service_description NSClient++Version
check_command check_nt!CLIENTVERSION
}
defineservice{
use generic-service
host_name 10.85.10.80
service_description Uptime
check_command check_nt!UPTIME
}
defineservice{
use generic-service
host_name 10.85.10.80
service_description CPULoad
check_command check_nt!CPULOAD!-l5,80,90
}
defineservice{
use generic-service
host_name 10.85.10.80
service_description MemoryUsage
check_command check_nt!MEMUSE!-w80-c90
}
defineservice{
use generic-service
host_name10.85.10.80
service_description C:/DriveSpace
check_command check_nt!USEDDISKSPACE!-lc-w80-c90
}
defineservice{
use generic-service
host_name10.85.10.80
service_description W3SVC
check_command check_nt!SERVICESTATE!-dSHOWALL-lW3SVC
}
defineservice{
use generic-service
host_name 10.85.10.80
service_description Explorer
check_command check_nt!PROCSTATE!-dSHOWALL-lExplorer.exe
}
如果有多台windowsPC,只需要把相关的属性复制一下,然后把host_name改成对应PC的就可以了。
在安装windows客户端的时候NSClient参数也需要做一些,具体参考blog:
HowToMonitorRemoteWindowsMachineUsingNagiosonLinux
http://blog.csdn.net/tianlesoftware/archive/2010/03/25/5417814.aspx
8)/usr/local/nagios/etc/objects/localhost.cfg监控Linux的客户端及监控配置文件,这个问题文件名也可以自己指定,在nagios.cfg中修改即可。
#Defineahostforthelocalmachine
definehost{
uselinux-server
host_namelocalhost
alias10.85.10.78
address127.0.0.1
check_period 24x7
check_interval 5
retry_interval 1
max_check_attempts 10
check_commandcheck-host-alive
notification_period 24x7
notification_interval 120
notification_options d,u,r
contact_groups admins
}
definehost{
uselinux-server
host_name10.85.9.150
alias10.85.9.150
address10.85.9.150
check_period 24x7
check_interval 5
retry_interval 1
max_check_attempts 10
check_commandcheck-host-alive
notification_period 24x7
notification_interval 120
notification_options d,u,r
contact_groups admins
}
#DefineanoptionalhostgroupforLinuxmachines
definehostgroup{
hostgroup_namelinux-servers
aliasLinuxServers
memberslocalhost,10.85.9.150
}
#Defineaserviceto"ping"thelocalmachine
defineservice{
uselocal-service;Nameofservicetemplatetouse
host_name10.85.9.150
service_descriptionPING
check_command check_ping!100.0,20%!500.0,60%
}
#Defineaservicetocheckthediskspaceoftherootpartition
#onthelocalmachine.Warningif<20%free,criticalif
#<10%freespaceonpartition.
defineservice{
uselocal-service;Nameofservicetemplatetouse
host_name10.85.9.150
service_descriptionRootPartition
check_command check_local_disk!20%!10%!/
}
#Defineaservicetocheckthenumberofcurrentlyloggedin
#usersonthelocalmachine.Warningif>20users,critical
#if>50users.
defineservice{
uselocal-service;Nameofservicetemplatetouse
host_name10.85.9.150
service_descriptionCurrentUsers
check_command check_local_users!20!50
}
#Defineaservicetocheckthenumberofcurrentlyrunningprocs
#onthelocalmachine.Warningif>250processes,criticalif
#>400users.
defineservice{
uselocal-service;Nameofservicetemplatetouse
host_name10.85.9.150
service_descriptionTotalProcesses
check_command check_local_procs!250!400!RSZDT
}
#Defineaservicetochecktheloadonthelocalmachine.
defineservice{
uselocal-service;Nameofservicetemplatetouse
host_name10.85.9.150
service_descriptionCurrentLoad
check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
}
#Defineaservicetochecktheswapusagethelocalmachine.
#Criticaliflessthan10%ofswapisfree,warningiflessthan20%isfree
defineservice{
uselocal-service;Nameofservicetemplatetouse
host_name10.85.9.150
service_descriptionSwapUsage
check_command check_local_swap!20!10
}
#DefineaservicetocheckSSHonthelocalmachine.
#Disablenotificationsforthisservicebydefault,asnotallusersmayhaveSSHenabled.
defineservice{
uselocal-service;Nameofservicetemplatetouse
host_name10.85.9.150
service_description SSH
check_command check_ssh
notifications_enabled 0
}
#DefineaservicetocheckHTTPonthelocalmachine.
#Disablenotificationsforthisservicebydefault,asnotallusersmayhaveHTTPenabled.
defineservice{
uselocal-service;Nameofservicetemplatetouse
host_name10.85.9.150
service_description HTTP
check_command check_http
notifications_enabled 0
}
如果有多台Linux,只需要把相关的属性复制一下,然后把host_name改成对应PC的就可以了。Linux的客户端需要安装NRPE包和plugins程序。
9)验证:
运行程序/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg来检查所有配置文件的正确性。如果运行完毕将在输出尾部出现
TotalWarnings:0
TotalErrors:0
则配置正确,如果有错误,提示也是很明显。修改过来即可。
如:
Error:Invalidhostgroupobjectdirective'membes'.
Error:Couldnotaddobjectpropertyinfile'/usr/local/nagios/etc/objects/windows.cfg'online58.
Errorprocessingobjectconfigfiles!
4.3配置Nagios,通过飞信将警报发送到手机
4.3.1飞信安装
飞信官方网站:http://www.it-adv.net/
fetion20091117
wgethttp://www.it-adv.net/fetion/downng/library_linux.tar.gz
wgethttp://www.it-adv.net/fetion/downng/fetion20090406003-linux.tar.gz
wgethttp://www.it-adv.net/fetion/downng/fetion20091117-linux.tar.gz
#在安装飞信之前需要在/usr/lib目录下加上libACE库文件,以便使飞信能够正常使用
[root@localhostsrc]#tarzxvflibrary_linux.tar.gz
[root@localhostsrc]#mvlibACE*libcrypto.so.0.9.8libssl.so.0.9.8/usr/lib
#正式安装飞信
[root@localhostsrc]#tarzxvffetion20090406003-linux.tar.gz
[root@localhostsrc]#mvinstall/usr/local/fetion
[root@localhostsrc]#chmod-R755/usr/local/fetion
[root@localhostsrc]#chown-Rnagios:nagios/usr/local/fetion
#移动服务器更新,需要更新软件
[root@localhostsrc]#tarzxvffetion20091117-linux.tar.gz
[root@localhostsrc]#cpfx/*/usr/local/fetion
[root@localhostsrc]#vi/etc/ld.so.conf
includeld.so.conf.d/*.conf
/usr/local/fetion#增加目录
[root@localhostsrc]#ldconfig
[root@localhostsrc]#/usr/local/fetion/fetion--mobile=138*****--pwd=***--to=138*****--msg-utf8="test"--debug
注意:这里的password是飞信的登陆密码。如果能收到短信,飞信就安装完成了。
[root@localhostsrc]#/usr/local/fetion/fetion##帮助
[root@localhostsrc]#cp/usr/local/fetion/fetion/usr/bin/
4.3.2Nagios中的飞信配置
1)在commads.cfg文件中添加2个选项
definecommand{
command_namenotify-host-by-fetion
command_line/usr/bin/fetion--mobile=13865997399--pwd=woshidmm--to=$CONTACTPAGER$--msg-utf8="Host$HOSTSTATE$alertfor$HOSTNAME$!on'$LONGDATETIME$'"$CONTACTPAGER$
}
definecommand{
command_namenotify-service-by-fetion
command_line/usr/bin/fetion--mobile=13865997399--pwd=woshidmm--to=$CONTACTPAGER$--msg-utf8="$HOSTADDRESS$$HOSTALIAS$/$SERVICEDESC$is$SERVICESTATE$on$LONGDATETIME$"$CONTACTPAGER$
}
2)在contacts.cfg的联系人中添加pager选项,和相关命令的调用。
definecontact{
contact_namenagiosadmin
usegeneric-contact
aliasNagiosAdmin
service_notification_period24x7
host_notification_period24x7
service_notification_optionsw,u,c,r
host_notification_optionsd,u,r
service_notification_commandsnotify-service-by-email,notify-service-by-fetion
host_notification_commandsnotify-host-by-email,notify-host-by-fetion
emaildaimm@sf-express.com
pager13888888888,13888888888
}
重启Nagios:servicenagiosreload
启动apache服务:
[root@Davebin]#servicehttpdstart
启动nagios服务:
[root@Davebin]#servicenagiosstart
4.4测试:
在IE中输入地址:http://ip/nagios就可以看到管理界面了。如果有更多的服务器,建议使用mysql数据来管理监控对象。
以上内容是Nagios的简单的安装部署应用,如果说要监听打印机,交换机之类的,还需要安装对应的插件。等以后有空的时候在慢慢研究了.如果感兴趣的也可以研究下Nagios的文档。
相关推荐
详细介绍nagios的安装部署,完美解决安装过程中遇到的各种Error
Nagios安装配置说明: 1,nagios的安装; 2,nagios配置; 3,nagios服务
Cacti+Nagios完全攻略整合cacti与nagios安装部署.pdf
(4)NDOUtils:则用来将Nagios的配置信息和各event产生的数据存入数据库,以实现 这些数据的快速检索和处理这四个ADDON(附件)中,NRPE和NSClient++工作于客户端,NDOUtils工作于服务器端,而NSCA则需要同时安装在...
linux下的nagios网络监视器的安装与部署
Nagios的安装部署和与Cacti的整合(linuxtone
nagios安装和配置全过程,具体到每一步,并加上个人安装配置心得!
nagios 安装 中文 部署 nagios 安装 中文 部署 nagios 安装 中文 部署 nagios 安装 中文 部署
nagios rpm 安装 配置 及部署 监控 nagios rpm 安装 配置 及部署 监控
Centos环境安装LAMP环境和nagios程式部署
这里对cacti和nagios做了整合,整合原理其实很简单,就是在cacti中安装nagios for cacti插件,nagios的数据通过ndo2db保存到mysql中,cacti读取mysql数据进行展示。 该文档包含的内容: 1.nagios的基本安装 2.msn...
linux下nagios安装配置,及用到的插件。
NAGIOS3.5详细安装说明,包括资源下载,安装步骤,对象配置等
nagios在redhat平台上的安装部署,通过飞信和邮件进行报警,nrpe的安装调试。
Linux下Nagios的安装与配置,详细说明开源软件Nagios的部署
nagios3.5.0 server端一键安装,客户端一键安装,附添加监控客户端脚本。 已经在centos5/rhel5和centos6/rhel6上测试过,均无问题。 监控内容包括 cpu内存使用率,磁盘使用情况,磁盘IO,磁盘utils,常用的服务,...
监控主机部署Nagios 基础环境 1.安装依赖包 [root@nagios ~]# yum install -y gcc glibc glibc-common wget unzip httpd php gd php-gd gd-devel perl postfix 2.获取Nagios以及相关插件包(这里已下载好,放在/usr...
nagios监控部署+邮箱报警—出问题报错可以看看不错的教程!
Nagios安装部署 nagios网络监测中文版 Nagios在线帮助中文版.CHM