如何解决部分镜像实例切换后系统时区配置有误问题

更新时间:
复制 MD 格式

问题现象

在整机克隆成新ECS、VMware云上恢复成ECS后,部分镜像的实例系统时间存在异常。

可能原因

在整机克隆成新ECS、VMware云上恢复成ECS后,部分镜像实例系统会默认使用localtime(非UTC)作为本地时区,该配置导致系统时间异常。

解决方案

登录切换后实例,将RTC in local TZ取值修改为no

  1. 登录切换后的实例。
  2. 执行timedatectl查询系统时间配置。
    如果RTC in local TZ取值为yes,则执行timedatectl set-local-rtc 0命令将RTC in local TZ取值修改为no
    [root@mysql ~]# timedatectl
          Local time: Mon 2023-02-20 06:30:23 UTC
      Universal time: Mon 2023-02-20 06:30:23 UTC
            RTC time: Mon 2023-02-20 06:30:23
           Time zone: Asia/Shanghai (UTC, +0000)
         NTP enabled: yes
    NTP synchronized: yes
     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'.
    [root@mysql ~]# timedatectl set-local-rtc 0
    [root@mysql ~]# timedatectl
          Local time: Mon 2023-02-20 06:30:58 UTC
      Universal time: Mon 2023-02-20 06:30:58 UTC
            RTC time: Mon 2023-02-20 06:30:58
           Time zone: Asia/Shanghai (UTC, +0000)
         NTP enabled: yes
    NTP synchronized: yes
     RTC in local TZ: no
          DST active: n/a