ºìÁªLinuxÃÅ»§
Linux°ïÖú

ÄãÐèÒªÖªµÀµÄ 16 ¸ö Linux ·þÎñÆ÷¼à¿ØÃüÁî

·¢²¼Ê±¼ä:2012-03-25 09:48:16À´Ô´:ºìÁª×÷Õß:894046126
Èç¹ûÄãÏëÖªµÀÄãµÄ·þÎñÆ÷ÕýÔÚ×ö¸Éʲô£¬Äã¾ÍÐèÒªÁ˽âһЩ»ù±¾µÄÃüÁһµ©Ä㾫ͨÁËÕâЩÃüÁÄÇÄã¾ÍÊÇÒ»¸ö רҵµÄ Linux ϵͳ¹ÜÀíÔ±¡£

ÓÐЩ Linux ·¢Ðаæ»áÌṩ GUI ³ÌÐòÀ´½øÐÐϵͳµÄ¼à¿Ø£¬ÀýÈç SUSE Linux ¾ÍÓÐÒ»¸ö·Ç³£°ô¶øÇÒרҵµÄ¹¤¾ß YaST£¬KDE µÄ KDE System Guard ͬÑùºÜ³öÉ«¡£µ±È»£¬ÒªÊ¹ÓÃÕâЩ¹¤¾ß£¬Äã±ØÐëÔÚ·þÎñÆ÷¸úÇ°½øÐвÙ×÷£¬¶øÇÒÕâЩ GUI µÄ³ÌÐòÕ¼ÓÃÁ˺ܶàϵͳ×ÊÔ´£¬ËùÒÔ˵£¬¾¡¹Ü GUI ÓÃÀ´×ö»ù±¾µÄ·þÎñÆ÷½¡¿µ×´Ì¬¼à²âͦºÃ£¬µ«Èç¹ûÄãÏëÖªµÀÕæÕý·¢Éúʲô£¬Çë¹Øµô GUI ¿ªÊ¼ÃüÁîÐÐÖ®Âðɡ£

ÄãÓ¦¸ÃÖ»ÔÚÐèÒªµÄʱºòÈ¥Æô¶¯ GUI £¬²»ÓõÄʱºò¹ØµôËü¡£Èç¹ûÒªÈ÷þÎñÆ÷±£³Ö×î¼ÑÐÔÄÜ£¬ÄãÓ¦¸Ã½« Linux ·þÎñÆ÷µÄÔËÐ춱ð runlevel ÉèÖÃΪ 3 £¬¾ÍÊÇ¿ØÖÆ̨ģʽ£¬µ±ÄãÐèҪͼÐλ¯×ÀÃæµÄʱºòʹÓà startx ÃüÁîÀ´Æô¶¯Ëü¡£

Èç¹ûÄãµÄ·þÎñÆ÷Æô¶¯ºó¾ÍÖ±½Ó½øÈëͼÐνçÃ棬ÄãÐèÒªÐÞ¸ÄÅäÖà /etc/inittab ÕÒµ½ initdefault Ò»Ñù£¬½« id:5:initdefault ÐÞ¸ÄΪ id:3:initdefault¡£

Èç¹ûÄãûÕÒµ½ /etc/inittab Îļþ£¬ÄǾʹ´½¨Ò»¸öеģ¬ÎļþÄÚÈÝÔö¼Ó id:3 ÕâôһÐС£ÕâÑùÏ´ηþÎñÆ÷Æô¶¯µÄʱºò¾Í²»»á½øÈëͼÐνçÃæ¡£Èç¹ûÄã²»ÏëµÈµ½·þÎñÆ÷ÖØÆôµÄʱºò²ÅÉúЧ£¬Äã¿ÉÒÔÖ´ÐÐ init 3 Õâ¸öÃüÁî¡£

Ò»µ©ÄãµÄ·þÎñÆ÷ÊÇÔÚ¿ØÖÆ̨ģʽÏÂÔËÐУ¬Äã¾Í¿ÉÒÔ¿ªÊ¼ÎÒÃǽÓÏÂÀ´µÄÄÚÈÝ¡£
iostat

