高级 Linux 命令精通指南管理linux环境4.docx
- 文档编号:29432545
- 上传时间:2023-07-23
- 格式:DOCX
- 页数:38
- 大小:41.17KB
高级 Linux 命令精通指南管理linux环境4.docx
《高级 Linux 命令精通指南管理linux环境4.docx》由会员分享,可在线阅读,更多相关《高级 Linux 命令精通指南管理linux环境4.docx(38页珍藏版)》请在冰豆网上搜索。
高级Linux命令精通指南管理linux环境4
GuidetoAdvancedLinuxCommandMastery,Part4:
ManagingtheLinuxEnvironment
byArupNanda
PublishedMay2009
Inthisinstallment,learnhowtomanagetheLinuxenvironmenteffectivelythroughthesecommonlyusedcommands.
ifconfig
Theifconfigcommandshowsthedetailsofthenetworkinterface(s)definedinthesystem.Themostcommonoptionis-a,whichshowsalltheinterfaces.
#ifconfig-a
TheusualnameoftheprimaryEthernetnetworkinterfaceiseth0.Tofindoutthedetailsofaspecificinterface,e.g.eth0,youcanuse:
#ifconfigeth0
Theoutputisshowbelow,withexplanation:
Herearesomekeypartsoftheoutput:
∙Linkencap:
thetypeofthehardwarephysicalmediumsupportedbythisinterface(Ethernet,inthiscase)
∙HWaddr:
theuniqueidentifieroftheNICcard.EveryNICcardhasauniqueidentifierassignedbythemanufacturer,calledMACorMACaddress.TheIPaddressisattachedtotheMACtotheserver.IfthisIPaddressischanged,orthiscardismovedfromthisservertoadifferentone,theMACdoesnotchange.
∙Mask:
thenetmask
∙inetaddr:
theIPaddressattachedtotheinterface
∙RXpackets:
thenumberofpacketsreceivedbythisinterface
∙TXpackets:
thenumberofpacketssent
∙errors:
thenumberoferrorsinsendingorreceiving
Thecommandisnotjustusedtocheckthesettings;it’susedtoconfigureandmanagetheinterfaceaswell.Hereisashortlistofparametersandoptionsforthiscommand:
up/down –enablesordisablesaspecificinterface.Youcanusethedownparametertoshutdownaninterface(ordisableit):
#ifconfigeth0down
Similarlytobringitup(orenable)it,youwoulduse:
#ifconfigeth0up
media –setsthetypeoftheEthernetmediasuchas10baseT,10Base2,etc.Commonvaluesforthemediaparameterare10base2,10baseT,andAUI.IfyouwantLinuxtosensethemediaautomatically,youcanspecify“auto”,asshownbelow:
#ifconfigeth0mediaauto
add –setsaspecificIPaddressfortheinterface.TosetanIPaddressof192.168.1.101totheinterfaceeth0,youwouldissue:
#ifconfigeth0add192.168.1.101
netmask –setsthenetmaskparameteroftheinterface.Hereisanexamplewhereyoucansetthenetmaskoftheeth0interfaceto255.255.255.0
#ifconfigeth0netmask255.255.255.0
InanOracleRealApplicationClustersenvironmentyouhavetosetthenetmaskinacertainway,usingthiscommand.
Insomeadvancedconfigurations,youcanchangetheMACaddressassignedtothenetworkinterface.Thehwparameteraccomplishesthat.Thegeneralformatis:
ifconfig
The
theMACaddressshownhereisfictional.IfitmatchesanyactualMAC,it’spurelycoincidental.):
#ifconfigeth0hwether12.34.56.78.90.12
Thisisusefulwhenyouaddanewcard(withanewMACaddress)butdonotwanttochangetheLinux-relatedconfigurationsuchasnetworkinterfaces.
UsagefortheOracleUser
Thecommand,alongwithnestatdescribedbelow,isoneofthemostwidelyusedinmanagingOracleRAC.OracleRAC’sperformancedependsheavilyontheinterconnectusedbetweenthenodesofthecluster.Iftheinterconnectissaturated(thatis,itnolongercarriesanyadditionaltraffic)orisfailing,youmayseereducedperformance.Thebestcourseofactioninthiscaseistolookattheifconfigoutputtoviewanyfailures.Hereisatypicalexample:
#ifconfigeth9
eth9Linkencap:
EthernetHWaddr00:
1C:
23:
CE:
6F:
82
inetaddr:
10.14.104.31Bcast:
10.14.104.255Mask:
255.255.255.0
inet6addr:
fe80:
:
21c:
23ff:
fece:
6f82/64Scope:
Link
UPBROADCASTRUNNINGMULTICASTMTU:
1500Metric:
1
RXpackets:
1204285416errors:
0
dropped:
560923
overruns:
0frame:
0
TXpackets:
587443664errors:
0
dropped:
623409
overruns:
0carrier:
0
collisions:
0txqueuelen:
1000
RXbytes:
1670104239570(1.5TiB)TXbytes:
42726010594(39.7GiB)
Interrupt:
169Memory:
f8000000-f8012100
Notethetexthighlightedinred.Thedroppedcountisextremelyhigh;thenumbershouldideallybe0orclosetoit.Ahighnumbermorethanhalfamillionsoundslikeafaultyinterconnectthatdropspackets,causingtheinterconnecttoresendpackets—whichshouldbeaclueintheissuediagnosis.
netstat
Thestatusoftheinputandoutputthroughanetworkinterfaceisassessedviathecommandnetstat.Thiscommandcanprovidethecompleteinformationonhowthenetworkinterfaceisperforming,downtoevensocketlevel.Hereisanexample:
#netstat
ActiveInternetconnections(w/oservers)
ProtoRecv-QSend-QLocalAddressForeignAddressState
tcp00prolin1:
31027prolin1:
5500TIME_WAIT
tcp40prolin1l:
1521applin1:
40205ESTABLISHED
tcp00prolin1l:
1522prolin1:
39957ESTABLISHED
tcp00prolin1l:
3938prolin1:
31017TIME_WAIT
tcp00prolin1l:
1521prolin1:
21545ESTABLISHED
…andsoon…
Theaboveoutputgoesontoshowalltheopensockets.Inverysimplisticterms,a socket isakintoa connection betweentwoprocesses.[Pleasenote:
strictlyspeaking,“sockets”and“connections”aretechnicallydifferent.Asocketcouldexistwithoutaconnection.However,adiscussiononsocketsandconnectionsisbeyondthescopeofthisarticle.ThereforeIhavemerelypresentedtheconceptinaneasy-to-understandmanner.]Naturally,aconnectionhastohaveasourceandadestination,called local and remoteaddress.Theendpointscouldbeonthesameserver;orondifferentservers.
Inmanycases,theprogramsconnecttothesameserver.Forinstance,iftwoprocessescommunicateamongeachother,thelocalandremoteaddresseswillbethesame,asyoucanseeinthefirstline–thelocalandremoteaddressesareboththesever“prolin1”.However,theprocessescommunicateovera port,whichwillbedifferent.Thisportisshownnexttothehostnameafterthe“:
”(colon)mark.Theuserprogramsendsthedatatobesentacrossthesockettoaqueueandthereceiverreadsfromaqueueattheremoteend.Herearethecolumnsoftheoutput:
1.Theleftmostcolumn“ Proto”showsthetypeoftheconnection–tcpinthiscase.
2.Thecolumn Recv-Q showsthebytesofdatainthequeuetobesenttotheuserprogramthatestablishedtheconnection.Thisvalueshouldbeascloseto0aspossible.Inbusyserversthisvaluewillbemorethan0butshouldn’tbeveryhigh.Ahighernumbermaynotmeanmuch,unlessyouseealargenumberin Send-Q column,describedbelow.
3.The Send-Q columndenotesthebytesinthequeuetobesenttotheremoteprogram,i.e.theremoteprogramhasnotyetacknowledgedreceivingit.Thisshouldbecloseto0.Alargenumbermayindicateanetworkbottleneck.
4.LocalAddress issourceoftheconnectionandtheportnumberoftheprogram.
5.ForeignAddress isthedestinationhostandportnumber.Inthefirstline,boththesourceanddestinationareonthesamehost:
prolin1.Theconnectionissimplywaiting.Thesecondlineshowsandestablishedconnectionbetweenport1521ofproiln1goingtotheport40205ofthehostapplin1.It’smostlikelyanOracleconnectioncomingfromtheclientapplin1tothedatabaseserverprolin1.TheOraclelisteneronprolin1runsonport1521;sotheportofthesourceis1521.Inthisconnection,theserverissendingtherequesteddatatotheclient.
6.Thecolumn State showsthestatusoftheconnection.Herearesomecommonvalues.
7.
oESTABLISHED –thattheconnectionhasbeenestablished.Itdoesnotmeanthatanydataisflowingbetweentheendpoints;merelythattheendpointshavetalkedtoeachother.
oCLOSED –theconnectionhasbeenclosed,i.e.notusednow.
oTIME_WAIT –theconnectionisbeingclosedbuttherearestillpacketsinthenetworkthatarebeinghandled.
oCLOSE_WAIT –theremoteendhasshutdownandhasaskedtoclosetheconnection.
Well,fromtheforeignandlocaladdresses,especiallyfromtheportnumbers,youcanprobablyguessthattheconnectionsareOraclerelated,butwon’titbenicetoknowthatforsure?
Ofcourse.The-poptionshowstheprocessinformationaswell:
#netstat-p
ProtoRecv-QSend-QLocalAddressForeignAddressStatePID/Programname
tcp00prolin1:
1521prolin1:
33303ESTABLISHED1327/oraclePROPRD1
tcp00prolin1:
1521applin1:
51324ESTABLISHED13827/oraclePROPRD1
tcp00prolin1:
1521prolin1:
33298ESTABLISHED32695/tnslsnr
tcp00prolin1:
1521prolin1:
32544ESTABLISHED15251/oracle+ASM
tcp00prolin1:
1521prolin1:
33331ESTABLISHED32695/tnslsnr
ThisclearlyshowstheprocessIPandtheprocessnameinthelastcolumn,whichconfirmsittobeOracleserverprocesses,listenerprocess,andASMserverprocesses.
Thenetstatcommandcanhavevariousoptionsandparameters.Herearesomekeyones:
Tofindoutthenetworkstatisticsforvariousinterfaces,usethe-ioption.
#netstat-i
KernelInterfacetable
IfaceMTUMetRX-OKRX-ERRRX-DRPRX-OVRTX-OKTX-ERRTX-DRPTX-OVRFlg
eth01500068606590002055833000BMRU
eth8150002345000833000BMRU
lo1643601444907900014449079000LRU
Thisshowsthedifferentinterfacespresentintheserver(eth0,eth8,etc.)andthemetricsassociatedwiththeinterface.
∙RX-OK showsthenumberofpacketssuccessfullysent(forthisinterface)
∙RX-ERR showsnumberoferrors
∙RX-DRP showspacketsdroppedandhadtobere-sent(eithersuccessfullyornot)
∙RX-OVR showspacketsoverrun
Thenextsetsofcolumns(TX-OK,TX-ERR,etc.)showthecorrespondingstatsforsenddata.
Flg columnisacompositevalueofthepropertyoftheinterface.Eachletterindicatesaspecificpropertybeingpresent.Hereisanexplanationoftheletters.
B–Broadcast
M–Multicast
R–Run
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 高级 Linux 命令精通指南管理linux环境4 命令 精通 指南 管理 环境
![提示](https://static.bdocx.com/images/bang_tan.gif)