g00*_*gle 16 linux unix debian time dmesg
我希望有人可以帮助我解决这个奇怪的问题。
我想我知道它为什么会发生,但我不知道如何解决它。也许是因为 BIOS 时间设置不正确或类似的原因。但我不想更改大约 400 多台服务器的 BIOS 时间。(或更换BIOS电池)
root@spool:~# echo TEST > /dev/kmsg
root@spool:~# dmesg -T | tail -1
[Mon Feb 17 04:57:03 2014] TEST
root@spool:~# date
Mon Feb 17 11:45:17 CET 2014
Run Code Online (Sandbox Code Playgroud)
服务器正在运行 ntp 以进行时间同步。
这里有人知道如何在操作系统中解决这个问题吗?
Linux spool 3.2.0-4-amd64 #1 SMP Debian 3.2.46-1+deb7u1 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)
为什么在回显到/dev/kmsg时,我的消息的日期/时间dmesg与系统日期/时间不同步?
小智 16
dmesg 只是打印内核环缓冲区,该缓冲区将消息记录为时间戳,以秒为单位的正常运行时间。
因此,如果您使用 -T 选项,所有这些正常运行时间值都会添加到您的系统启动日期。如果您有时间在挂起或恢复时休眠,它们就会丢失,因此在这种情况下 -T 选项没有用,因为日期/时间值当时和过去都不正确。
168*_*556 10
解决方法是使用journalctl 和-k, --dmesg。我使用 -k 因为它更短:
journalctl -k
Run Code Online (Sandbox Code Playgroud)
它只会显示内核消息和正确时间。
仅显示匹配短语的内核行:
journalctl -kg phrase
Run Code Online (Sandbox Code Playgroud)
要验证您的理论(顺便说一下,这是合理的),请以 root 身份执行以下操作:
hwclock --show
Run Code Online (Sandbox Code Playgroud)
这将显示您正在执行命令的服务器上的硬件时钟。
要将硬件时钟与系统时间(由 ntp 管理)同步,请运行以下命令:
hwclock --systohc --utc
Run Code Online (Sandbox Code Playgroud)
最后一个参数 (--utc) 告诉 hwclock 以协调世界时将时间存储在硬件时钟中。
此外,请记住 dmesg(1) 的手册页说明如下,因此您遇到的行为已记录在案且有效:
-T, --ctime
Print human-readable timestamps.
Be aware that the timestamp could be inaccurate! The time
source used for the logs is not updated after system
SUSPEND/RESUME.
Run Code Online (Sandbox Code Playgroud)
要获得 中“最近”条目的准确时间dmesg,您可以通过对输出进行一些黑客攻击将 dmesg 时间戳转换为实时。
“最近”是指上次挂起/恢复之后的时间,因为(正如其他人已经指出的那样)挂起时间不计入 dmesg 时间戳。
但是如果你经常需要它,比如在笔记本上,你可以将如下内容放入函数或别名中:
# write current time to kernel ring buffer so it appears in dmesg output
echo "timecheck: $(date +%s) = $(date +%F_%T)" | sudo tee /dev/kmsg
# use our "timecheck" entry to get the difference
# between the dmesg timestamp and real time
offset=$(dmesg | grep timecheck | tail -1 \
| perl -nle '($t1,$t2)=/^.(\d+)\S+ timecheck: (\d+)/; print $t2-$t1')
# pipe dmesg output through a Perl snippet to
# convert it's timestamp to correct readable times
dmesg | tail \
| perl -pe 'BEGIN{$offset=shift} s/^\[(\d+)\S+/localtime($1+$offset)/e' $offset
# or use this instead to keep dmesg colors
dmesg --color=always | tail \
| perl -pe 'BEGIN{$offset=shift} s/^(\x1b\[.*?m)?\[(\d+)\S+/$1.localtime($2+$offset)/e' $offset
Run Code Online (Sandbox Code Playgroud)
示例输出:
...
Sat Jun 29 11:12:28 2019 wlp3s0: Limiting TX power to 30 (30 - 0) dBm as advertised by 10:5a:f7:53:1d:0f
Sat Jun 29 11:12:28 2019 IPv6: ADDRCONF(NETDEV_CHANGE): wlp3s0: link becomes ready
Sat Jun 29 11:34:16 2019 timecheck: 1561800856 = 2019-06-29_11:34:16
Sat Jun 29 12:10:11 2019 wlp3s0: cannot understand ECSA IE operating class, 5, ignoring
Run Code Online (Sandbox Code Playgroud)
与原始dmesg输出(关闭 3 天)相比:
$ dmesg | tail -4
[249424.746958] wlp3s0: Limiting TX power to 30 (30 - 0) dBm as advertised by 10:5a:f7:53:1d:0f
[249424.749662] IPv6: ADDRCONF(NETDEV_CHANGE): wlp3s0: link becomes ready
[250732.318826] timecheck: 1561800856 = 2019-06-29_11:34:16
[252887.828699] wlp3s0: cannot understand ECSA IE operating class, 5, ignoring
$ dmesg -T | tail -4
[Wed Jun 26 17:59:09 2019] wlp3s0: Limiting TX power to 30 (30 - 0) dBm as advertised by 10:5a:f7:53:1d:0f
[Wed Jun 26 17:59:09 2019] IPv6: ADDRCONF(NETDEV_CHANGE): wlp3s0: link becomes ready
[Wed Jun 26 18:20:57 2019] timecheck: 1561800856 = 2019-06-29_11:34:16
[Wed Jun 26 18:56:52 2019] wlp3s0: cannot understand ECSA IE operating class, 5, ignoring
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13225 次 |
| 最近记录: |