在 Linux 系统中,“日志时间同步”通常指两件事之一:
下面按常见场景说明。
大多数现代 Linux(CentOS 7+、Ubuntu 16.04+)使用 systemd-timesyncd 或 chrony / ntpd
timedatectl
timedatectl set-ntp true
timedatectl timesync-status
# CentOS / RHEL
yum install -y ntp
# Ubuntu / Debian
apt install -y ntp
systemctl enable ntpd
systemctl start ntpd
或(Ubuntu 新版):
systemctl enable ntp
systemctl start ntp
yum install -y chrony
systemctl enable chronyd
systemctl start chronyd
查看同步情况:
chronyc tracking
timedatectl
如果不是本地时区:
timedatectl set-timezone Asia/Shanghai
rsyslog / syslog:直接使用系统时间journald:使用系统时间只要系统时间同步,日志时间就同步。
server ntp.aliyun.com iburst
server cn.pool.ntp.org iburst
重启服务:
systemctl restart ntpd
date
journalctl -n
如果 date 不对,日志一定不对。
可能是:
Linux 日志时间同步 = 系统时间同步 + 时区统一 + NTP/chrony
如果你能告诉我:
我可以给你更精确的配置示例。