iostat ÃüÁîÓÃÀ´ÏÔʾ´æ´¢×ÓϵͳµÄÏêϸÐÅÏ¢£¬Í¨³£ÓÃËüÀ´¼à¿Ø´ÅÅÌ I/O µÄÇé¿ö¡£ÒªÌرð×¢Òâ iostat ͳ¼Æ½á¹ûÖÐµÄ %iowait Öµ£¬Ì«´óÁ˱íÃ÷ÄãµÄϵͳ´æ´¢×ÓϵͳÐÔÄܵÍÏ¡£
meminfo ºÍ free

Meminfo ¿ÉÈÃÄã»ñÈ¡ÄÚ´æµÄÏêϸÐÅÏ¢£¬Äã¿ÉÒÔʹÓà cat ºÍ grep ÃüÁîÀ´ÏÔʾ meminfo ÐÅÏ¢£º
1 cat /proc/meminfo

ÁíÍâÄã¿ÉÒÔʹÓà free ÃüÁîÀ´ÏÔʾ¶¯Ì¬µÄÄÚ´æʹÓÃÐÅÏ¢£¬free Ö»ÊǸøÄã´ó¸ÅµÄÄÚ´æÐÅÏ¢£¬¶ø meminfo ÌṩµÄÐÅÏ¢¸ü¼ÓÏêϸ¡£

mpstat

mpstat mpstatÊÇMultiProcessor StatisticsµÄËõд£¬ÊÇʵʱϵͳ¼à¿Ø¹¤¾ß¡£Æ䱨¸æÓëCPUµÄһЩͳ¼ÆÐÅÏ¢£¬ÕâЩÐÅÏ¢´æ·ÅÔÚ/proc/statÎļþÖС£ÔÚ¶àCPUsϵͳÀÆä²»µ«Äܲ鿴ËùÓÐCPUµÄƽ¾ù×´¿öÐÅÏ¢£¬¶øÇÒÄܹ»²é¿´Ìض¨CPUµÄÐÅÏ¢¡£

¹ØÓÚ mpstat Ö´Ðнá¹ûÖеIJÎÊýÒâ˼Çë²Î¿¼´ËÌù¡£
netstat

Netstat ºÍ ps ÃüÁîÀàËÆ£¬ÊÇ Linux ¹ÜÀíÔ±»ù±¾ÉÏÿÌ춼»áÓõŤ¾ß£¬ËüÏÔʾÁË´óÁ¿¸úÍøÂçÏà¹ØµÄÐÅÏ¢£¬ÀýÈç socket µÄʹÓá¢Â·ÓÉ¡¢½Ó¿Ú¡¢Ð­Òé¡¢ÍøÂçµÈµÈ£¬ÏÂÃæÊÇһЩ³£ÓõIJÎÊý£º
1 -a Show all socket information
2 -r Show routing information
3 -i Show network interface statistics
4 -s Show network protocol statistics

nmon

Nmon, ÊÇ Nigel's Monitor µÄËõд£¬ÊÇÒ»¸öʹÓúÜÆÕ±éµÄ¿ªÔ´¹¤¾ß£¬ÓÃÒÔ¼à¿Ø Linux ϵͳµÄÐÔÄÜ¡£Nmon ¼à¿Ø¶à¸ö×ÓϵͳµÄÐÔÄÜÊý¾Ý£¬ÀýÈç´¦ÀíÆ÷µÄʹÓÃÂÊ¡¢ÄÚ´æʹÓÃÂÊ¡¢¶ÓÁС¢´ÅÅÌI/Oͳ¼Æ¡¢ÍøÂçI/Oͳ¼Æ¡¢ÄÚ´æÒ³´¦ÀíºÍ½ø³ÌÐÅÏ¢¡£Nmon Ò²ÌṩÁËÒ»¸öͼÐλ¯µÄ¹¤¾ß£º

sjvn_LinuxServerMonitoring_nmon.png

ÒªÔËÐÐ nmon£¬Äã¿ÉÒÔÔÚÃüÁîÐÐÖÐÆô¶¯Ëü£¬È»ºóÑ¡ÔñÒª¼à¿ØµÄ×Óϵͳ£¬ÕâЩ×Óϵͳ¶¼¶ÔÓ¦ÓÐÒ»¸ö¿ì½Ý¼ü£¬ÀýÈçÊäÈë c ¿É²é¿´ CPU ÐÅÏ¢£¬mÓÃÓڲ鿴Äڴ棬dÓÃÀ´²é¿´´ÅÅÌÐÅÏ¢µÈ£¬ÄãÒ²¿ÉÒÔʹÓà -f ÃüÁ nmon µÄÖ´Ðнá¹û±£´æµ½Ò»¸ö CSV ÎļþÖУ¬±ãÓÚÈÕºó·ÖÎö¡£

