大多数现代Linux发行版使用systemd-timesyncd
或chrony
/ntp
作为时间同步服务。
# 查看时间同步状态
timedatectl status
# 启用时间同步服务
sudo timedatectl set-ntp true
# 禁用时间同步服务
sudo timedatectl set-ntp false
# 安装chrony(如未安装)
sudo yum install chrony # RHEL/CentOS
sudo apt install chrony # Debian/Ubuntu
# 启动并启用服务
sudo systemctl enable --now chronyd
# 检查同步状态
chronyc tracking
chronyc sources -v
# 安装ntp
sudo yum install ntp # RHEL/CentOS
sudo apt install ntp # Debian/Ubuntu
# 启动并启用服务
sudo systemctl enable --now ntpd
# 检查同步状态
ntpq -p
# 使用ntpdate手动同步(需要先停止ntp服务)
sudo systemctl stop ntpd
sudo ntpdate pool.ntp.org
sudo systemctl start ntpd
# 或者使用chronyc强制同步
sudo chronyc -a makestep
timedatectl
# 或
date
# 或查看/etc/localtime链接
ls -l /etc/localtime
timedatectl list-timezones
# 可以配合grep搜索,例如查找亚洲时区
timedatectl list-timezones | grep Asia
sudo timedatectl set-timezone Asia/Shanghai
sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
sudo dpkg-reconfigure tzdata
# 将硬件时钟设置为本地时间(通常Windows使用)
sudo timedatectl set-local-rtc 1
# 将硬件时钟设置为UTC时间(通常Linux使用)
sudo timedatectl set-local-rtc 0
# 同步系统时间到硬件时钟
sudo hwclock --systohc
时间同步失败:
cn.pool.ntp.org
)时区更改后时间不正确:
/etc/localtime
链接正确双系统时间不一致:
sudo timedatectl set-local-rtc 1 --adjust-system-clock
RealTimeIsUniversal
DWORD值为1通过以上设置,您的Linux系统应该能够保持准确的时间和正确的时区设置。