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

Éî¶È½éÉÜLinuxÄÚºËÊÇÈçºÎ¹¤×÷µÄ

·¢²¼Ê±¼ä:2009-04-01 11:02:40À´Ô´:ºìÁª×÷Õß:LinuxSpace
±¾ÎÄ·¢±íÓÚLinux Format magazineÔÓÖ¾£¬×÷Õß´Ó¼¼ÊõÉî¶ÈÉϽâÊÍÁËLinux KernelÊÇÈçºÎ¹¤×÷µÄ¡£ÏàÐŶÔLinux¿ª·¢ÕßÀ´ËµÓв»Ð¡µÄ°ïÖú¡£

Å£½ò×ÖµäÖжÔ"kernel"Ò»´ÊµÄ¶¨ÒåÊÇ£º"½ÏÈíµÄ¡¢Í¨³£ÊÇÒ»¸ö¼á¹û¿ÉʳÓõIJ¿·Ö¡£"µ±È»»¹ÓеڶþÖÖ¶¨Ò壺"ij¸ö¶«Î÷ºËÐÄ»òÕß×îÖØÒªµÄ²¿·Ö¡£"¶ÔLinuxÀ´Ëµ£¬ËüµÄKernelÎÞÒÉÊôÓÚµÚ¶þÖÖ½âÊÍ¡£ÈÃÎÒÃÇÀ´¿´¿´Õâ¸öÖØÒªµÄ¶«Î÷ÊÇÈçºÎ¹¤×÷µÄ£¬ÏÈ´ÓÒ»µãÀíÂÛ˵Æð¡£

¹ãÒåµØÀ´Ëµkernel¾ÍÊÇÒ»¸öÈí¼þ£¬ËüÔÚÓ²¼þºÍÔËÐÐÔÚ¼ÆËã»úÉϵÄÓ¦ÓóÌÐòÖ®¼äÌṩÁËÒ»¸ö²ã¡£Ñϸñµã´Ó¼ÆËã»ú¿ÆѧµÄ½Ç¶ÈÀ´Ëµ£¬LinuxÖеÄKernelÖ¸µÄÊÇLinus TorvaldsÔÚ90Äê´ú³õÆÚдµÄÄǵã´úÂë¡£

ËùÓеÄÄãÔÚLinux¸÷°æ±¾Öп´µ½µÄÆäËû¶«Î÷--Bash shell¡¢KDE´°¿Ú¹ÜÀíÆ÷¡¢webä¯ÀÀÆ÷¡¢X·þÎñÆ÷¡¢Tux RacerÒÔ¼°ËùÓеÄÆäËû£¬¶¼²»¹ýÊÇÔËÐÐÔÚLinuxÉϵÄÓ¦ÓöøÒÑ£¬¶ø²»ÊDzÙ×÷ϵͳ×ÔÉíµÄÒ»²¿·Ö¡£ÎªÁ˸ø´ó¼ÒÒ»¸ö¸ü¼ÓÖ±¹ÛµÄ¸Ð¾õ£¬ÎÒÀ´¾Ù¸öÀý×Ó£¬±ÈÈçRHEL5µÄ°²×°´ó¸ÅÒªÕ¼¾Ý2.5GBµÄÓ²Å̿ռ䣨¾ßÌå¶à´óµ±È»ÊÓÄãµÄÑ¡Ôñ°²×°À´¶¨£©£¬ÔÚÕâÆäÖУ¬kernelÒÔ¼°ËüµÄ¸÷¸öÄ£¿é×é¼þ£¬Ö»ÓÐ47MB£¬ËùÕ¼±ÈÀýԼΪ2%¡£

ÔÚkernelÄÚ²¿

ÄÇôkernelµ½µ×ÊÇÈçºÎ¹¤×÷µÄÄØ?ÈçÏÂÃæµÄͼ±í¡£Kernelͨ¹ýÐí¶àµÄ½øÈë¶Ë¿ÚÒ²¾ÍÊÇÎÒÃÇ´Ó¼¼Êõ½Ç¶ÈËù˵µÄϵͳµ÷Óã¬À´Ê¹µÃÔËÐÐÔÚËüÉÏÃæµÄÓ¦ÓóÌÐò¿ÉÓá£KernelʹÓõÄϵͳµ÷ÓñÈÈç"¶Á"ºÍ"д"À´ÌṩÄãÓ²¼þµÄ³éÏó£¨abstraction£©¡£

