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

LinuxÈÕÖ¾´¦ÀíµÄÀ´ÁúÈ¥Âö

·¢²¼Ê±¼ä:2007-10-28 01:12:24À´Ô´:ºìÁª×÷Õß:Mqqlecyro
ÿ¸öʹÓÃUNIX/LINUXµÄÈ˶¼ÖªµÀÈÕÖ¾µÄÓô¦,ÄÇÄãÊÇ·ñÇå³þLINUXÕâЩÈÕÖ¾ÐÅÏ¢´¦ÀíµÄÀ´ÁúÈ¥ÂöÄØ~

±¾È˽üÒ»¸öÔÂÀ´,ͨ¹ý¶ÔÔ´´úÂëµÄËÀ²øÀôò,ÖÕÓÚÓÐËùÌå»á!

ÎÒÃÇ¿ÉÒÔ¿´µ½LINUXϵͳÐÅÏ¢ÈÕÖ¾µÄ;¾¶»ù±¾ÓÐÒÔÏÂ2ÖÖ:

1>dmesg²é¿´----Õâ¸öÃüÁî±È½Ï³£¼û

2>/var/log/ϵÄÎļþ

ÄÇÏÂÃæÎÒÃǾʹÓÕâ¸ö2¸ö;¾¶×ÅÊÖ,Ò»²½²½µÄ×ßÏÂÈ¥.

<Ò»>

Ê×ÏÈ,ÎÒÃÇÀ´¿´dmesgÕâ¸ö³£¼ûµÄÃüÁî±³ºóÒþ²ØµÄÊÇʲô!!

1> ÏÈÈÃÎÒÃÇÀ´MANÒ»ÏÂÕâ¸ö¼Ò»ï

----------------------------------------------man dmesg--------------------------------------------------

----------------------------------------------man dmesg--------------------------------------------------

NAME
dmesg - print or control the kernel ring buffer

SYNOPSIS
dmesg [ -c ] [ -n level ] [ -s bufsize ]

DESCRIPTION
dmesg is used to examine or control the kernel ring
buffer.

The program helps users to print out their bootup mes-
sages. Instead of copying the messages by hand, the user
need only:
dmesg > boot.messages
and mail the boot.messages file to whoever can debug their
problem.

OPTIONS
-c Clear the ring buffer contents after printing.

-sbufsize
Use a buffer of size bufsize to query the kernel
ring buffer. This is 16392 by default. (The
default kernel syslog buffer size was 4096 at
first, 8192 since 1.3.54, 16384 since 2.1.113.) If
you have set the kernel buffer to be larger than
the default then this option can be used to view
the entire buffer.

-nlevel
Set the level at which logging of messages is done
to the console. For example, -n 1 prevents all
messages, expect panic messages, from appearing on
the console. All levels of messages are still
written to /proc/kmsg, so syslogd(8) can still be
used to control exactly where kernel messages
appear. When the -n option is used, dmesg will not
print or clear the kernel ring buffer.

When both options are used, only the last option on
the command line will have an effect.


´ÓLINUXÌṩµÄÊÖ²á,ÎÒÃÇ¿ÉÒÔµÃÖªÒ»Ìõ×îÖØÒªµÄÐÅÏ¢dmesgÊÇ´Ókernel µÄring buffer(»·»º³åÇø)ÖжÁÈ¡ÐÅÏ¢µÄ.

2> ÄÇʲôÊÇring bufferÄØ?

ÔÚLINUXÖÐ,ËùÓеÄϵͳÐÅÏ¢(°üÄÚºËÐÅÏ¢)¶¼»á´«Ë͵½ring bufferÖÐ.¶øÄں˲úÉúµÄÐÅÏ¢ÓÉprintk()´òÓ¡³öÀ´¡£ÏµÍ³Æô¶¯Ê±Ëù¿´µ½µÄÐÅÏ¢¶¼ÊÇÓɸú¯Êý´òÓ¡µ½ÆÁÄ»ÖС£ printk£¨£©´ò³öµÄÐÅÏ¢ÍùÍùÒÔ <0><2>...ÕâµÄÊý×Ö±íÃ÷ÏûÏ¢µÄÖØÒª¼¶±ð¡£¸ßÓÚÒ»¶¨µÄÓÅÏȼ¶±ð»á´òÓ¡µ½ÆÁÄ»ÉÏ£¬ ·ñÔòÖ»»á±£ÁôÔÚϵͳµÄ»º³åÇøÖÐ(ring buffer)¡£

