Loading... #### 概述 在日常巡检中发现系统日志和java服务日志与系统时间不一致问题。 #### 解决思路 ##### 查看时区是否异常 ```shell [root@46 phase2]# date -R Mon, 09 Aug 2021 10:24:24 +0800 [root@46 phase2]# timedatectl Local time: 一 2021-08-09 10:24:34 CST Universal time: 一 2021-08-09 02:24:34 UTC RTC time: 一 2021-08-09 02:24:34 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: yes NTP synchronized: yes RTC in local TZ: no DST active: n/a ``` 如时区不为+0800则替换配置 ```shell ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ``` ##### 系统日志时间不一致 查看/var/log/messages 日志内容发现时间与系统时间不一致 ```shell Aug 9 02:06:58 46 dbus-daemon: dbus[991]: [system] Activating via systemd: service name='org.freedesktop.timedate1' unit='dbus-org.freedesktop.timedate1.service' Aug 9 02:06:58 46 dbus[991]: [system] Activating via systemd: service name='org.freedesktop.timedate1' unit='dbus-org.freedesktop.timedate1.service' Aug 9 02:06:58 46 systemd: Starting Time & Date Service... Aug 9 02:06:59 46 dbus[991]: [system] Successfully activated service 'org.freedesktop.timedate1' Aug 9 02:06:59 46 dbus-daemon: dbus[991]: [system] Successfully activated service 'org.freedesktop.timedate1' Aug 9 02:06:59 46 systemd-timedated: /etc/localtime should be a symbolic link to a time zone data file in /usr/share/zoneinfo/. Aug 9 02:06:59 46 systemd: Started Time & Date Service. Aug 9 02:07:50 46 systemd: Starting Time & Date Service... Aug 9 02:07:50 46 systemd-timedated: /etc/localtime should be a symbolic link to a time zone data file in /usr/share/zoneinfo/. Aug 9 02:07:50 46 systemd: Started Time & Date Service. [root@46 ~]# date 2021年 08月 09日 星期一 10:22:25 CST ``` 重启系统日志服务 ```shell systemctl restart rsyslog ``` ##### java服务日志时间异常 查看java服务进程日志时间也不一致,新建或修改/etc/sysconfig/clock配置为如下内容: ```shell # The time zone of the system is defined by the contents of /etc/localtime. # This file is only for evaluation by system-config-date, do not rely on its # contents elsewhere. ZONE="Asia/Shanghai" UTC=false ARC=false ``` 重启系统后正常。 最后修改:2022 年 09 月 16 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