´Ó³ÌÐòÔ±µÄÊÓ½ÇÀ´¿´£¬ÕâЩ¿´ÆðÀ´Ö»ÊÇÆÕͨµÄ¹¦Äܵ÷Óã¬È»¶øʵ¼ÊÉÏϵͳµ÷ÓÃÔÚ´¦ÀíÆ÷µÄ²Ù×÷ģʽÉÏ£¬´ÓÓû§¿Õ¼äµ½Kernel¿Õ¼äÓÐÒ»¸öÃ÷ÏÔµÄÇл»¡£Í¬Ê±£¬ÏµÍ³µ÷ÓÃÌṩÁËÒ»¸ö"LinuxÐéÄâ»ú"£¬¿ÉÒÔ±»ÈÏΪÊǶÔÓ²¼þµÄ³éÏó¡£

KernelÌṩµÄ¸üÃ÷ÏԵijéÏóÖ®Ò»ÊÇÎļþϵͳ¡£¾ÙÀýÀ´Ëµ£¬ÕâÀïÓÐÒ»¶Î¶ÌµÄ³ÌÐòÊÇÓÃCдµÄ£¬Ëü´ò¿ªÁËÒ»¸öÎļþ²¢½«ÄÚÈÝ¿½±´µ½±ê×¼µÄÊä³ö£º

#include
int main()
{
int fd, count; char buf[1000];
fd=open("mydata", O_RDONLY);
count = read(fd, buf, 1000);
write(1, buf, count);
close(fd);
}

ÔÚÕâÀÄã¿ÉÒÔ¿´µ½Ëĸöϵͳµ÷ÓõÄÀý×Ó£º´ò¿ª¡¢¶Á¡¢Ð´ºÍ¹Ø±Õ¡£²»Ì¸Õâ¶Î³ÌÐòÓï·¨µÄϸ½Ú£¬ÖصãÊÇ£ºÍ¨¹ýÕâЩϵͳµ÷ÓÃLinux KernelÌṩÁËÒ»¸öÎļþµÄ"´í¾õ"£¬¶øʵ¼ÊÉÏËü²»¹ýÊÇÒ»¶ÑÊý¾ÝÓÐÁ˸öÃû×Ö£¬ÕâÑùÒ»À´Äã¾Í²»±ØÈ¥ÓëÓ²¼þµ×²ãµÄ¶ÑÕ»¡¢·ÖÇø¡¢Í·ºÍÖ¸Õë¡¢·ÖÇøµÈ½»ÉæÁË£¬¶øÊÇÖ±½ÓÒÔÀý×ÓÖеķ½Ê½ÓëÓ²¼þ"½»Á÷"£¬ÕâÒ²¾ÍÊÇÎÒÃÇËù˵µÄ³éÏó£¨abstraction£©£¬½«µ×²ãµÄ¶«Î÷ÒÔ¸üÒ׶®µÄ·½Ê½±í´ï³öÀ´¡£

̨ǰĻºó

ϵͳÎļþÊÇKernelÌṩµÄ½ÏΪÃ÷ÏÔµÄÒ»ÖÖ³éÏó¡£»¹ÓÐһЩÌØÐÔ²»ÊÇÕâôµÄÃ÷ÏÔ£¬±ÈÈç½ø³Ìµ÷¶È¡£ÈκÎÒ»¸öʱ¼ä£¬¶¼¿ÉÄÜÓкü¸¸ö½ø³Ì»òÕß³ÌÐòµÈ´ý×ÅÔËÐС£KernelµÄʱ¼äµ÷¶È¸øÿ¸ö½ø³Ì·ÖÅäCPUʱ¼ä£¬ËùÒÔ¾ÍÒ»¶Îʱ¼äÄÚÀ´Ëµ£¬ÎÒÃÇ»áÓÐÖÖ´í¾õ£ºµçÄÔͬһʱ¼äÔËÐкü¸¸ö³ÌÐò¡£ÕâÊÇÁíÍâÒ»¸öC³ÌÐò£º

#include
main()
{
if (fork()) {
write(1, "Parent\n", 7);
wait(0);
exit(0);
}
else {
write(1, "Child\n", 6);
exit(0);
}
}

