ÄãÕæµÄ»áµ÷ÊÔ Linux Äں˹ÊÕÏÂ𣬿´ÍêÕâһƪºóÄã»áéÈû¶Ù¿ªµÄ£¡
LinuxÄÚºËÊDzÙ×÷ϵͳµÄ½¹µã£¬Ëü¿ØÖƶÔϵͳ×ÊÔ´£¨ÀýÈ磺CPU¡¢I/O×°±¸¡¢ÎïÀíÄÚ´æºÍÎļþϵͳ£©µÄ»á¼û¡£ÔÚÖ¸µ¼Àú³ÌÖÐÒÔ¼°ÏµÍ³ÔËÐÐʱ£¬Äں˻ὫÖÖÖÖÐÂÎÅдÈëÄں˻·Ðλº³åÇø¡£ÕâЩÐÂÎÅ°üÀ¨ÓйØϵͳ²Ù×÷µÄÖÖÖÖÐÅÏ¢¡£
Äں˻·Ðλº³åÇøÊÇÎïÀíÄÚ´æµÄÒ»²¿·Ö£¬ÓÃÓÚÉúÑÄÄں˵ÄÈÕÖ¾ÐÂÎÅ¡£Ëü¾ßÓÐÀο¿µÄ¾Þϸ£¬ÕâÒâζ×ÅÒ»µ©»º³åÇøÒÑÂú£¬½Ï¾ÉµÄÈÕÖ¾¼Í¼½«±»ÁýÕÖ¡£
dmesgÏÂÁîÐÐÊÊÓóÌÐòÓÃÓÚÔÚLinuxºÍÆäËûÀàËÆUnixµÄ²Ù×÷ϵͳÖдòÓ¡ºÍ¿ØÖÆÄں˻·Ðλº³åÇø¡£¹ØÓÚ¼ì²éÄÚºËÆô¶¯ÐÂÎź͵÷ÊÔÓëÓ²¼þÏà¹ØµÄÎÊÌâºÜÓÐÓá£
ÔÚ±¾½Ì³ÌÖУ¬ÎÒÃǽ«ÏÈÈÝdmesgÏÂÁîµÄ»ù´¡¡£
ʹÓà dmesg ÏÂÁî
dmesgÏÂÁîµÄÓï·¨ÈçÏ£º
dmesg [OPTIONS] ÔÚ²»´øÈκÎÑ¡ÏîµÄÇéÐÎÏÂŲÓÃʱ£¬dmesg½«ËùÓÐÐÂÎÅ´ÓÄں˻·Ðλº³åÇøдÈë±ê×¼Êä³ö£º
µÇ¼ºó¸´ÖÆ
$ dmesg
ĬÈÏÇéÐÎÏ£¬ËùÓÐÓû§¶¼¿ÉÒÔÔËÐÐdmesgÏÂÁî¡£¿ÉÊÇ£¬ÔÚijЩϵͳÉÏ£¬·Ç root Óû§¿ÉÄÜ»áÏÞÖƶÔdmesgµÄ»á¼û¡£ÔÚÕâÖÖÇéÐÎÏ£¬Å²Óà dmesg ʱÄú½«ÊÕµ½ÈçϹýʧÐÂÎÅ£º
dmesg: readkernel buffer failed: Operation not permitted
Äں˲ÎÊýkernel.dmesg_restrictÖ¸¶¨·ÇÌØȨÓû§ÊÇ·ñ¿ÉÒÔʹÓÃdmesgÉó²éÀ´×ÔÄÚºËÈÕÖ¾»º³åÇøµÄÐÂÎÅ¡£ÒªÉ¾³ýÏÞÖÆ£¬Ç뽫ÆäÉèÖÃΪÁ㣺
$ sudo sysctl -w kernel.dmesg_restrict=0
ͨ³££¬Êä³ö°üÀ¨Ðí¶àÐÅÏ¢ÐУ¬Òò´ËÖ»ÄÜ¿´µ½Êä³öµÄ×îºóÒ»²¿·Ö¡£ÒªÒ»´ÎÉó²éÒ»Ò³£¬Ç뽫Êä³öͨ¹ý¹ÜµÀ´«Ë͵½·ÖÒ³ÊÊÓóÌÐò£¬ÀýÈçless»òmore£º
$ dmesg –color=always | less
ÆäÖеĖcolor=always²ÎÊýÓÃÓÚ±£´æ²ÊÉ«Êä³ö¡£
ÈôÊÇÒª¹ýÂË»º³åÇøÐÂÎÅ£¬¿ÉÄÜʹÓÃgrep¡£ÀýÈ磬Ҫ½öÉó²éÓë USB Ïà¹ØµÄÐÂÎÅ£¬Çë¼üÈ룺
$ dmesg | grep -i usb
dmesg ´Ó/proc/kmsgÐéÄâÎļþÖжÁÈ¡ÄÚºËÌìÉúµÄÐÂÎÅ¡£¸ÃÎļþÌṩÁ˵½Äں˻·Ðλº³åÇøµÄ½Ó¿Ú£¬²¢ÇÒÖ»ÄÜÓÉÒ»¸öÀú³Ì·¿ª¡£ÈôÊÇϵͳÉÏÕýÔÚÔËÐÐsyslogÀú³Ì£¬²¢ÇÒÄãʵÑéʹÓÃcat»òlessÏÂÁî¶ÁÈ¡Îļþ£¬ÔòÏÂÁ¹ÒÆð¡£
syslogÊØ»¤³ÌÐò½«ÄÚºËÐÂÎÅת´¢µ½/var/log/dmesg£¬Òò´ËÄãÒ²¿ÉÒÔʹÓøÃÈÕÖ¾Îļþ£º
$ cat /var/log/dmesg
ÃûÌû¯ dmesg Êä³ö¡£
dmesgÏÂÁîÌṩÁËÐí¶àÑ¡Ï¿É×ÊÖúÄãÃûÌû¯ºÍ¹ýÂËÊä³ö¡£
dmesgÖÐ×î³£ÓõÄÑ¡ÏîÖ®Ò»ÊÇ-H£¨–human£©£¬Ëü½«Êä³ö¸üÈÝÒ׶ÁµÄЧ¹û¡£
$ dmesg -H
Òª´òÓ¡ÈËÀà¿É¶ÁµÄʱ¼ä´Á£¬ÇëʹÓÃ-T£¨–ctimeÑ¡Ï£º
$ dmesg -T [Mon Oct 14 14:38:04 2019] IPv6: ADDRCONF(NETDEV_CHANGE): wlp1s0: link becomes ready
µÇ¼ºó¸´ÖÆ
ʱ¼ä´ÁÃûÌÃÒ²¿ÉÒÔʹÓÖtime-format Ñ¡ÏîÉèÖ㬿ÉÒÔÊÇctime£¬reltime£¬delta£¬notime»òiso¡£ÀýÈ磺ҪʹÓÃÔöÁ¿ÃûÌã¬Äã¿ÉÒÔÊäÈ룺
$ dmesg –time-format=delta
ÄãÒ²¿ÉÒÔ×éºÏÁ½¸ö»ò¶à¸öÑ¡Ï
$ dmesg -H -T
ҪʵʱԢĿdmesgÏÂÁîµÄÊä³ö£¬ÇëʹÓÃ-w£¨–follow£©Ñ¡Ï
$ dmesg –follow
¹ýÂË dmesg Êä³ö¡£
Äã¿ÉÒÔ½«dmesgÊä³öÏÞÖÆΪ¸ø¶¨µÄÉèÊ©ºÍÆ·¼¶¡£dmesgÖ§³ÖÒÔÏÂÀàÐÍ£º
kern-ÄÚºËÐÂÎÅ
user-Óû§¼¶ÐÂÎÅ
mail-Óʼþϵͳ
daemon-ϵͳÊØ»¤³ÌÐò
auth-Çå¾²/ÊÚȨÐÂÎÅ
syslog-ÄÚ²¿ syslogd ÐÂÎÅ
lpr-ÐÐʽ´òÓ¡»ú×Óϵͳ
news-ÍøÂçÐÂÎÅ×Óϵͳ
-f£¨–facility £©Ñ¡ÏîÔÊÐíÄ㽫Êä³öÏÞÖÆΪÌض¨µÄ×°±¸£¬¸ÃÑ¡Ïî½ÓÊÜÒ»¸ö»ò¶à¸ö¶ººÅÍÑÀëµÄ¹¦Ð§¡£
ÀýÈ磬Ҫ½öÏÔʾÄں˺ÍϵͳÊØ»¤³ÌÐòÐÂÎÅ£¬¿ÉÒÔʹÓãº
$ dmesg -f kern,daemon
ÿÌõÈÕÖ¾ÐÂÎŶ¼ÓëÒ»¸öÏÔʾÐÂÎÅÖ÷ÒªÐÔµÄÈÕÖ¾¼¶±ðÏà¹ØÁª£¬dmesgÖ§³ÖÒÔÏÂÈÕÖ¾¼¶±ð£º
emerg-ϵͳÎÞ·¨Ê¹ÓÃ
alert-±ØÐèÁ¬Ã¦½ÓÄɲ½·¥
crit-½ôÆÈÇéÐÎ
err-¹ýʧÌõ¼þ
warn-ÖÒÑÔÌõ¼þ
notice-Õý³£µ«Ö÷ÒªµÄÌõ¼þ
info-ÐÅÏ¢ÐÔ
debug-µ÷ÊÔ¼¶ÐÂÎÅ
-l£¨–level £©Ñ¡ÏîÔÊÐíÄ㽫Êä³öÏÞÖÆΪ½ç˵µÄ¼¶±ð£¬¸ÃÑ¡Ïî½ÓÊÜÒ»¸ö»ò¶à¸ö¶ººÅÍÑÀëµÄ¼¶±ð¡£ÒÔÏÂÏÂÁî½öÏÔʾ¹ýʧºÍÑÏÖØÐÂÎÅ£º
$ dmesg -l err,crit
ɨ³ý»·Ðλº³åÇø
-C£¨–clear£©Ñ¡Ïî¿ÉÈÃÄúɨ³ý»·Ðλº³åÇø£º
$ sudo dmesg -C
Ö»ÓÐroot»ò¾ßÓÐsudoÌØȨµÄÓû§²Å»ªÉ¨³ý»º³åÇø¡£
ÒªÔÚɨ³ý֮ǰ´òÓ¡»º³åÇøÄÚÈÝ£¬ÇëʹÓÃ-c£¨–read-clear£©Ñ¡Ï
$ sudo dmesg -c
ÈôÊÇÒªÔÚɨ³ýÎļþ֮ǰ½«Ä¿½ñdmesgÈÕÖ¾ÉúÑĵ½ÎļþÖУ¬Äã¿ÉÒÔ½«Êä³öÖض¨Ïòµ½Îļþ£º
$ dmesg > dmesg_messages
½áÂÛ
dmesgÏÂÁîÔÊÐíÄãÉó²éºÍ¿ØÖÆÄں˻·Ðλº³åÇø¡£¶ÔÄں˻òÓ²¼þÎÊÌâ¾ÙÐйÊÕÏɨ³ýʱ£¬ËüºÜÊÇÓÐÓá£
ÔÚÖÕ¶ËÖÐÊäÈëman dmesg£¬Äã¿ÉÒÔ»ñÈ¡ÓйØËùÓпÉÓÃdmesgÑ¡ÏîµÄÐÅÏ¢¡£
ÒÔÉϾÍÊÇÄãÕæµÄ»áµ÷ÊÔ Linux Äں˹ÊÕÏÂ𣬿´ÍêÕâһƪºóÄã»áéÈû¶Ù¿ªµÄ£¡µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