RTC没有时区--实际案例

概要

前述已有三篇文章介绍了RTC没有时区,此文用实际案例来说明一起RTC设置对于系统启动时的时间戳的影响。

案例

Jun 26 16:14:15 localhost journal: Avahi client failure: Daemon connection failed
Jun 26 16:14:15 localhost systemd: Stopping OpenSSH server daemon...
Jun 26 16:14:15 localhost systemd: Stopping ABRT kernel log watcher...
Jun 26 16:14:15 localhost systemd: Stopped Daily Cleanup of Temporary Directories.
Jun 26 16:14:15 localhost systemd: Stopped Resets System Activity Logs.
Jun 26 16:14:15 localhost systemd: Stopping GNOME Display Manager...
Jun 26 16:14:15 localhost systemd: Stopping VDO volume services...
Jun 26 16:14:15 localhost systemd: Stopping irqbalance daemon...
Jun 27 00:15:47 localhost kernel: Initializing cgroup subsys cpuset
Jun 27 00:15:47 localhost kernel: Initializing cgroup subsys cpu
Jun 27 00:15:47 localhost kernel: Initializing cgroup subsys cpuacct
Jun 27 00:15:47 localhost kernel: Linux version 3.10.0-1160.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Mon Oct 19 16:18:59 UTC 2020
Jun 27 00:15:47 localhost kernel: Command line: BOOT_IMAGE=/vmlinuz-3.10.0-1160.el7.x86_64 root=/dev/mapper/centos-root ro crashkernel=auto spectre_v2=retpoline rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=en_US.UTF-8
Jun 27 00:15:47 localhost kernel: e820: BIOS-provided physical RAM map:
Jun 27 00:15:47 localhost kernel: BIOS-e820: [mem 0x0000000000000000-0x000000000009ffff] usable
Jun 27 00:15:47 localhost kernel: BIOS-e820: [mem 0x00000000000a0000-0x00000000000fffff] reserved
Jun 27 00:15:47 localhost kernel: BIOS-e820: [mem 0x0000000000100000-0x00000000a5c03fff] usable

Jun 26 16:15:52 localhost systemd[1]: RTC configured in localtime, applying delta of 480 minutes to system time.

案例分析

1、从linux系统日志可看到,系统在20230621 10:51发生了重启,但系统重启时候时间戳比原机器时间多了8个小时。
2、等系统起来后,从日志可看到时间恢复正常。
原因有两点:
1、该机器的RTC被设置为了localtime,因此系统的时间跟RTC的时间在数值上是相同的。如下所示:
[root@localhost ~]# timedatectl
Local time: Mon 2023-06-26 18:18:59 CST
Universal time: Mon 2023-06-26 10:18:59 UTC
RTC time: Mon 2023-06-26 18:18:59
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: yes
DST active: n/a

Warning: The system is configured to read the RTC time in the local time zone.
This mode can not be fully supported. It will create various problems
with time zone changes and daylight saving time adjustments. The RTC
time is never updated, it relies on external facilities to maintain it.
If at all possible, use RTC in UTC by calling
'timedatectl set-local-rtc 0'.
2、当linux系统启动时(这个时候可以理解系统的时间服务还未完全启动),linux系统仍然会认为RTC为UTC,所以linux系统在启动之前的时间戳在RTC的时间数值上+8,体现在日志上就是时间多了8个小时。
3、等待系统完全启动后,linux系统时间服务已经起来,这个时候linux系统知道了应该把RTC认为localtime,所以系统时间恢复正常。见如下日志条目:
Jun 26 16:15:52 localhost systemd[1]: RTC configured in localtime, applying delta of 480 minutes to system time.
4、8*60minutes=480minutes。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容