ÔÚÕâ¸ö³ÌÐòÖд´½¨ÁËÒ»¸öнø³Ì£¬¶øÔ­À´µÄ½ø³Ì£¨¸¸½ø³Ì£©ºÍнø³Ì£¨×Ó½ø³Ì£©¶¼±àдÁ˱ê×¼Êä³öÈ»ºó½áÊø¡£×¢Òâϵͳµ÷ÓÃfork(), exit() ÒÔ¼° wait()Ö´ÐгÌÐòµÄ´´½¨¡¢½áÊøºÍ¸÷×Ôͬ²½¡£ÕâÊǽø³Ì¹ÜÀíºÍµ÷¶ÈÖÐ×îµäÐ͵ļòµ¥µ÷Óá£

Kernel»¹ÓÐÒ»¸ö¸ü¼Ó²»Ò×¼ûµ½µÄ¹¦ÄÜ£¬Á¬³ÌÐòÔ±¶¼²»Òײì¾õ£¬ÄǾÍÊÇ´æ´¢¹ÜÀí¡£Ã¿¸ö³ÌÐòÔËÐеö¼ºÃÏñËüÓиö×Ô¼ºµÄµØÖ·¿Õ¼äÀ´µ÷ÓÃÒ»Ñù£¬Êµ¼ÊÉÏËü¸úÆäËû½ø³ÌÒ»Ñù¹²Ïí¼ÆËã»úµÄÎïÀí´æ´¢£¬Èç¹ûϵͳÔËÐеĴ洢¹ýµÍ£¬ËüµÄµØÖ·¿Õ¼äÉõÖÁ»á±»´ÅÅ̵Ľ»»¥ÇøÔÝʱ¼ÄÓᣴ洢¹ÜÀíµÄÁíÍâÒ»¸ö·½ÃæÊÇ·ÀÖ¹Ò»¸ö½ø³Ì·ÃÎÊÆäËû½ø³ÌµÄµØÖ·¿Õ¼ä--¶ÔÓÚ¶à½ø³Ì²Ù×÷ϵͳÀ´ËµÕâÊǺܱØÒªµÄÒ»¸ö·À·¶´ëÊ©¡£

KernelͬÑù»¹ÅäÖÃÍøÂçÁ´½ÓЭÒé±ÈÈçIP¡¢TCPºÍUDPµÈ£¬ËüÃÇÔÚÍøÂçÉÏÌṩ»úÆ÷¶Ô»úÆ÷£¨machine-to-machine£©ºÍ½ø³Ì¶Ô½ø³Ì£¨process-to-process£©µÄͨÐÅ¡£ÕâÀïÓÖ»áÔì³ÉÒ»ÖÖ¼ÙÏ󣬼´TCPÔÚÁ½¸ö½ø³ÌÖ®¼äÌṩÁËÒ»¸ö¹Ì¶¨Á¬½Ó--¾ÍºÃÏñÁ¬½ÓÁ½¸öµç»°µÄÍ­ÏßÒ»Ñù£¬Êµ¼ÊÖÐÈ´²¢Ã»Óй̶¨µÄÁ¬½Ó£¬ÌØÊâµÄÒýÓÃЭÒé±ÈÈçFTP¡¢DNSºÍHTTPÊÇͨ¹ýÓû§¼¶³ÌÐòÀ´ÊµÊ©µÄ£¬¶ø²¢·ÇKernelµÄÒ»²¿·Ö¡£

Linux£¨Ïñ֮ǰµÄUnix£©ÔÚ°²È«·½Ãæ¿Ú±®ºÜºÃ£¬ÕâÊÇÒòΪKernel¸ú×ټǼÁËÿ¸öÔËÐнø³ÌµÄuser IDºÍgroup ID£¬Ã¿´Îµ±Ò»¸öÓ¦ÓÃÆóͼ·ÃÎÊ×ÊÔ´£¨±ÈÈç´ò¿ªÒ»¸öÎļþÀ´Ð´È룩µÄʱºò£¬Kernel¾Í»áºË¶ÔÎļþÉϵķÃÎÊÐí¿ÉÈ»ºó×ö³öÔÊÐí/½ûÖ¹µÄÃüÁî¡£ÕâÖÖ·ÃÎÊ¿ØÖÆģʽ×îÖÕ¶ÔÕû¸öLinuxϵͳµÄ°²È«×÷Óúܴó¡£

