CentOS7.X时间调整为系统时间之后,重新开机就无效了


0. 原因分析

  • 系统时区非上海
  • 没有同步网络时间

1. 时间修改

  • 查看虚拟机系统时间
[root@node01 ~]$ timedatectl
Local time: 日 2022-09-18 10:22:31 GMT
Universal time: 日 2022-09-18 10:22:31 UTC
RTC time: 日 2022-09-18 10:22:31
Time zone: Atlantic/Reykjavik (GMT, +0000)
NTP enabled: n/a
NTP synchronized: no
RTC in local TZ: no
DST active: n/a

此处为​​Atlantic/Reykjavik​​不是​​上海时区​​,需要更改

[root@node01 ~]$ timedatectl set-timezone Asia/Shanghai
  • 再次查询时间
[root@node01 ~]$ timedatectl
Local time: 日 2022-09-18 18:36:25 CST
Universal time: 日 2022-09-18 10:36:25 UTC
RTC time: 日 2022-09-18 10:36:25
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: n/a
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
  • 查看系统时区
[root@node01 ~]$ ls /usr/share/zoneinfo/
Africa Atlantic Chile Eire GB GMT+0 Indian Japan Mexico NZ-CHAT posixrules ROK Universal zone1970.tab
America Australia CST6CDT EST GB-Eire Greenwich Iran Kwajalein MST Pacific PRC Singapore US zone.tab
Antarctica Brazil Cuba EST5EDT GMT Hongkong iso3166.tab leapseconds MST7MDT Poland PST8PDT Turkey UTC Zulu
Arctic Canada EET Etc GMT0 HST Israel Libya Navajo Portugal right tzdata.zi WET
Asia CET Egypt Europe GMT-0 Iceland Jamaica MET NZ posix ROC UCT W-SU
  • 替换系统时区
[root@node01 ~]$ ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  • 同步网络时间

需要提前安装ntp时间服务器

# 安装ntpdate
[root@node01 ~]$ yum install -y ntpdate
# 同步时间
[root@node01 ~]$ ntpdate asia.pool.ntp.org
# 为了校对网络时间,将ntpdate服务设置为自启动,
[root@node01 ~]$ systemctl enable ntpdate.service
#启动ntp服务
[root@node01 ~]$ service ntpd restart
#查看时间
[root@node01 ~]$ timedatectl

2. 参考

​https://cxymm.net/article/wngpenghao/117027687​