ÔÚÿÈյļà¿Ø¹¤×÷ÖУ¬ÎÒ·¢ÏÖ nmon ÊÇÎÒ×î³£ÓõŤ¾ß¡£
pmap

pmap ÃüÁîÓÃÀ´±¨¸æÿ¸ö½ø³ÌÕ¼ÓÃÄÚ´æµÄÏêϸÇé¿ö£¬¿ÉÓÃÀ´¿´ÊÇ·ñÓнø³Ì³¬Ö§ÁË£¬¸ÃÃüÁîÐèÒª½ø³Ì id ×÷Ϊ²ÎÊý¡£
ps ºÍ pstree

ps ºÍ pstree ÃüÁîÊÇ Linux ϵͳ¹ÜÀíÔ±×îºÃµÄÅóÓÑ£¬¶¼¿ÉÒÔÓÃÀ´ÁбíÕýÔÚÔËÐеÄËùÓнø³Ì¡£ps ¸æËßÄãÿ¸ö½ø³ÌÕ¼ÓõÄÄÚ´æºÍ CPU ´¦Àíʱ¼ä£¬¶ø pstree ÏÔʾµÄÐÅϢûÄÇôÏêϸ£¬µ«ËüÒÔÊ÷ÐνṹÏÔʾ½ø³ÌÖ®¼äµÄÒÀÀµ¹Øϵ£¬°üÀ¨×Ó½ø³ÌÐÅÏ¢¡£Ò»µ©·¢ÏÖij¸ö½ø³ÌÓÐÎÊÌ⣬Äã¿ÉÒÔʹÓà kill À´É±µôËü¡£
sar

sar ³ÌÐòÊÇϵͳ¼à¿Ø¹¤¾ßÀïµÄÈðÊ¿¾üµ¶¡£¸Ã³ÌÐò°üº¬Èý¸ö¹¤¾ß£ºsar ÓÃÀ´ÏÔʾÊý¾Ý£¬sa1 ºÍ sa2 ÓÃÀ´ÊÕ¼¯Êý¾Ý²¢±£´æ¡£sar ¿ÉÓÃÀ´ÏÔʾ CPU ʹÓÃÂÊ¡¢ÄÚ´æÒ³Êý¾Ý¡¢ÍøÂç I/O ºÍ´«Êäͳ¼Æ¡¢½ø³Ì´´½¨»î¶¯ºÍ´ÅÅÌÉ豸µÄ»î¶¯ÏêÇé¡£sar ºÍ nmon ×î´óµÄ²»Í¬¾ÍÊÇ sar ¸úÊʺÏÓÃ×÷³¤Æڵļà¿Ø£¬¶ø nmon ¿ÉÒÔÈÃÄã¿ìËÙµÄÁ˽âϵͳµ±Ç°×´Ì¬¡£
strace

strace ¾­³£±»ÈÏΪÊdzÌÐòÔ±µ÷ÊԵŤ¾ß£¬µ«²»Ö¹Èç´Ë¡£Ëü¿ÉÒԼǼ½ø³Ì½øÐÐϵͳµ÷ÓõÄÏêÇ飬Òò´ËËüÒ²ÊÇÒ»¸ö·Ç³£ºÃµÄÕï¶Ï¹¤¾ß£¬ÀýÈçÄã¿ÉÒÔʹÓÃËüÀ´ÕÒ³öij¸ö³ÌÐòÕýÔÚ´ò¿ªÄ³¸öÅäÖÃÎļþ¡£

Strace Ò²ÓÐÒ»¸öȱÏÝ£¬µ«ËüÔÚ¸ú×Ùij¸ö½ø³Ìʱ»áÈøýø³ÌµÄÐÔÄܱäµÃ·Ç³£²î£¬Òò´ËÇë½÷É÷ʹÓá£
tcpdump