Kernel»¹ÌṩÁËÒ»´óÌ×Ä£¿éµÄ¼¯ºÏ£¬Æ书ÄÜ°üÀ¨ÈçºÎ´¦ÀíÓëÓ²¼þÉ豸½»Á÷µÄÖî¶àϸ½Ú¡¢ÈçºÎ´Ó´ÅÅ̶ÁÈ¡Ò»¸ö·ÖÇø¡¢Èç¹û´ÓÍøÂç½Ó¿Ú¿¨»ñÈ¡Êý¾Ý°üµÈ¡£ÓÐʱÎÒÃdzÆÕâЩΪÉ豸Çý¶¯¡£

Ä£¿é»¯µÄKernel

ÏÖÔÚÎÒÃǶÓKernelÊÇ×öʲôµÄÒѾ­ÓÐÁËһЩÁ˽⣬ÈÃÎÒÃÇÔÙÀ´¼òµ¥¿´ÏÂËüµÄÎïÀí×é³É¡£ÔçÆÚ°æ±¾µÄLinux KernelÊÇÕûÌåʽµÄ£¬Ò²¾ÍÊÇ˵ËùÓеIJ¿¼þ¶¼¾²Ì¬µØÁ¬½Ó³ÉÒ»¸ö£¨ºÜ´óµÄ£©Ö´ÐÐÎļþ¡£

Ïà±È½Ï¶øÑÔ£¬ÏÖÔÚµÄLinux KernelÊÇÄ£¿é»¯µÄ£ºÐí¶à¹¦ÄÜ°üº¬ÔÚÄ£¿éÄÚ£¬È»ºó¶¯Ì¬µØÔØÈëkernelÖС£ÕâʹµÃkernelµÄÄں˺ÜС£¬¶øÇÒÔÚÔËÐÐkernelʱ¿ÉÒÔ²»±Øreboot¾ÍÄÜÔØÈëºÍÌæ´úÄ£¿é¡£

KernelµÄÄÚºËÔÚboot timeʱ´ÓλÓÚ/boot Ŀ¼µÄÒ»¸öÎļþ¼ÓÔؽø´æ´¢ÖУ¬Í¨³£Õâ¸ö/boot Ŀ¼»á±»½Ð×öKERNELVERSION£¬KERNELVERSIONÓëkernel°æ±¾Óйء££¨Èç¹ûÄãÏëÖªµÀÄãµÄkernel°æ±¾ÊÇʲô£¬ÔËÐÐÃüÁîÐÐÏÔʾϵͳÐÅÏ¢-r¡££©kernelµÄÄ£¿éλÓÚĿ¼/lib/modules/KERNELVERSION֮ϣ¬ËùÓеÄ×é¼þ¶¼»áÔÚkernel°²×°Ê±±»¿½±´¡£

¹ÜÀíÄ£¿é

´ó²¿·ÖÇé¿öÏ£¬Linux¹ÜÀíËüµÄÄ£¿é²»ÐèÒªÄãµÄ°ï棬µ«ÊÇÈç¹û±ØÒªµÄʱºòÓÐÃüÁîÐпÉÒÔÀ´ÊÖ¶¯¼ì²éºÍ¹ÜÀíÄ£¿é¡£±ÈÈ磬ΪÁ˲éÇå³þµ±Ç°µ½µ×ÄĸöÄ£¿éÔÚÔØÈëkernel¡£ÕâÀïÓÐÒ»¸öÊä³öµÄÀý×Ó£º

# lsmod
pcspkr 4224 0
hci_usb 18204 2
psmouse 38920 0
bluetooth 55908 7 rfcomm,l2cap,hci_usb
yenta_socket 27532 5
rsrc_nonstatic 14080 1 yenta_socket
isofs 36284 0

Êä³öµÄÄÚÈÝ°üÀ¨£ºÄ£¿éµÄÃû×Ö¡¢´óС¡¢Ê¹ÓôÎÊýºÍÒÀÀµÓÚËüµÄÄ£¿éÁÐ±í¡£Ê¹ÓôÎÊý¶Ô·ÀֹжÔص±Ç°»îÔ¾µÄÄ£¿é·Ç³£×ÜÒª¡£LinuxÖ»ÔÊÐíʹÓôÎÊýΪÁãµÄÄ£¿é±»ÒƳý¡£