ÖÁÓÚdmesg¾ßÌåÊÇÈçºÎ´Óring bufferÖжÁÈ¡µÄ,´ó¼Ò¿ÉÒÔ¿´dmesg.cÔ´´úÂë.ºÜ¶Ì,±È½ÏÈÝÒ×¶Á¶®.

<¶þ>

dmesgÔõô¸ãµÄ´ó¼ÒÓ¦¸ÃºÜÃ÷°×Á˰É.ÖÁÓÚ/var/log/ϵÄÎļþ¸üÊÇ´ó¼ÒÊìϤµÃ²»ÄÜÔÙÊìϤÁË!

1> /var/log/..ÏÂΪʲôÓÐÕâô¶àÎļþÄØ?

Ò»¾ä»°½âÊÍ: ÊÇsyslogdÕâ¸öÊØ»¤½ø³Ì¸ù¾Ý/etc/syslog.conf,½«²»Í¬µÄ·þÎñ²úÉúµÄLog¼Ç¼µ½²»Í¬µÄÎļþÖÐ.

ÕâÀïµÄ/etc/syslog.confÎҾͲ»Ï¸ËµÁË,ºÜ¶àÕâ·½ÃæµÄÐÅÏ¢(È¥²é°É).

2> ¼ÈȻ֪µÀÁË,/var/log/..ÊÇÓÉsyslogdÕâ¸öÊØ»¤½ø³Ì²úÉúµÄ.ÄǾÍÔÙ˳×ÅÕâÌõÏß×ßÏÂÈ¥.

LINUXϵͳÆô¶¯ºó£¬ÓÉ/etc/init.d/sysklogdÏȺóÆô¶¯klogd,syslogdÁ½¸öÊØ»¤½ø³Ì¡£

ÆäÖÐklogd»áͨ¹ýsyslog()ϵͳµ÷ÓûòÕß¶ÁÈ¡procÎļþϵͳÀ´´Óϵͳ»º³åÇø(ring buffer)Öеõ½ÓÉÄÚºËprintk()

·¢³öµÄÐÅÏ¢.¶øsyslogdÊÇͨ¹ýklogdÀ´¶ÁȡϵͳÄÚºËÐÅÏ¢.

ÎÒÏëÖÁ´Ë,´ó¼ÒÐÄÀíÓ¦¸Ã¶Ôlog²úÉú,¶ÁÈ¡µÈһϵÁе͝×÷ÓÐËù¸Ð¾õ.

ΪÁË»¹²»Ã÷°×µÄÈË:

°³×ܽáÒ»ÏÂ:

1> ËùÓÐϵͳÐÅÏ¢ÊÇÊä³öµ½ring bufferÖÐÈ¥µÄ.dmesgËùÏÔʾµÄÄÚÈÝÒ²ÊÇ´Óring bufferÖжÁÈ¡µÄ.

2> LINUXϵͳÖÐ/etc/init.d/sysklogd»áÆô¶¯2¸öÊØ»¤½ø³Ì:Klogd&&Syslogd

3> klogdÊǸºÔð¶ÁÈ¡ÄÚºËÐÅÏ¢µÄ,ÓÐ2ÖÖ·½Ê½:

syslog()ϵͳµ÷ÓÃ(Õâ¸öº¯ÊýÓ÷¨±È½ÏÈ«,´ó¼ÒÈ¥MANһϿ´¿´)

Ö±½ÓµÄ¶Ô/proc/kmsg½øÐжÁÈ¡(ÔÙÕâÌáÒ»ÏÂ,/proc/kmsgÊÇרÃÅÊä³öÄÚºËÐÅÏ¢µÄµØ·½)

4> KlogdµÄÊä³ö½á¹û»á´«Ë͸øsyslogd½øÐд¦Àí,syslogd»á¸ù¾Ý/etc/syslog.confµÄÅäÖðÑlog

ÐÅÏ¢Êä³öµ½/var/log/ϵIJ»Í¬ÎļþÖÐ.

ÖÕÓÚдÍêÁË,±È½Ï´Ö²Ú.

ÆäÖйØÓÚ:

1>syslog()ϵͳµ÷ÓõÄÓ÷¨

2>dmesgµ½µ×ÈçºÎ¶ÁÈ¡ring bufferµÄ

3>KlogdºÍsyslogdÖ®¼äÊÇÈçºÎ´«µÝÐÅÏ¢µÄ.
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 1 ÌõÆÀÂÛ

  1. Ddrmail ÓÚ 2007-10-28 16:42:52·¢±í:

    ѧϰÁË