当前位置:网站首页>查看服务器重启前的 dmesg 日志
查看服务器重启前的 dmesg 日志
2022-07-27 06:10:00 【TechForGeek】
注: 文章中的示例代码都在 Ubuntu 系统中执行,其他 Linux 发行版操作类似。
场景描述
在日常的运维工作中,不可避免的会遇到服务器故障的问题。虽然在应用运维或SRE岗,不必亲自去维修服务器,但是有必要去排查导致问题的原因,以便后续提交报修工单。
在各种类型的服务器故障中,有一种是这样的:
某一天,服务器突然无法登录,服务器重启后又恢复正常。
服务器重启恢复正常后,我们登录到服务器上,需要去判断这次故障是否是由于硬件问题导致的,如果是硬件有问题的话,通常会在 dmesg 日志中有所体现。
问题是,每次服务器重启之后,登录到机器上执行 dmesg 命令,都只能展示本次重启后的日志,重启之前的日志就看不到了。而我们为了排查服务器故障的原因,就必须要看到重启之前的 dmesg 日志。
Ubuntu < 15.04
现在使用小于 Ubuntu 15.04 版本的人应该很少了,不过如果你在使用这些旧的 Ubuntu 系统的话,在你的 /var/log/ 目录下,会有如下名称的日志文件:
dmesg
dmesg.0
dmesg.1.gz
...dmesg 日志文件中保存的是本次重启后的日志,而 dmesg.0 是这次重启前的 dmesg 日志,dmesg.1.gz 是上次重启前的 dmesg 日志,依次类推。
通过查看 dmesg.0 日志文件中的内容,就可以看到服务器重启前的 dmesg 日志了。
Ubuntu >= 15.04
现在更多人用的 Ubuntu 应该是 15.04 以后的版本了。Ubuntu 从 15.04 开始使用 systemd, systemd 中有一个日志服务,名为 journald,通过命令行工具 journalctl 可以方便的获取 journald 记录下来的日志,这其中就包括 dmesg 日志。
要查看服务器重启前的 dmesg 日志,可以使用如下命令:
journalctl -k -b -1-k: 表示要查看 dmesg 日志
-b -1: 表示查看服务器重启前的日志
结束语
排查服务器故障时,dmesg 日志是一个很有用的信息源。如果你使用的是 Ubuntu 15.04 之前的系统,/var/log/dmesg.0 就是重启前的 dmesg 日志;如果你用的时 Ubuntu 15.04 之后的系统,通过 journalctl 命令你可以很方便地查看到服务器重启前的 dmesg 日志。
一如既往,如果你对文章中的内容有任何疑问,或者是发现文章中有任何错误,都可以通过留言告诉我;如果你喜欢我的文章,欢迎关注我的微信公众号 Tech For Geek。
边栏推荐
- Misunderstanding of slice slice in golang
- jjwt 生成token
- Calledprocesserror during pre commit install
- Student achievement management system based on SSM
- C time related operation
- Digital image processing Chapter 1 Introduction
- Codeforces Round #809 (Div. 2)(6/6)(Kruskal重构树)
- 从技术原理看元宇宙的可能性:Omniverse如何“造”火星
- Codeworks round 809 (Div. 2) (6/6) (Kruskal reconstruction tree)
- pre-commit install 时 CalledProcessError
猜你喜欢

Esp8266 (esp-12f) third party library use -- sparkfun_ Apds9960 (gesture recognition)

Watermelon book chapter 3 - linear model learning notes

整体二分?

Digital image processing -- Chapter 3 gray scale transformation and spatial filtering

How to learn C language? This article gives you the complete answer

pytorch笔记:TD3

Visual horizontal topic bug1:filenotfounderror: could not find module 'mvcameracontrol dll‘ (or one of it

Generics -- learn it, and there are many benefits

Firefox browser, when accessing Tencent cloud server, failed to establish a secure connection.

Jmeter:接口自动化测试-BeanShell对数据库数据和返回数据比较
随机推荐
pre-commit install 时 CalledProcessError
Interpretation of deepsort source code (III)
Digital image processing -- Chapter 3 gray scale transformation and spatial filtering
What is OKR and what is the difference between OKR and KPI
Digital image processing Chapter 1 Introduction
Watermelon book learning Chapter 5 --- neural network
Quartus:往别人的工程添加.v文件报错
Interpretation of deepsort source code (6)
Word wrap: break word line feed is compatible with browsers
MySQL limit paging query optimization practice
Working principle analysis of deepsort
Convert Excel to csv/csv UTF-8
Which C4d cloud rendering platform to cooperate with?
VIM editor deletes all file contents
Common problems in converting pytorch to onnx
Digital image processing - Chapter 6 color image processing
Gbase 8C core technology
Campus news release management system based on SSM
[latex format] there are subtitles side by side on the left and right of double columns and double pictures, and subtitles are side by side up and down
Pan Aimin, chairman of instruction set, attended the 2022 ecug con to speak for China's technical forces