文档
检查时区/时间
# 查看时区/时间
timedatectl
# 结果示例
root@xuxiaowei-pc:~# timedatectl
Local time: 四 2025-02-27 20:08:23 CST
Universal time: 四 2025-02-27 12:08:23 UTC
RTC time: 四 2025-02-27 20:08:24
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
root@xuxiaowei-pc:~#
安装
# yum
sudo yum -y install ntpdate
# apt
sudo apt -y install ntpdate
启动
# 启动
sudo systemctl start ntpdate.service
sudo systemctl enable ntpdate.service
# 重启
sudo systemctl restart ntpdate.service
手动同步时间
# 手动同步时间
ntpdate ntp.aliyun.com
# ntpdate ntp1.aliyun.com
其他命令
| 名称 |
命令 |
说明 |
| 修改时区 |
sudo timedatectl set-timezone Asia/Shanghai |
|
RTC(实时时钟)设置为 UTC 时间 |
sudo timedatectl set-local-rtc 0 |
避免由于时区变化或夏令时调整引起的问题 |