Äã¿ÉÒÔʹÓÃmodprobeÀ´ÊÖ¶¯¼ÓÔغÍжÔØÄ£¿é£¬£¨»¹ÓÐÁ½¸öÃüÁîÐнÐ×öinsmodºÍrmmod£¬µ«modprobe¸üÒ×ÓÚʹÓÃÒòΪËü×Ô¶¯ÒƳýÁËÄ£¿éÒÀÀµ£©¡£±ÈÈçlsmodµÄÊä³öÔÚÎÒÃǵĵçÄÔÉÏÏÔʾÁËÒ»¸öÃû½ÐisofsµÄжÔØÄ£¿é£¬ËüµÄʹÓôÎÊýÊÇÁã¶øÇÒûÓÐÒÀÀµÄ£¿é£¬£¨isofsÊÇÒ»¸öÄ£¿é£¬ËüÖ§³ÖCDÉÏʹÓõÄISOϵͳÎļþ¸ñʽ£©ÕâÖÖÇé¿öÏ£¬kernel»áÔÊÐíÎÒÃÇжÔØÄ£¿é£º

# modprobe -r isofs

ÏÖÔÚ£¬isofs²»ÔÙÏÔʾÔÚIsmodµÄÊä³öÖУ¬kernelÓɴ˽ÚÊ¡ÁË36,284×ֽڵĴ洢¡£Èç¹ûÄã·ÅÈëCD²¢ÇÒÈÃËü×Ô¶¯°²×°£¬kernel½«×Ô¶¯ÖØÐÂÔØÈëisofsÄ£¿é£¬¶øÇÒisofsµÄʹÓôÎÊýÔö¼Óµ½1´Î¡£Èç¹ûÕâʱºòÄ㻹ÊÔͼÒƳýÄ£¿é£¬¾Í²»»á³É¹¦ÁËÒòΪËüÕýÔÚ±»Ê¹Óãº

# modprobe -r isofs
FATAL: Module isofs is in use.

LsmodÖ»ÊÇÁгöÁ˵±Ç°±»ÔØÈëµÄÄ£¿é£¬modprobeÔò½«ÁгöËùÓпÉÓõÄÄ£¿é£¬Ëüʵ¼ÊÉÏÊä³öÁË/lib/modules/KERNELVERSIONĿ¼ÏÂËùÓеÄÄ£¿é£¬Ãûµ¥»áºÜ³¤£¡

ʵ¼ÊÉÏ£¬Ê¹ÓÃmodprobeÀ´ÊÖ¶¯¼ÓÔØÒ»¸öÄ£¿é²¢²»³£¼û£¬µ«È·Êµ¿ÉÒÔͨ¹ýmodprobeÃüÁîÐÐÀ´¶ÔÄ£¿éÉèÖòÎÊý£¬ÀýÈ磺

# modprobe usbcore blinkenlights=1

ÎÒÃDz¢²»ÊÇÔÚ´´½¨blinkenlights£¬¶øÊÇusbcoreÄ£¿éµÄʵ²ÎÊý¡£

ÄÇôÈçºÎÖªµÀÒ»¸öÄ£¿é»á½ÓÊÜʲô²ÎÊýÄØ£¿Ò»¸ö±È½ÏºÃµÄ·½·¨ÊÇʹÓÃmodinfoÃüÁËüÁгöÁ˹ØÓÚÄ£¿éµÄÖÖÖÖÐÅÏ¢¡£ÕâÀïÓÐÒ»¸ö¹ØÓÚÄ£¿ésnd-hda-intelµÄÀý×Ó

