Linux/Ubuntu 系统日志中找出系统关闭/关机的原因

编程教程 > Linux (136) 2024-11-26 14:39:04

有时候服务器运行的好好的,突然就无法连接无法执行任何操作了,强制重启后需要通过系统日志排查系统故障的原因

只有root特权程序才能正常关闭系统。因此,当系统以正常方式关闭时,它要么是具有root特权的用户,要么是acpi脚本。在这两种情况下,我们都可以通过检查日志来查找。按下电源按钮,过热或电池电量不足(笔记本电脑)可能会导致acpi关闭。
1、首先尝试以下命令
 

last reboot |less  #显示最近的重启条目列表
last -x |less #显示最近关闭的条目列表

last -x | grep shutdown|less

2、检查last -x 命令的输出

last -x |head |tac

 

正常关机实例
正常关闭和家电如下所示

runlevel (to lvl 3)   3.10.0-1160.el7. Mon Aug 29 17:00 - 17:00  (00:00)    
shutdown system down  3.10.0-1160.el7. Mon Aug 29 17:00 - 17:01  (00:00)    
reboot   system boot  3.10.0-1160.el7. Mon Aug 29 17:01 - 14:42 (14+21:41)  
runlevel (to lvl 3)   3.10.0-1160.el7. Mon Aug 29 17:01 - 14:42 (14+21:41) 

 

3、意外关机示例

reboot   system boot  3.10.0-1127.19.1 Sun Sep 11 01:31 - 14:40 (2+13:09)   
runlevel (to lvl 3)   3.10.0-1127.19.1 Sat Sep 10 17:31 - 14:40 (2+21:09) 

检查/vat/log/中的日志
一个bash命令来过滤日志

grep -iv ': starting\|kernel: .*: Power Button\|watching system buttons\|Stopped Cleaning Up\|Started Crash recovery kernel' \
/root/messages /var/log/syslog /var/log/apcupsd* \
| grep -iw 'recover[a-z]*\|power[a-z]*\|shut[a-z ]*down\|rsyslogd\|ups'

当意外关闭电源或发生硬件故障时,文件系统将无法正确卸载,因此在下次启动时,可能会输出如下日志

[    3.238424] IPVS: [rr] scheduler registered.
[    3.475768] systemd-journald[479]: Received request to flush runtime journal from PID 1
[    3.483416] systemd-journald[479]: File /var/log/journal/20200914151306980406746494236010/system.journal corrupted or uncleanly shut down, renaming and re
[    3.483812] piix4_smbus 0000:00:01.3: SMBus Host Controller at 0x700, revision 0

当按下电源按钮而关闭系统电源时,将输出以下日志

systemd-logind: Power key pressed.
systemd-logind: Powering Off...
systemd-logind: System is powering down.

当按下电源按钮而关闭系统电源时,将输出以下日志

systemd-logind: Power key pressed.
systemd-logind: Powering Off...
systemd-logind: System is powering down.

当服务器正常关闭时,将会输出以下日志

rsyslogd: ... exiting on signal 15

当系统因为温度过高导致关闭时,将会输出以下日志

critical temperature reached...,shutting down

如果您有UPS并运行守护程序来监视电源和关闭电源,则显然应该检查其日志(NUT日志位于/ var / log / messages,但apcupsd日志位于/ var / log / apcupsd *)

4、last 手册中的描述

last [...] prints information about connect times of users. 
Records are printed from most recent to least recent.  
[...]
The special users reboot and shutdown log in when the system reboots
or (surprise) shuts down. 

我们head用来保留最近的10个事件,并tac用来颠倒顺序,这样我们就不会为最近事件到最近事件的最后打印感到困惑。

5、一些可能的日志文件可供探索

/var/log/debug
/var/log/syslog (will be pretty full and may be harder to browse)
/var/log/user.log
/var/log/kern.log
/var/log/boot

6、我这里发现的原因是:

systemd-journald[479]: File /var/log/journal/....../system.journal corrupted or uncleanly shut down, renaming and replacing.

是由于底层宿主机软硬件故障导致的系统崩溃


评论
User Image
提示:请评论与当前内容相关的回复,广告、推广或无关内容将被删除。

相关文章
有时候服务器运行的好好的,突然就无法连接无法执行任何操作了,强制重启后需要通过系统日志排查系统故障的原因只有root特权程序才能正常关闭系统。因此,当系统以正常
开启crontab日志默认情况大多数系统都是没有开启cron的日志的。编辑配置文件sudo vim /etc/rsyslog.d/50-default.conf
Ubuntu系统或者Linux系统都应该保证软件更新到最新,以减少软件漏洞导致服务器风险。Ubuntu系统更新软件主要分两步。第一步:更新软件源信息该操作只会更新软件最新的信息到本地,不会下载和安装。
ubuntu 禁用/启用防火墙iptablesUbuntu查看防火墙状态命令sudo ufw status Status: activeactive  -  启用inactive - 停用Ub...
Ubuntu 硬盘分区扩容命令进行磁盘操作时请务必备份数据!!!事情是这样的,服务器系统盘是块 120GB 的 SSD,当时装系统的时候只给了 50GB,还剩下
Linux(centos)系统远程(SSH)登录输入错误密码多次锁定账号时间PAM实现方式
ubuntu 配置sudo不需要输入密码Ubuntu单用用户配置sudo vi /etc/sudoers在打开文件的最下方添加以下行内容:ubuntu ALL=
Ubuntu 20.04 安装netstat工具sudo apt install net-tools安装完成后即可使用netstat命令ubuntu@test-1:~$ sudo netstat...
Ubuntu 20.04 更换国内apt源第一步:备份源文件:sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup第二步:编辑/e...
错误描述pve8或ubuntu fail2ban 无法启动 Have not found any log file for sshd jail导致原因没有找到s
Alpine Linux 分区扩容切换国内源(已经操作则忽略该步骤)echo "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/main/" &g...
一、ubuntu14.04版本1、配置静态IP地址:ubuntu(乌班图)各版本(14、16、18、20、22、23)网卡静态IP地址及DNS设置大全 - 哔哩
1.通过文件名查找文件语法:sudo find 目录 -name '*特定字符串*'sudo 根据查询文件目录归属看是否加示例:find ./ -name '*
ubuntu / centos 高版本 均可参考临时生效命令sudo hostname your-hostname重启失效 永久生效 sudo hostname
Linux crontab常用表达式查看crontab任务crontab -l编辑crontab任务crontab -e每隔多少秒执行一次脚本* * * * * sleep 10; /bin/y...