




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
Nagiosnagios可以對服務器進行全面的監控,包括服務(apache、mysql、ntp、dns、disk、qmail和sshd等等)的狀態,服務器的狀態(up、down等等)。它是一個完全GPL協議的開源軟件包,包含有nagios主程序和它的各個插件,配置非常靈活,可以監視的項目很多,可以自定義shell腳本進行監控服務,非常適合大型網絡。nagios的包含主動監控和被動監控。主動檢查是通過監控中心的主機發出請求,讓運行在遠程主機上的nrpe守護進程收集信息,然后報告它,它通過web接口把數據顯示在頁面上。它的工作原理如下:被動監控是當遠程被監控主機處于防火墻之內的時候,只有遠程主機可以訪問到監控中心,防火墻之內可以設置另外一個監控中心,遠程監控中心的nagios收集服務器信息以后,和nsca報告,由naca客戶端報告naca的服務器端,然后報告監控中心的nagios,通過web接口顯示監控結果。nagios的功能非常強大,/是它的窩,只有e文、法文和日文,沒有中文,可惜啊。我現在引用它的一段文字進行總結一下到底什么是nagios:WhatIsThis?什么是nagios?Nagios®isasystemandnetworkmonitoringapplication.Itwatcheshostsandservicesthatyouspecify,alertingyouwhenthingsgobadandwhentheygetbetter.NagioswasoriginallydesignedtorununderLinux,althoughitshouldworkundermostotherunicesaswell.SomeofthemanyfeaturesofNagios®include:Monitoringofnetworkservices(SMTP,POP3,HTTP,NNTP,PING,etc.)Monitoringofhostresources(processorload,diskusage,etc.)SimpleplugindesignthatallowsuserstoeasilydeveloptheirownservicechecksParallelizedservicechecksAbilitytodefinenetworkhosthierarchyusing"parent"hosts,allowingdetectionofanddistinctionbetweenhoststhataredownandthosethatareunreachableContactnotificationswhenserviceorhostproblemsoccurandgetresolved(viaemail,pager,oruser-definedmethod)AbilitytodefineeventhandlerstoberunduringserviceorhosteventsforproactiveproblemresolutionAutomaticlogfilerotationSupportforimplementingredundantmonitoringhostsOptionalwebinterfaceforviewingcurrentnetworkstatus,notificationandproblemhistory,logfile,etc.Nagios是一個監視系統和網絡的應用程序。它監視你所指定主機和服務,當監視的內容變好或者變壞時發出警告。Nagios最初是被設計在Linux平臺上運行的,然而現在在其他平臺上也運行良好。Nagios的特性包括:監視網絡服務(SMTP,POP3,HTTP,NNTP,PING等等)監視主機資源(處理器負載、磁盤空間等)容許用戶開發自己的插件去檢查自定義的項目;通過使用“父主機”,定義網絡主機的分層,容許探測主機down掉或者不可到達。可以定義在主機或服務運行期間,事件發生以后如何處理和解決方式;自動記錄錯誤日志;支持冗余監視;可選web接口,通過web頁面查看當前網絡狀態,提示和報告故障歷史,日志文件等;Nagios的系統要求:Linux、Unix等apacheGD庫(1.63以上)zlibpnglibjpeglibbasicicons等,其中apache的安裝在blog中已經有相關的文章,搜索一下就行;gd、zlib、pnglib和jpeglib安裝比較簡單,步驟:下載tarballtarzxvfxxx.tar.gzcdxxx./configuremake&&makeinstallNagios的安裝過程(FreeBSD)nagios的安裝比較簡單,復雜的是設置和配置參數的設定。不過你要放松一點,畢竟我們要搞定它,不是嗎?那就開始吧:1:獲得最新的安裝包,/download2:以root身份登錄服務器,目前最新的版本是2.5:nagios,版本2.5:fetch/sourceforge/nagios/nagios-2.5.tar.gzorwget/sourceforge/nagios/nagios-2.5.tar.gz獲得nagios插件,版本1.4.3:/sourceforge/nagiosplug/nagios-plugins-1.4.3.tar.gz3)獲得圖庫文件:/nagios/imagepak-base.tar.gzNRPE,版本2.5.2/sourceforge/nagios/nrpe-2.5.2.tar.gzNSCA,版本2.6/sourceforge/nagios/nsca-2.6.tar.gz3:切換到root用戶:sudosu4:解壓縮tarzxvfnagios-2.5.tar.gz5:建立運行nagios的用戶:addusernagios6:建立安裝nagios的文件夾,并使這個文件夾的所有者為nagios:nagiosmkdir/usr/local/nagioschownnagios.nagios/usr/local/nagios7:確認web服務器的用戶可能會通過web接口執行一些命令,必須確定web服務器以哪個用戶運行的,通常為apache:grep"AUser"/usr/local/apache2/conf/httpd.conf8:建立命令文件組這個新的組會包括apache的用戶和nagios的用戶pwgroupaddnagcmdpwusermodapache-Gnagcmdpwusermodnagios-Gnagcmdcat/etc/groupnagcmd:*:9007:apache,nagios8:運行配置腳本并安裝nagioscdnagios-2.5./configure--prefix=/usr/local/nagios--with-gd-lib=/usr/local/lib--with-gd-inc=/usr/local/include***Configurationsummaryfornagios2.507-13-2006***GeneralOptions:Nagiosexecutable:nagiosNagiosuser/group:nagios,nagiosCommanduser/group:nagios,nagiosEmbeddedPerl:noEventBroker:yesInstall${prefix}:/usr/local/nagiosLockfile:${prefix}/var/nagios.lockInitdirectory:/usr/local/etc/rc.dHostOS:freebsd6.0WebInterfaceOptions:HTMLURL:http://localhost/nagios/CGIURL:http://localhost/nagios/cgi-bin/Traceroute(usedbyWAP):/usr/sbin/tracerouteReviewtheoptionsaboveforaccuracy.Iftheylookokay,type'makeall'tocompilethemainprogramandCGIs.makeallmakeinstallmakeinstall-initmakeinstall-commandmodemakeinstall-config9:安裝nagios-pluginstarzxvfnagios-plugins-1.4.3.tar.gzcdnagios-plugins-1.4.3./configure--prefix=/usr/local/nagios-pluginsmakeallmakeinstall安裝完成以后在/usr/local/nagios-plugins-plugins會產生一個libexec的目錄,將該目錄全部移動到/usr/local/nagios目錄下即可。mv/usr/local/nagios-plugins-plugins/libexec//usr/local/nagios/10:imagepak-base.tar.gz的安裝tar-vzfimagepak-base.tar.gz解壓以后是base目錄mvbase//usr/local/nagios/share/images/logos/現在開始配置:1:配置web接口假設你已經運行了apache,如果沒有,請參考:http://localhost/upload/blog.php?do-showone-tid-18.htmlvi/usr/local/apache2/conf/httpd.conf添加如下內容:ScriptAlias/nagios/cgi-bin/usr/local/nagios/sbin<Directory"/usr/local/nagios/sbin">OptionsExecCGIAllowOverrideNoneOrderallow,denyAllowfromallAuthName"NagiosAccess"AuthTypeBasicAuthUserFile/usr/local/nagios/etc/htpasswd.usersRequirevalid-user</Directory>Alias/nagios/usr/local/nagios/share<Directory"/usr/local/nagios/share">OptionsNoneAllowOverrideNoneOrderallow,denyAllowfromallAuthName"NagiosAccess"AuthTypeBasicAuthUserFile/usr/local/nagios/etc/htpasswd.usersRequirevalid-user</Directory>修改完畢,保存文件,并重啟apache:/usr/local/apahce2/bin/apachectlrestart2:配置apache的BASIC認證:生成認證密碼:/usr/local/apache2/bin/htpasswd-/usr/local/nagios/etc/htpasswd.usersnagiosnagiosapache接口配置完成。開始配置nagios:cd/usr/local/nagios/etc/在/usr/local/nagios/etc下是nagios的配置模板文件-sample,把.cfg-sample文件全部拷貝成.cfg例如:cpnagios.cfg-samplenagios.cfg全部拷貝完成即可.viminimal.cfg注釋所有command:注釋的方法是在每一個定義語句前面添加”#“修改cgi.cfg修改use_authentication=l為use_authentication=0,即不用驗證.不然有一些頁面不會顯示。現在檢查配置文件是否有語法錯誤:/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg如果正確,會顯示以下結果:TotalWarnings:0TotalErrors:0否則,需要根據提示進行修改配置文件。配置文件等會再弄。現在啟動nagios/usr/local/nagios/bin/nagios-d/usr/local/nagios/etc/nagios.cfg為了使nagios異常中斷,我們使用daemontools啟動:安裝daemontool:mkdir-p/packagechmodl755/packagecd/packagefetchhttp://cr.yp.to/daemontools/daemontools-0.76.tar.gzcdadmin/daemontools-0.76/package/install檢查svscan進程是否啟動:psaux|grepsvscanroot 3760.00.0l6360con-IW- 0:00.00/bin/sh/command/svscanbootroot 4ll0.00.0l224208con-S8Jul060:42.50svscan/serviceok,啟動正常了。cd/servicemkdirnagioschmodl755nagiostouch./runchmod755./runvirunPATH=/usr/local/bin:/usr/bin:/binexportPATHexecenv-PATH=$PATH\/usr/local/nagios/bin/nagios/usr/local/nagios/etc/nagios.cfgmkdirlogcdlogtouch./runchmod755./runvi./run#!/bin/shexecsetuidgidlogadminmultilogts1000000n100./mainmkdirmainchmod777mainchownnagios.nagiosmaintouchstatuschownnagios.nagiosstatussvc-u/service/nagios/svstat/service/nagios/root@##psauxww|grepnagiosroot232760.00.11176488??I5:00PM0:01.71supervisenagiosnagios342510.00.323161552??S6:06PM0:00.10/usr/local/nagios/bin/nagios/usr/local/nagios/etc/nagios.cfgroot@##ok,現在把nagios服務做成自動啟動的服務了。通過svc命令可以啟動或者停止服務。svcoptsservicesoptsisaseriesofgetopt-styleoptions.servicesconsistsofanynumberofarguments,eachargumentnamingadirectoryusedbysupervise.-u:Up.Iftheserviceisnotrunning,startit.Iftheservicestops,restartit.-d:Down.Iftheserviceisrunning,senditaTERMsignalandthenaCONTsignal.Afteritstops,donotrestartit.-o:Once.Iftheserviceisnotrunning,startit.Donotrestartitifitstops.-p:Pause.SendtheserviceaSTOPsignal.-c:Continue.SendtheserviceaCONTsignal.-h:Hangup.SendtheserviceaHUPsignal.-a:Alarm.SendtheserviceanALRMsignal.-i:Interrupt.SendtheserviceanINTsignal.-t:Terminate.SendtheserviceaTERMsignal.-k:Kill.SendtheserviceaKILLsignal.-x:Exit.supervisewillexitassoonastheserviceisdown.Ifyouusethisoptiononastablesystem,you'redoingsomethingwrong;superviseisdesignedtorunforever.比如:停止nagios--svc-d/service/nagios/重啟nagios--svc-t/service/nagios/啟動nagios--svc-u/service/nagios/當然,你也可以使用inited的方式進行:/usr/local/etc/rc.d/nagiosstart/stop好了,反正daemontools很強大,以后慢慢熟悉,轉入正題。現在打開網頁:http://localhost/nagios/一定會讓你大吃一驚,呵呵,我的服務器和服務狀態都清楚的看到了。現在我們的nagios中只有一個,那就是它自己,loca山ost,呵呵,等會我們添加別的主機和主機服務,ok,我們認識一下nagios的廬山真面目:配置nagios:1) 為主機添加服務2) 添加主機并添加服務3) 停止一個服務4) 刪除一臺主機和服務5) 查看所有主機的故障6) 查看一臺特定的主機狀態7) 改變報警的時間間隔8) 改變發現故障的重試次數9) 如何在nagios中使用外部命令1)為主機添加一個服務為localhost主機添加qmail服務的監控,方法如下:viminimal.cfgdefineservice{use generic-service;Nameofservicetemplatetousehost_name localhostTOC\o"1-5"\h\zservice_descriptionqmail_smtpis_volatile 0check_period 24x7max_check_attempts1normal_check_interval1retry_check_interval 1contact_groups adminsnotification_options w,u,c,rnotification_interval960notification_period 24x7check_command check_smtp!20%!10%!/
可以直接拷貝原有的進行修改,我這個就是拷貝的原有的check」ocal_disk進行的。修改host_name,service_description,check_command等defineservice{use generic-service;Nameofservicetemplatetousehost_name localhostservice_descriptionqmail_pop3TOC\o"1-5"\h\zis_volatile 0check_period 24x7max_check_attempts 1normal_check_interval1retry_check_interval 1contact_groupsnotification_optionsnotification_intervalnotification_periodcheck_command}contact_groupsnotification_optionsnotification_intervalnotification_periodcheck_command}照貓畫虎的進行修改adminsw,u,c,r96024x7check_pop!20%!10%!/然后去修改:vicheckcommands.cfg#'check_qmail'commanddefinitiondefinecommand{command_namecheck_qmailcommand_line$USER1$/check_smtp-H}definecommand{command_namecheck_pop3command_line$USER1$/check_pop-H}保存,然后檢查配置文件:/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg如果沒有錯誤會顯示:TotalWarnings:0TotalErrors:0如果有錯誤,請根據提示進行錯誤的修正。重啟nagiossvc-d/service/nagios/&&svc-u/service/nagios/通過web頁面檢查nagios的結果:53/nagios/點擊“ServiceDetail"會出現:2)添加主機并添加服務我們會監控這臺主機的負載、磁盤等一些沒有通過端口方式啟動的服務器狀態,以及它的服
務,比如:apache、mysql、qmail和ntp等等吧。那么沒有端口的nagios直接能監控到嗎?答案是不行。所以我們必須在兩臺主機上安裝nrpe,nrpe可以啟動5666端口,把檢測的信息源源不斷的傳給監控中心的主機。ok,我們把apache、mysql、qmail和ntp先加上,這回我們把監控的主機和服務新建一個文件:cd/usr/local/nagios/etc/touch10_5_1_156.cfgvinagios.cfgcfg_file=/usr/local/nagios/etc/10_5_1_156.cfgvi10_5_1_156.cfg定義一個主機:definehost{use generic-host ;Nameofhosttemplatetousehost_nametest_nrpealias clientaddress56check_commandcheck-host-alivemax_check_attempts1check_period24x7notification_interval120notification_period24x7notification_optionsd,rcontact_groupsadmins}定義主機需要檢查的服務:defineservice{use generic-service ;Nameofservicetemplatetousehost_name test_nrpeservice_descriptionPINGTOC\o"1-5"\h\zis_volatile 0check_period 24x7max_check_attempts1normal_check_interval1retry_check_interval 1contact_groups adminsnotification_options w,u,c,rnotification_interval960notification_periodcheck_command}notification_periodcheck_command}check_ping!100.0,20%!500.0,60%defineservice{
usegeneric-service;Nameofservicetemplatetousehost_name test_nrpeservice_descriptionapacheis_volatile 0check_period24x7max_check_attempts1normal_check_interval1retry_check_interval1contact_groupsadminsnotification_optionsw,u,c,rnotification_interval960notification_periodcheck_commandnotification_periodcheck_command}check_http!100.0,20%!500.0,60%defineservice{usegeneric-service;Nameofservicetemplatetousehost_name test_nrpeservice_descriptionmysqlis_volatile 0check_period24x7max_check_attempts1normal_check_interval1retry_check_interval1contact_groupsadminsnotification_optionsw,u,c,rnotification_interval960notification_periodcheck_commandnotification_periodcheck_command}check_mysql!100.0,20%!500.0,60%defineservice{usegeneric-service ;Nameofservicetemplatetousehost_name test_nrpeservice_descriptionntpis_volatile 0check_period24x7max_check_attempts1normal_check_interval1retry_check_interval1contact_groupsadminsnotification_optionsw,u,c,rnotification_interval960notification_period24x7
check_commandcheck_ntp!100.0,20%!500.0,60%}defineservice{usegeneric-service ;Nameofservicetemplatetousehost_name test_nrpeservice_descriptionqmail_smtpis_volatile 0check_period24x7max_check_attempts1normal_check_interval1retry_check_interval1contact_groupsadminsnotification_optionsw,u,c,rnotification_interval960notification_periodcheck_commandnotification_periodcheck_command}check_smtp!100.0,20%!500.0,60%defineservice{usegeneric-service ;Nameofservicetemplatetousehost_name test_nrpeservice_descriptionqmail_pop3is_volatile 0check_period24x7max_check_attempts1normal_check_interval1retry_check_interval1contact_groupsadminsnotification_optionsw,u,c,rnotification_interval960notification_periodcheck_commandnotification_periodcheck_commandcheck_pop!100.0,20%!500.0,60%}現在我們象上次一樣把服務也定義完了
}現在我們象上次一樣把服務也定義完了new_host_serviceliu1084回復于:2006-08-1418:29:02此時是不是多了一個主機和它下面的服務呢?那是肯定的,添加主機和服務可能出現的問題有如下情況:1:配置參數出現問題,如果你沒有檢查配置就啟動nagios,可能會啟動成功,但是顯示會不正常;解決方法:調整配置參數2:Connectionrefused當出現這個問題的時候,我開始以為是ssh的無密碼登錄沒有成功,但是其實我的服務器沒有啟動該服務造成的,啟動服務即可。但是這些是有端口的服務,沒有使用端口的狀態任何檢測?使用nrpe,ok,我們現在在服務器上安裝nrpe:一、遠程主機的配置1、安裝nrpe與配置fetch/sourceforge/nagios/nrpe-2.5.2.tar.gztarzxvfnrpe-2.5.2.tar.gzcdnrpe-2.5.2./configure--enable-ssl--enable-command-argsmakeallmkdir-p/usr/local/nagios/etcmkdir/usr/local/nagios/binmkdir/usr/local/nagios/libexecpwaddgroupnagiospwuseraddnagios-gnagios-d/usr/local/nagios/-s/sbin/nologinchown-Rnagios:nagios/usr/local/nagioscp./sample-config/nrpe.cfg/usr/local/nagios/etccpsrc/nrpe/usr/local/nagios/bin2、啟動nrpe,端口為5666/usr/local/nagios/bin/nrpe-c/usr/local/nagios/etc/nrpe.cfg-dnetstat-ant|grep5666tcp400*.5666 *.*LISTEN二、監控服務器上的配置1、 安裝nrpe(主要是使用check_nrpe模塊)fetch/sourceforge/nagios/nrpe-2.5.2.tar.gztarzxvfnrpe-2.5.2.tar.gzcdnrpe-2.5.2./configure--enable-ssl--enable-command-argsmakeallcpsrc/check_nrpe/usr/local/nagios/libexec2、 nagios文件的配置vicheckcommands.cfg定義check_nrpe命令#'check_nrep'commanddefinitiondefinecommand{command_namecheck_nrpecommand_line/usr/local/nagios/libexec/check_nrpe-H$HOSTADDRESS$-c$ARG1$}三、上面我們已經配置了一部分參數,下面是配置的最終結果:definehost{use generic-host ;Nameofhosttemplatetousehost_nametest_nrpealias clientaddress56check_commandcheck-host-alivemax_check_attempts1check_period24x7
notification_interval120notification_period24x7notification_optionsd,rcontact_groupsadmins}#'check_load'commanddefinitiondefinecommand{command_namecheck_loadcommand_line$USER1$/check_load-w$ARG1$-c$ARG2$}#'check_load'commanddefinitiondefinecommand{command_namecheck_diskcommand_line$USER1$/check_disk-w$ARG1$-c$ARG2$}defineservice{usegeneric-service ;Nameofservicetemplatetousehost_name test_nrpeservice_descriptionPINGis_volatile 0check_period24x7max_check_attempts1normal_check_interval1retry_check_interval1contact_groupsadminsnotification_optionsw,u,c,rnotification_interval960notification_periodcheck_commandnotification_periodcheck_command}check_ping!100.0,20%!500.0,60%defineservice{usegeneric-service ;Nameofservicetemplatetousehost_name test_nrpeservice_descriptionapacheis_volatile 0check_period24x7max_check_attempts1normal_check_interval1retry_check_interval1contact_groupsadminsnotification_optionsw,u,c,r
notification_intervalnotification_periodcheck_command96024x7check_http!100.0,20%!500.0,60%}defineservice{usegeneric-service;Nameofservicetemplatetousehost_name test_nrpeservice_descriptionmysqlis_volatile 0check_period24x7max_check_attempts1normal_check_interval1retry_check_interval1contact_groupsadminsnotification_optionsw,u,c,rnotification_interval960notification_periodcheck_commandnotification_periodcheck_command}check_mysql!100.0,20%!500.0,60%defineservice{usegeneric-service;Nameofservicetemplatetousehost_name test_nrpeservice_descriptionntpis_volatile 0check_period24x7max_check_attempts1normal_check_interval1retry_check_interval1contact_groupsadminsnotification_optionsw,u,c,rnotification_interval960notification_periodcheck_commandnotification_periodcheck_command}check_ntp!100.0,20%!500.0,60%defin
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年中秋節慰問活動方案
- 2025年銷售工作總結和工作方案演講稿
- 贈與協議(附贍養義務)
- 內蒙古通遼歷年中考作文題與審題指導(2008-2024)
- 2025年玻璃門保鮮柜項目可行性研究報告
- 2025年燃油切斷裝置項目可行性研究報告
- 湖南省郴州市第五完全中學2024-2025學年初三第二次調研考試(物理試題文)試卷含解析
- 云南省玉溪市紅塔區2024-2025學年初三下第一次測試化學試題含解析
- 湖南師范大學樹達學院《品牌規劃與設計》2023-2024學年第二學期期末試卷
- 沈陽工業大學工程學院《生物醫學圖像處理》2023-2024學年第二學期期末試卷
- 人教鄂教版科學五年級下冊第一單元 晝夜與四季單元教學教案
- 山東省煙臺市芝罘區(五四制)2022-2023學年七年級下學期期中考試英語試題及答案
- 2024年福建泉州交發集團招聘考試真題
- 深度學習入門試題及答案概述
- 統編版語文五年級下冊習作《形形色色的人》精美課件
- 骨科關節鏡手術器械行業深度調研及發展戰略咨詢報告
- 2024年廣西職業院校技能大賽高職組《智能飛行器應用技術》賽項樣題第2套
- 2025年北森人才測評試題及答案2023
- 10.1二元一次方程組的概念教學設計+++-2024-2025學年人教版數學七年級下冊
- 四年級希望杯歷年數學競賽試題與答案1-13屆+奧數分類專項練習集等
- 愛嬰醫院母乳喂養知識培訓
評論
0/150
提交評論