# modinfo snd-hda-intel
filename: /lib/modules/2.6.20-16-generic/kernel/sound/pci/hda/snd-hda-intel.ko
description: Intel HDA driver
license: GPL
srcversion: A3552B2DF3A932D88FFC00C
alias: pci:v000010DEd0000055Dsv*sd*bc*sc*i*
alias: pci:v000010DEd0000055Csv*sd*bc*sc*i*
depends: snd-pcm,snd-page-alloc,snd-hda-codec,snd
vermagic: 2.6.20-16-generic SMP mod_unload 586
parm: index:Index value for Intel HD audio interface. (int)
parm: id:ID string for Intel HD audio interface. (charp)
parm: model:Use the given board model. (charp)
parm: position_fix:Fix DMA pointer (0 = auto, 1 = none, 2 = POSBUF, 3 = FIFO size). (int)
parm: probe_mask:Bitmask to probe codecs (default = -1). (int)
parm: single_cmd:Use single command to communicate with codecs (for debugging only). (bool)
parm: enable_msi:Enable Message Signaled Interrupt (MSI) (int)
parm: enable:bool

¶ÔÎÒÃÇÀ´Ëµ±È½ÏÓÐÐËȤµÄÒÔ"parm"¿ªÍ·µÄÄÇЩ²¿·Ö£ºÏÔʾÁËÄ£¿éËù½ÓÊܵIJÎÊý¡£ÕâЩÃèÊö¶¼±È½Ï¼òÃ÷£¬Èç¹ûÏëÒª¸ü¶àµÄÐÅÏ¢£¬ÄǾͰ²×°kernelµÄÔ´´úÂ룬ÔÚÀàËÆÓÚ/usr/src/KERNELVERSION/DocumentationµÄĿ¼ÏÂÄã»áÕÒµ½¡£

ÀïÃæ»áÓÐһЩÓÐȤµÄ¶«Î÷£¬±ÈÈçÎļþ/usr/src/KERNELVERSION/Documentation/sound/alsa/ALSA-Configuration.txtÃèÊöµÄÊDZ»Ðí¶àALSAÉùÒôÄ£¿é³ÐÈϵIJÎÊý£»/usr/src/KERNELVERSION/Documentation/kernel-parameters.txtÕâ¸öÎļþÒ²ºÜÓÐÓá£

Ç°¼¸ÌìÔÚUbuntuÂÛ̳ÓÐÒ»¸öÀý×Ó£¬ËµµÄÊÇÈçºÎ½«²ÎÊý´«µÝµ½Ò»¸öÄ£¿é£¨Ïê¼ûhttps://help.ubuntu.com/community/HdaIntelSoundHowto£©¡£Êµ¼ÊÉÏÎÊÌâµÄ¹Ø¼üÊÇsnd-hda-intel²ÎÊýÔÚÕýÈ·Çý¶¯ÉùÒôÓ²¼þʱÐèÒªÒ»µã²Ù×÷£¬¶øÇÒÔÚboot time¼ÓÔØʱ»áÖÐÖ¹¡£½â¾ö·½·¨µÄÒ»²¿·ÖÊǽ«probe_mask=1Ñ¡Ï¸øÄ£¿é£¬Èç¹ûÄãÊÇÊÖ¶¯¼ÓÔØÄ£¿é£¬ÄãÐèÒªÊäÈ룺

# modprobe snd-hda-intel probe_mask=1

¸üÓпÉÄÜ£¬ÄãÔÚÎļþ/etc/modprobe.confÖзÅÖÃÕâÑùÀàËƵÄÒ»ÐУºoptions snd-hda-intel probe_mask=1

Õâ"¸æËß"modprobeÿ´ÎÔÚ¼ÓÔØsnd-hda-intelÄ£¿éʱ°üº¬probe_mask=1Ñ¡Ïî¡£ÏÖÔÚµÄÓÐЩLinux°æ±¾½«ÕâÒ»ÐÅÏ¢·ÖÀë½ø/etc/modprobe.dϵIJ»Í¬ÎļþÖÐÁË£¬¶ø²»ÊÇ·ÅÈëmodprobe.confÖС£

/procϵͳÎļþ

