九天猎人 发表于 2024-6-26 01:55:32

Linux云计算进阶-10条指令在1分钟内排查出服务器问题之dmesg篇

dmesg 可以检察Linux 内核引导干系的所有信息

dmesg’命令装备故障的诊断是非常重要的。在‘dmesg’命令的资助下进行硬件的连接或断开连接操作时,我们可以看到硬件的检测大概断开连接的信息。‘dmesg’命令在多数基于Linux和Unix的操作体系中都可以使用。
列出加载到内核中的所有驱动

我们可以使用如‘more’。 ‘tail’, ‘less ’大概‘grep’笔墨处置惩罚工具来处置惩罚‘dmesg’命令的输出。由于dmesg日记的输出不适合在一页中完全显示,因此我们使用管道(pipe)将其输出送到more大概less命令单页显示。
# dmesg | more
[    0.000000] Linux version 5.14.0-402.el9.x86_64 (mockbuild@x86-05.stream.rdu2.redhat.com) (gcc (GCC) 11.4.1 2023060
5 (Red Hat 11.4.1-2), GNU ld version 2.35.2-42.el9) #1 SMP PREEMPT_DYNAMIC Thu Dec 21 19:46:35 UTC 2023
[    0.000000] The list of certified hardware and cloud instances for Red Hat Enterprise Linux 9 can be viewed at the
Red Hat Ecosystem Catalog, https://catalog.redhat.com.
[    0.000000] Command line: BOOT_IMAGE=(hd0,msdos1)/vmlinuz-5.14.0-402.el9.x86_64 root=/dev/mapper/cs-root ro rd.lvm.
lv=cs/root
[    0.000000] Disabled fast string operations
[    0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[    0.000000] x86/fpu: xstate_offset:576, xstate_sizes:256
[    0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'compacted' format.
[    0.000000] signal: max sigframe size: 1776
[    0.000000] BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: usable
[    0.000000] BIOS-e820: reserved
[    0.000000] BIOS-e820: reserved
[    0.000000] BIOS-e820: usable
[    0.000000] BIOS-e820: ACPI data
[    0.000000] BIOS-e820: ACPI NVS
[    0.000000] BIOS-e820: usable
[    0.000000] BIOS-e820: reserved
[    0.000000] BIOS-e820: reserved
[    0.000000] BIOS-e820: reserved
[    0.000000] BIOS-e820: reserved
[    0.000000] NX (Execute Disable) protection: active
[    0.000000] SMBIOS 2.7 present.
[    0.000000] DMI: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 11/12/2020
[    0.000000] vmware: hypercall mode: 0x02
[    0.000000] Hypervisor detected: VMware
[    0.000000] vmware: TSC freq read from hypervisor : 3600.000 MHz
[    0.000000] vmware: Host bus clock speed read from hypervisor : 66000000 Hz
--更多--
如下的指令也是雷同的区别。
dmesg | less
输出如下。
# dmesg | less
[    0.000000] Linux version 5.14.0-402.el9.x86_64 (mockbuild@x86-05.stream.rdu2.redhat.com) (gcc (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2), GNU ld version 2.35.2-42.el9) #1 SMP PREEMPT_DYNAMIC Thu Dec 21 19:46:35 UTC 2023[    0.000000] The list of certified hardware and cloud instances for Red Hat Enterprise Linux 9 can be viewed at the Red Hat Ecosystem Catalog, https://catalog.redhat.com.[    0.000000] Command line: BOOT_IMAGE=(hd0,msdos1)/vmlinuz-5.14.0-402.el9.x86_64 root=/dev/mapper/cs-root ro rd.lvm.lv=cs/root[    0.000000] Disabled fast string operations[    0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'[    0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'[    0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'[    0.000000] x86/fpu: xstate_offset:576, xstate_sizes:256[    0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'compacted' format.[    0.000000] signal: max sigframe size: 1776[    0.000000] BIOS-provided physical RAM map:[    0.000000] BIOS-e820: usable[    0.000000] BIOS-e820: reserved[    0.000000] BIOS-e820: reserved[    0.000000] BIOS-e820: usable[    0.000000] BIOS-e820: ACPI data[    0.000000] BIOS-e820: ACPI NVS[    0.000000] BIOS-e820: usable[    0.000000] BIOS-e820: reserved[    0.000000] BIOS-e820: reserved[    0.000000] BIOS-e820: reserved[    0.000000] BIOS-e820: reserved[    0.000000] NX (Execute Disable) protection: active[    0.000000] SMBIOS 2.7 present.[    0.000000] DMI: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 11/12/2020[    0.000000] vmware: hypercall mode: 0x02[    0.000000] Hypervisor detected: VMware[    0.000000] vmware: TSC freq read from hypervisor : 3600.000 MHz[    0.000000] vmware: Host bus clock speed read from hypervisor : 66000000 Hz[    0.000000] vmware: using clock offset of 26849061647 ns[    0.000020] tsc: Detected 3600.000 MHz processor[    0.001616] e820: update usable ==> reserved[    0.001619] e820: remove usable[    0.001623] last_pfn = 0x80000 max_arch_pfn = 0x400000000[    0.001642] total RAM covered: 3072M[    0.001885] Found optimal setting for mtrr clean up[    0.001886]gran_size: 64Kchunk_size: 64K         num_reg: 2      lose cover RAM: 0G[    0.001889] MTRR map: 6 entries (5 fixed + 1 variable; max 21), built from 8 variable MTRRs[    0.001890] x86/PAT: Configuration : WBWCUC- UCWBWPUC- WT[    0.009247] found SMP MP-table at : 列出所有被检测到的硬件

要显示所有被内核检测到的硬盘装备,你可以使用‘grep’命令搜索‘sda’关键词,如下
# dmesg |grep sd
[    0.000000] Command line: BOOT_IMAGE=(hd0,msdos1)/vmlinuz-5.14.0-402.el9.x86_64 root=/dev/mapper/cs-root ro rd.lvm.lv=cs/root
[    0.150022] Kernel command line: BOOT_IMAGE=(hd0,msdos1)/vmlinuz-5.14.0-402.el9.x86_64 root=/dev/mapper/cs-root ro rd.lvm.lv=cs/root
[    0.150061] Unknown kernel command line parameters "BOOT_IMAGE=(hd0,msdos1)/vmlinuz-5.14.0-402.el9.x86_64", will be passed to user space.
[    3.366214]   BOOT_IMAGE=(hd0,msdos1)/vmlinuz-5.14.0-402.el9.x86_64
[    5.559567] sd 2:0:0:0: 251658240 512-byte logical blocks: (129 GB/120 GiB)
[    5.559645] sd 2:0:0:0: Write Protect is off
[    5.559647] sd 2:0:0:0: Mode Sense: 61 00 00 00
[    5.559754] sd 2:0:0:0: Cache data unavailable
[    5.559755] sd 2:0:0:0: Assuming drive cache: write through
[    5.569553]sda: sda1 sda2
[    5.569701] sd 2:0:0:0: Attached SCSI disk
[   25.628710] XFS (sda1): Mounting V5 Filesystem 33b3fa8b-f02c-409d-afc0-cccd91030610
[   31.721751] XFS (sda1): Ending clean mount
__ 注解 sda 表现第一块 SATA硬盘,sdb表现第二块SATA硬盘。若想检察IDE硬盘搜索hda或hdb关键词。__
只输出dmesg命令的前30行日记

在‘dmesg’命令后跟随‘head’命令来显示开始几行,‘dmesg | head -30′命令将显示开始的前20行
# dmesg | head -30
[    0.000000] Linux version 5.14.0-402.el9.x86_64 (mockbuild@x86-05.stream.rdu2.redhat.com) (gcc (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2), GNU ld version 2.35.2-42.el9) #1 SMP PREEMPT_DYNAMIC Thu Dec 21 19:46:35 UTC 2023
[    0.000000] The list of certified hardware and cloud instances for Red Hat Enterprise Linux 9 can be viewed at the Red Hat Ecosystem Catalog, https://catalog.redhat.com.
[    0.000000] Command line: BOOT_IMAGE=(hd0,msdos1)/vmlinuz-5.14.0-402.el9.x86_64 root=/dev/mapper/cs-root ro rd.lvm.lv=cs/root
[    0.000000] Disabled fast string operations
[    0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[    0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[    0.000000] x86/fpu: xstate_offset:576, xstate_sizes:256
[    0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'compacted' format.
[    0.000000] signal: max sigframe size: 1776
[    0.000000] BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: usable
[    0.000000] BIOS-e820: reserved
[    0.000000] BIOS-e820: reserved
[    0.000000] BIOS-e820: usable
[    0.000000] BIOS-e820: ACPI data
[    0.000000] BIOS-e820: ACPI NVS
[    0.000000] BIOS-e820: usable
[    0.000000] BIOS-e820: reserved
[    0.000000] BIOS-e820: reserved
[    0.000000] BIOS-e820: reserved
[    0.000000] BIOS-e820: reserved
[    0.000000] NX (Execute Disable) protection: active
[    0.000000] SMBIOS 2.7 present.
[    0.000000] DMI: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 11/12/2020
[    0.000000] vmware: hypercall mode: 0x02
[    0.000000] Hypervisor detected: VMware
[    0.000000] vmware: TSC freq read from hypervisor : 3600.000 MHz
[    0.000000] vmware: Host bus clock speed read from hypervisor : 66000000 Hz
[    0.000000] vmware: using clock offset of 26849061647 ns
只输出dmesg命令最后20行日记

在‘dmesg’命令后跟随‘tail’命令(‘ dmesg | tail -fn20’)来输出‘dmesg’命令的最后20行日记,当你插入可移动装备时它是非常有效的。
# dmesg | tail -fn 20
[   25.739895] vmwgfx 0000:00:0f.0: DMA map mode: Caching DMA mappings.
[   25.740440] vmwgfx 0000:00:0f.0: Legacy memory limits: VRAM = 4096 kB, FIFO = 256 kB, surface = 0 kB
[   25.740442] vmwgfx 0000:00:0f.0: MOB limits: max mob size = 262144 kB, max mob pages = 196608
[   25.740444] vmwgfx 0000:00:0f.0: Max GMR ids is 64
[   25.740445] vmwgfx 0000:00:0f.0: Max number of GMR pages is 65536
[   25.740446] vmwgfx 0000:00:0f.0: Maximum display memory size is 262144 kiB
[   25.766524] vmwgfx 0000:00:0f.0: Screen Target display unit initialized
[   25.770299] vmwgfx 0000:00:0f.0: Fifo max 0x00040000 min 0x00001000 cap 0x0000077f
[   25.770815] vmwgfx 0000:00:0f.0: Using command buffers with DMA pool.
[   25.770821] vmwgfx 0000:00:0f.0: Available shader model: Legacy.
[   25.845914] Initialized vmwgfx 2.20.0 20211206 for 0000:00:0f.0 on minor 0
[   25.852749] fbcon: vmwgfxdrmfb (fb0) is primary device
[   25.853553] Console: switching to colour frame buffer device 160x50
[   25.856173] vmwgfx 0000:00:0f.0: fb0: vmwgfxdrmfb frame buffer device
[   31.721751] XFS (sda1): Ending clean mount
[   36.632583] NET: Registered PF_VSOCK protocol family
[   47.484728] Warning: Unmaintained driver is detected: ip_set
[   47.484730] Warning: Deprecated Driver is detected: ip_set will not be maintained in a future major release and may be disabled
[   47.694148] vmxnet3 0000:03:00.0 ens160: intr type 3, mode 0, 2 vectors allocated
[   47.694537] vmxnet3 0000:03:00.0 ens160: NIC Link is Up 10000 Mbps
由于‘dmesg’命令的输出实在太长了,在此中搜索某个特定的字符串是非常困难的。因此,有须要过滤出一些包含‘usb’ ‘dma’ ‘tty’ ‘memory’等字符串的日记行。grep 命令 的‘-i’选项表现忽略巨细写
# dmesg | grep -i memory
[    0.009403] ACPI: Reserving FACP table memory at
[    0.009404] ACPI: Reserving DSDT table memory at
[    0.009405] ACPI: Reserving FACS table memory at
[    0.009405] ACPI: Reserving FACS table memory at
[    0.009406] ACPI: Reserving BOOT table memory at
[    0.009406] ACPI: Reserving APIC table memory at
[    0.009407] ACPI: Reserving MCFG table memory at
[    0.009407] ACPI: Reserving SRAT table memory at
[    0.009408] ACPI: Reserving HPET table memory at
[    0.009408] ACPI: Reserving WAET table memory at
[    0.009720] Early memory node ranges
[    0.026936] PM: hibernation: Registered nosave memory:
[    0.026938] PM: hibernation: Registered nosave memory:
[    0.026938] PM: hibernation: Registered nosave memory:
[    0.026939] PM: hibernation: Registered nosave memory:
[    0.026939] PM: hibernation: Registered nosave memory:
[    0.026940] PM: hibernation: Registered nosave memory:
[    0.026941] PM: hibernation: Registered nosave memory:
[    0.175052] Memory: 260860K/2096628K available (16384K kernel code, 5616K rwdata, 11640K rodata, 3872K init, 6008K bss, 156564K reserved, 0K cma-reserved)
[    0.697805] x86/mm: Memory block size: 128MB
[    1.961405] Non-volatile memory driver v1.3
[    2.915414] Freeing initrd memory: 35840K
[    3.269535] Freeing unused decrypted memory: 2028K
[    3.270606] Freeing unused kernel image (initmem) memory: 3872K
[    3.273128] Freeing unused kernel image (rodata/data gap) memory: 648K
[   25.740440] vmwgfx 0000:00:0f.0: Legacy memory limits: VRAM = 4096 kB, FIFO = 256 kB, surface = 0 kB
[   25.740446] vmwgfx 0000:00:0f.0: Maximum display memory size is 262144 kiB
显示时间戳

使用dmesg -T可以显示对应事故的时间戳。
https://img-blog.csdnimg.cn/direct/6a0dd3c1cc3a476dbfb1f7acc778c873.png#pic_center
人性化显示

使用dmesg -H指令,人性化显示信息,如下图所示。
https://img-blog.csdnimg.cn/direct/67d8441f302c45daa333f53401b9f87b.png#pic_center
过滤体系初始化时的错误信息

服务器在初始化启动和启动后运行的一段时间内,假如有对应的报错,会将报错信息进行收集,然后通过dmesg指令可以检察,如下。
# dmesg -T |grep-i 'error\|fail\|warn'
[一 1月 29 16:25:04 2024] pci 0000:00:15.3: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:15.4: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:15.5: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:15.6: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:15.7: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:16.3: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:16.4: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:16.5: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:16.6: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:16.7: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:17.3: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:17.4: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:17.5: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:17.6: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:17.7: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:18.2: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:18.3: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:18.4: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:18.5: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:18.6: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:18.7: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:18.7: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:18.6: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:18.5: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:18.4: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:18.3: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:18.2: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:17.7: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:17.6: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:17.5: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:17.4: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:17.3: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:16.7: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:16.6: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:16.5: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:16.4: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:16.3: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:15.7: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:15.6: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:15.5: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:15.4: BAR 13: failed to assign
[一 1月 29 16:25:04 2024] pci 0000:00:15.3: BAR 13: failed to assign
[一 1月 29 16:25:08 2024] Warning: Unmaintained driver is detected: mptbase
[一 1月 29 16:25:08 2024] Warning: Unmaintained driver is detected: mptscsih
[一 1月 29 16:25:08 2024] Warning: Unmaintained driver is detected: mptspi
[一 1月 29 16:25:50 2024] Warning: Unmaintained driver is detected: ip_set
[一 1月 29 16:25:50 2024] Warning: Deprecated Driver is detected: ip_set will not be maintained in a future major release and may be disabled


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: Linux云计算进阶-10条指令在1分钟内排查出服务器问题之dmesg篇