如何使用SNMP来监控Linux服务器.docx
《如何使用SNMP来监控Linux服务器.docx》由会员分享,可在线阅读,更多相关《如何使用SNMP来监控Linux服务器.docx(35页珍藏版)》请在冰豆网上搜索。
如何使用SNMP来监控Linux服务器
如何使用SNPM来监控Linux服务器
作者:
icefired(*********************)
2005-9-16
[Keywords]SNMP,Linux,OrionNPM,MRTG,Net-SNMP
[Objects]UsingSNMPtomonitoraLinuxserver
[准备]
1.Net-SNMP5.1.2或UCD-SNMP4.2.3
下载:
-snmp.org/download.html
2.ALinuxServer:
RedhatLinux7/8/9,RHEL3/4或其他Linux发行版。
3.SNMPTool:
SolarwindstoolsetV8.2或OrionNetworkPerformanceMonitorV7.8,其他支持SNMP监控的工具如HPOpenView,IBMNetView,SNMPCV7均可以。
[步骤]
1.安装Net-SNMP或UCD-SNMP.(三种方法)
1.1安装Linux系统时自动安装
安装Linux系统的时候选择UCD-SNMP和SNMP-Utility两个安装包就可以了。
1.2使用RPM包来安装,这里以Redhat9为例来说明。
先检查有无安装旧的版本:
rpm–qucd-snmp
全新安装:
#rpm–ivhnet-snmp-5.1.2-1.rh9.i386.rpm
#rpm–ivhnet-snmp-devel-5.1.2-1.rh9.i386.rpm
1.3使用原代码来安装
#wget
#tar–xzvfnet-snmp-5.1.3.1.tar.gz
#cdnet-snmp-5.1.3.1
#./configure
#make&makeinstall
如果没什么问题则顺利完成安装,Linux的安装和命令使用不在本文讨论范围,请大家查询相关手册。
2.配置SNMP
2.1设置SNMPD服务自动启动
#setup然后勾选上services->snmpd
启动snmpd进程
#servicesnmpdstart
2.2检查一下snmpd进程是否运行正常
#ps–ef|grepsnmpd
2.3配置/etc/snmp/snmpd.conf
好了,按照前面的步骤我们已经顺利的安装好SNMP服务了,如果使用默认的snmpd.conf文件,我们将只能够看到系统信息,而不能对系统资源进行监测。
下面是一份net-snmp自带的snmpd.conf文件:
##################---Begin---################################
####################
#snmpd.conf:
#Anexampleconfigurationfileforconfiguringtheucd-snmpsnmpdagent.
#
#########################################################
#
#Thisfileisintendedtoonlybeasastartingpoint.Manymore
#configurationdirectivesexistthanarementionedinthisfile.For
#fulldetails,seethesnmpd.conf(5)manualpage.
#
#Alllinesbeginningwitha'#'arecommentsandareintendedforyou
#toread.Allotherlinesareconfigurationcommandsfortheagent.
##########################################################AccessControl
#########################################################
#Asshipped,thesnmpddemonwillonlyrespondtoqueriesonthe
#systemmibgroupuntilthisfileisreplacedormodifiedfor
#securitypurposes.Examplesareshownbelowabouthowtoincreasethe
#levelofaccess.
#Byfar,themostcommonquestionIgetabouttheagentis"whywon't
#itwork?
",whenreallyitshouldbe"howdoIconfiguretheagentto
#allowmetoaccessit?
"
#
#Bydefault,theagentrespondstothe"public"communityforread
#onlyaccess,ifrunoutoftheboxwithoutanyconfigurationfilein
#place.Thefollowingexamplesshowyouotherwaysofconfiguring
#theagentsothatyoucanchangethecommunitynames,andgive
#yourselfwriteaccesstothemibtreeaswell.
#
#Formoreinformation,readtheFAQaswellasthesnmpd.conf(5)
#manualpage.
####
#First,mapthecommunityname"public"intoa"securityname"
#sec.namesourcecommunity
com2secnotConfigUserdefaultpublic
####
#Second,mapthesecuritynameintoagroupname:
#groupNamesecurityModelsecurityName
groupnotConfigGroupv1notConfigUser
groupnotConfigGroupv2cnotConfigUser
####
#Third,createaviewforustoletthegrouphaverightsto:
#Makeatleastsnmpwalk-v1localhost-cpublicsystemfastagain.
#nameincl/exclsubtreemask(optional)
viewsystemviewincluded.1.3.6.1.2.1.1
viewsystemviewincluded.1.3.6.1.2.1.25.1.1
####
#Finally,grantthegroupread-onlyaccesstothesystemviewview.
#groupcontextsec.modelsec.levelprefixreadwritenotif
accessnotConfigGroup""anynoauthexactsystemviewnonenone
#-----------------------------------------------------------------------------
#Hereisacommentedoutexampleconfigurationthatallowsless
#restrictiveaccess.
#YOUSHOULDCHANGETHE"COMMUNITY"TOKENBELOWTOANEWKEYWORDONLY
#KNOWNATYOURSITE.YOU*MUST*CHANGETHENETWORKTOKENBELOWTO
#SOMETHINGREFLECTINGYOURLOCALNETWORKADDRESSSPACE.
##sec.namesourcecommunity
#com2seclocallocalhostCOMMUNITY
#com2secmynetworkNETWORK/24COMMUNITY
##group.namesec.modelsec.name
#groupMyRWGroupanylocal
#groupMyROGroupanymynetwork
#
#groupMyRWGroupanyotherv3user
#...
##incl/exclsubtreemask
#viewallincluded.180
##-orjustthemib2tree-
#viewmib2included.iso.org.dod.internet.mgmt.mib-2fc
##contextsec.modelsec.levelprefixreadwritenotif
#accessMyROGroup""anynoauth0allnonenone
#accessMyRWGroup""anynoauth0allallall
##########################################################Systemcontactinformation
#
#ItisalsopossibletosetthesysContactandsysLocationsystem
#variablesthroughthesnmpd.conffile:
syslocationUnknown(edit/etc/snmp/snmpd.conf)
syscontactRoot(configure/etc/snmp/snmp.local.conf)
#Exampleoutputofsnmpwalk:
#%snmpwalk-v1localhost-cpublicsystem
#system.sysDescr.0="SunOSnamesun4c"
#system.sysObjectID.0=OID:
enterprises.ucdavis.ucdSnmpAgent.sunos4
#system.sysUpTime.0=Timeticks:
(595637548)68days,22:
32:
55
#system.sysContact.0="Me<****************>"
#system.sysName.0="name"
#system.sysLocation.0="Righthere,rightnow."
#system.sysServices.0=72
#-----------------------------------------------------------------------------
#########################################################
#Processchecks.
#
#Thefollowingareexamplesofhowtousetheagenttocheckfor
#processesrunningonthehost.Thesyntaxlookssomethinglike:
#
#procNAME[MAX=0][MIN=0]
#
#NAME:
thenameoftheprocesstocheckfor.Itmustmatch
#exactly(ie,httpwillnotfindhttpdprocesses).
#MAX:
themaximumnumberallowedtoberunning.Defaultsto0.
#MIN:
theminimumnumbertoberunning.Defaultsto0.
#
#Examples(commentedoutbydefault):
#
#Makesuremountdisrunning
#procmountd
#Makesuretherearenomorethan4ntalkdsrunning,but0isoktoo.
#procntalkd4
#Makesureatleastonesendmail,butlessthanorequalto10arerunning.
#procsendmail101
#Asnmpwalkoftheprocessmibtreewouldlooksomethinglikethis:
#
#%snmpwalk-v1localhost-cpublic.1.3.6.1.4.1.2021.2
#enterprises.ucdavis.procTable.prEntry.prIndex.1=1
#enterprises.ucdavis.procTable.prEntry.prIndex.2=2
#enterprises.ucdavis.procTable.prEntry.prIndex.3=3
#enterprises.ucdavis.procTable.prEntry.prNames.1="mountd"
#enterprises.ucdavis.procTable.prEntry.prNames.2="ntalkd"
#enterprises.ucdavis.procTable.prEntry.prNames.3="sendmail"
#enterprises.ucdavis.procTable.prEntry.prMin.1=0
#enterprises.ucdavis.procTable.prEntry.prMin.2=0
#enterprises.ucdavis.procTable.prEntry.prMin.3=1
#enterprises.ucdavis.procTable.prEntry.prMax.1=0
#enterprises.ucdavis.procTable.prEntry.prMax.2=4
#enterprises.ucdavis.procTable.prEntry.prMax.3=10
#enterprises.ucdavis.procTable.prEntry.prCount.1=0
#enterprises.ucdavis.procTable.prEntry.prCount.2=0
#enterprises.ucdavis.procTable.prEntry.prCount.3=1
#enterprises.ucdavis.procTable.prEntry.prErrorFlag.1=1
#enterprises.ucdavis.procTable.prEntry.prErrorFlag.2=0
#enterprises.ucdavis.procTable.prEntry.prErrorFlag.3=0
#enterprises.ucdavis.procTable.prEntry.prErrMessage.1="Nomountdprocessrunning."
#enterprises.ucdavis.procTable.prEntry.prErrMessage.2=""
#enterprises.ucdavis.procTable.prEntry.prErrMessage.3=""
#enterprises.ucdavis.procTable.prEntry.prErrFix.1=0
#enterprises.ucdavis.procTable.prEntry.prErrFix.2=0
#enterprises.ucdavis.procTable.prEntry.prErrFix.3=0
#
#NotethattheerrorFlagformountdissetto1becauseoneisnot
#running(inthiscaseanrpc.mountdis,butthatsnotgoodenough),
#andtheErrMessagetellsyouwhat'swrong.Theconfiguration
#imposedinthesnmpd.conffileisalsoshown.
#
#SpecialCase:
Whentheminandmaxnumbersareboth0,itassumes
#youwantamaxofinfinityandaminof1.
#
#-----------------------------------------------------------------------------
##########################################################Executables/scripts
#
#
#Youcanalsohaveprogramsrunbytheagentthatreturnasingle
#lineofoutputandanexitcode.Herearetwoexamples.
#
#execNAMEPROGRAM[ARGS...]
#
#NAME:
Agenericname.
#PROGRAM:
Theprogramtorun.Includethepath!
#ARGS:
optionalargumentstobepassedtotheprogram
#asimplehelloworld
#execechotest/bin/echohelloworld
#Runashellscriptcontaining:
#
##!
/bin/sh
#echohelloworld
#echohithere
#exit35
#
#Note:
thishasbeenspecificallycommentedouttoprevent
#accidentalsecurityholesduetosomeoneelseonyoursystemwriting
#a/tmp/shtestbeforeyoudo.Uncommenttouseit.
#
#execshelltest/bin/sh/tmp/shtest
#Then,
#%snmpwalk-v1localhost-cpublic.1.3.6.1.4.1.2021.8
#enterprises.ucdavis.extTable.extEntry.extIndex.1=1
#enterprises.ucdavis.extTable.extEntry.extIndex.2=2
#enterprises.ucdavis.extTable.extEntry.extNames.1="echotest"
#enterprises.ucdavis.extTable.extEntry.extNames.2="shelltest"
#enterprises.ucdavis.extTable.extEntry.extCommand.1="/bin/echohelloworld"
#enterprises.ucdavis.extTable.extEntry.extCommand.2="/bin/sh/tmp/shtest"
#enterprises.ucdavis.extTable.extEntry.extResult.1=0
#enterprises.ucdavis.extTable.extEntry.extResult.2=35
#enterprises.ucdavis.extTable.extEntry.extOutput.1="helloworld."
#enterprises.ucdavis.extTable.extEntry.extOutput.2="helloworld."
#enterprises.ucdavis.extTable.extEntry.extErrFix.1=0
#enterprises.ucdavis.extTable.extEntry.extErrFix.2=0
#Notethatthesecondlineofthe/tmp/shtestshellscriptiscut
#off.Alsonotethattheexitstatusof35wasreturned.
#-----------------------------------------------------------------------------
##########################################################diskchecks
#
#Theagentcanchecktheamountofavailablediskspace,andmake