Linux kernelͬÑùͨ¹ý/procϵͳÎļþÀ´Õ¹Ê¾ÁËÐí¶àϸ½Ú¡£ÎªÁË˵Ã÷/proc£¬ÎÒÃÇÊ×ÏÈÐèÒªÀ©Õ¹ÎÒÃǶÔÓÚÎļþµÄÀí½â¡£³ýÁËÈÏΪÎļþ¾ÍÊÇ´æ´¢ÔÚÓ²ÅÌ»òÕßCD»òÕß´æ´¢¿Õ¼äÉϵij־ÃÐÅÏ¢Ö®Í⣬ÎÒÃÇ»¹Ó¦µ±°ÑËüÀí½âΪÈκοÉÒÔͨ¹ý´«Í³ÏµÍ³µ÷ÓÃÈ磺´ò¿ª¡¢¶Á¡¢Ð´¡¢¹Ø±ÕµÈ·ÃÎʵÄÐÅÏ¢£¬µ±È»ËüÒ²¿ÉÒÔ±»³£¼ûµÄ³ÌÐò·ÃÎÊ¡£

/proc֮ϵÄ"Îļþ"ÍêÈ«ÊÇkernelÐéÄâµÄÒ»¸ö²¿·Ö£¬¸øÎÒÃÇÒ»¸öÊӽǿÉÒÔ¿´µ½kernelÄÚ²¿µÄÊý¾Ý½á¹¹¡£Êµ¼ÊÉÏ£¬Ðí¶àLinuxµÄ±¨¸æ¹¤¾ß¾ùÄܹ»ºÜºÃµØ³ÊÏÖÔÚ/procϵÄÎļþÖÐÑ°µ½µÄ¸ñʽ»¯°æ±¾µÄÐÅÏ¢¡£±ÈÈ磬һÁÐ/proc/modules½«Õ¹Ê¾Ò»Áе±Ç°¼ÓÔصÄÄ£¿é¡£

ͬÑùµÄ£¬/proc/meminfoÌṩÁ˹ØÓÚÐéÄâ´æ´¢ÏµÍ³µ±Ç°×´Ì¬µÄ¸ü¶àϸ½ÚÐÅÏ¢£¬¶øÀàÈçvmstatµÄ¹¤¾ßÔòÊÇÒÔÒ»ÖÖ¸ü¼Ó¿ÉÀí½âµÄ·½Ê½ÌṩÁËÏàͬµÄһЩÐÅÏ¢£»/proc/net/arpÏÔʾÁËϵͳARP cacheµÄµ±Ç°ÄÚÈÝ£¬´ÓÃüÁîÐÐÀ´Ëµ£¬arp -aÏÔʾµÄÒ²ÊÇÏàͬµÄÐÅÏ¢¡£

ÓÈÆäÓÐÒâ˼µÄÊÇ/proc/sysϵÄ"Îļþ"¡£/proc/sys/net/ipv4/ip_forwardϵÄÉèÖøæËßÎÒÃÇkernelÊÇ·ñ½«×ª·¢IPÊý¾Ý°ü£¬Ò²¾ÍÊÇ˵ÊÇ·ñ°çÑÝÍø¹ØµÄ×÷Óá£ÏÖÔÚ£¬kernel¸æËßÎÒÃÇÕâÊǹرյģº

# cat /proc/sys/net/ipv4/ip_forward
0

µ±Äã·¢ÏÖÄã¿ÉÒÔ¶ÔÕâЩÎļþдÈëµÄʱºò£¬Äã»á¾õµÃ¸ü¼ÓÓÐÒâ˼¡£¼ÌÐø¾ÙÀýÀ´Ëµ£º

# echo 1 > /proc/sys/net/ipv4/ip_forward

½«ÔÚÔËÐеÄkernelÖдò¿ªIP ת·¢£¨IP forwarding£©

³ýÁËʹÓÃcatºÍechoÀ´¼ì²éºÍ¸üÕý/proc/sysϵÄÉèÖÃÒÔÍ⣬ÄãÒ²¿ÉÒÔʹÓÃsysctlÃüÁ

# sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 0

ÕâµÈͬÓÚ£º
# cat /proc/sys/net/ipv4/ip_forward
0

Ò²µÈͬÓÚ£º
# sysctl -w net.ipv4.ip_forward=1
net.ipv4.ip_forward = 1

»¹µÈͬÓÚ£º
# echo 1 > /proc/sys/net/ipv4/ip_forward