Tcpdump ÊÇÒ»¸ö¼òµ¥¡¢¿É¿¿µÄÍøÂç¼à¿Ø¹¤¾ß£¬ÓÃÀ´×ö»ù±¾µÄЭÒé·ÖÎö£¬¿´¿´ÄÇЩ½ø³ÌÔÚʹÓÃÍøÂçÒÔ¼°ÈçºÎʹÓÃÍøÂç¡£µ±È»£¬Èç¹ûÄãÒª»ñÈ¡¸úÏêϸµÄÐÅÏ¢£¬ÄãÓ¦¸ÃʹÓà Wireshark (ÏÂÃæÎÒÃÇ»á½éÉÜ).
top

top ÃüÁîÏÔʾµ±Ç°µÄ»î¶¯½ø³Ì£¬Ä¬ÈÏËüÊÇ°´ÏûºÄ CPU µÄÀ÷º¦³Ì¶È½øÐÐÅÅÐò£¬Ã¿5ÃëÖÓË¢ÐÂÒ»´ÎÁÐ±í£¬ÄãÒ²¿ÉÒÔÑ¡Ôñ²»Í¬µÄÅÅÐò·½Ê½£¬ÀýÈç m ÊÇ°´ÄÚ´æÕ¼Ó÷½Ê½½øÐÐÅÅÐòµÄ¿ì½Ý¼ü¡£
uptime

uptime ÃüÁî¸æËßÄãÕą̂·þÎñÆ÷´Ó¿ª»úÆô¶¯µ½ÏÖÔÚÒѾ­ÔËÐÐÁ˶೤ʱ¼äÁË¡£Í¬Ê±Ò²°üº¬ÁË´ÓÆô¶¯µ½ÏÖÔÚ·þÎñÆ÷µÄƽ¾ù¸ºÔØÇé¿ö.

vmstat

Äã¿ÉÒÔʹÓà vmstat À´¼à¿ØÐéÄâÄڴ棬һ°ã Linux ÉϵĿª·¢Õßϲ»¶Ê¹ÓÃÐéÄâÄÚ´æÀ´»ñµÃ×î¼ÑµÄ´æ´¢ÐÔÄÜ¡£¸ÃÃüÁ¸æ¹ØÓÚÄÚºËÏ̡߳¢ÐéÄâÄÚ´æ¡¢´ÅÅÌ¡¢ÏÝÚåºÍ CPU »î¶¯µÄͳ¼ÆÐÅÏ¢¡£ÓÉ vmstat ÃüÁîÉú³ÉµÄ±¨¸æ¿ÉÒÔÓÃÓÚƽºâϵͳ¸ºÔػ¡£ÏµÍ³·¶Î§ÄÚµÄÕâЩͳ¼ÆÐÅÏ¢£¨ËùÓеĴ¦ÀíÆ÷ÖУ©¶¼¼ÆËã³öÒ԰ٷֱȱíʾµÄƽ¾ùÖµ£¬»òÕß¼ÆËãÆä×ܺ͡£

Wireshark

Wireshark, Ç°ÉíÊÇ Ethereal £¬ÊÇÒ»¸öÍøÂçЭÒé¼ì²â³ÌÐò£¬ÈÃÄú¾­ÓɳÌÐòץȡÔËÐеÄÍøÕ¾µÄÏà¹Ø×ÊѶ£¬°üÀ¨Ã¿Ò»·â°üÁ÷Ïò¼°ÆäÄÚÈÝ¡¢×ÊѶ¿ÉÒÀ²Ù×÷ϵͳÓïϵ¿´³ö,·½±ã²é¿´¡¢¼à¿ØTCP session¶¯Ì¬µÈµÈ.

ÕâÀïÂÞÁеÄÊÇ´ó¶àÊý×îÓмÛÖµµÄ Linux ¼à¿Ø³ÌÐò£¬µ±È»£¬Äã¿ÉÄÜ»¹»áʹÓÃÆäËûµÄ¹¤¾ß£¬²»·Á¸ú´ó¼Ò·ÖÏíÏ¡£

Ó¢ÎÄÔ­ÎÄ hp.com OSCHINA Ô­´´·­Òë
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 1 ÌõÆÀÂÛ

  1. laoshue ÓÚ 2012-03-25 11:15:14·¢±í:

    È«¶¼Ñ§ÏÂà¶~~