ÐèҪעÒâµÄÊÇ£¬ÒÔÕâÖÖ·½Ê½ÄãËù×öµÄÉèÖøıäÖ»ÄÜÓ°Ï쵱ǰÔËÐеÄkernelµÄ£¬µ±rebootµÄʱºò¾Í²»ÔÙÓÐЧ¡£Èç¹ûÏëÈÃÉèÖÃÓÀ¾ÃÓÐЧ£¬½«ËüÃÇ·ÅÖÃÔÚ/etc/sysctl.confÎļþÖС£ÔÚboot timeʱ£¬sysctl½«×Ô¶¯ÖØÐÂÈ·¶¨ËüÔÚ´ËÎļþÏÂÕÒµ½µÄÈκÎÉèÖá£

/etc/sysctl.confϵĴúÂëÐдó¸ÅÊÇÕâÑùµÄ£ºnet.ipv4.ip_forward=1

ÐÔÄܵ÷ÓÅ£¨performance tuning£©

ÓÐÕâÑùÒ»¸ö˵·¨£º/proc/sysÏ¿ÉдÈëµÄ²ÎÊýÔÐÓýÁËÕû¸öLinuxÐÔÄܵ÷ÓŵÄÑÇÎÄ»¯¡£ÎÒ¸öÈ˾õµÃÕâÖÖ˵·¨Óеã¹ý¿ä£¬µ«ÕâÀï»áÓм¸¸öÄãȷʵºÜÏëÒ»ÊÔµÄÀý×Ó£ºOracle 10gµÄ°²×°ËµÃ÷£¨www.oracle.com/technology/obe/obe10gdb/install/linuxpreinst/linuxpreinst.htm£©ÒªÇóÄãÉèÖÃÒ»×é²ÎÊý£¬°üÀ¨£ºkernel.shmmax=2147483648 Õ⽫¹«Óô洢Æ÷µÄ´óСÉèÖÃΪ2GB¡££¨¹«Óô洢Æ÷ÊÇ´¦ÀíÆÚÄÚµÄͨÐÅ»úÖÆ£¬ÔÊÐí´æ´¢µ¥ÔªÔÚ¶à¸ö½ø³ÌµÄµØÖ·¿Õ¼äÄÚͬʱ¿ÉÓã©

IBM 'Redpaper'ÔÚLinuxÐÔÄܺ͵÷ÓÅ·½ÃæµÄ˵Ã÷£¨www.redbooks.ibm.com/abstracts/redp4285.html£©ÔÚµ÷½Ì/proc/sysϵIJÎÊý·½Ãæ¸ø³öÁ˲»ÉÙ½¨Ò飬°üÀ¨£ºvm.swappiness=100 Õâ¸ö²ÎÊý¿ØÖÆ×Å´æ´¢Ò³ÈçºÎ±»½»»»µ½´ÅÅÌ¡£

һЩ²ÎÊý¿ÉÒÔ±»ÉèÖôӶøÌá¸ß°²È«ÐÔ£¬Èçnet.ipv4.icmp_echo_ignore_broadcasts=1 Ëü"¸æËß"kernel²»±ØÏìÓ¦ICMPÇëÇ󣬴ӶøʹµÃÄãµÄÍøÂçÃâÊÜÀàÈçSmurf¹¥»÷Ö®ÀàµÄ¾Ü¾ø·þÎñÆ÷£¨denial-of-service£©Ð͹¥»÷¡£
net.ipv4.conf.all.rp_filter=1 ÔòÊÇ"¸æËß"kernel¼ÓÇ¿ÈëÕ¾¹ýÂË£¨ingress filtering£©ºÍ³öÕ¾¹ýÂË£¨egress filtering£©

ÄÇôÓÐûÓÐÒ»¸ö˵Ã÷Äܺ­¸ÇÕâËùÓеIJÎÊý£¿ºÃ°É£¬ÕâÓÐÒ»ÐÐÃüÁ# sysctl -a Ëü½«Õ¹Ê¾ËùÓеIJÎÊýÃû×ֺ͵±Ç°Öµ¡£ÁбíºÜ³¤£¬µ«ÊÇÄãÎÞ·¨ÖªµÀÕâЩ²ÎÊýÊÇ×öʲôµÄ¡£ÁíÍâ±È½ÏÓÐÓõIJο¼ÊÇRed Hat Enterprise Linux Reference Guide£¬¶Ô´ËÓÐÕûÕ½ڵÄÃèÊö£¬Äã¿ÉÒÔ´Ówww.redhat.com/docs/manuals/enterpriseÉÏÏÂÔØ¡£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