Ubuntu 24.04 LTS系统上配置国内时间同步

以下是在Ubuntu 24.04 LTS系统上配置时间同步到中国NTP服务器的详细步骤:

1. 确认系统版本

首先验证系统版本,确保为Ubuntu 24.04 LTS:

bash 复制代码
lsb_release -a
# 输出应显示:Ubuntu 24.04 LTS

2. 检查timesyncd服务状态

Ubuntu 24.04默认使用systemd-timesyncd进行时间同步,检查其状态:

bash 复制代码
sudo systemctl status systemd-timesyncd
  • 若服务未运行,使用以下命令启动并设置开机自启:

    bash 复制代码
    sudo systemctl enable --now systemd-timesyncd

3. 配置中国NTP服务器

编辑配置文件 /etc/systemd/timesyncd.conf

bash 复制代码
sudo nano /etc/systemd/timesyncd.conf

修改或添加以下内容(推荐使用中国境内NTP服务器):

ini 复制代码
[Time]
NTP=ntp.aliyun.com ntp.tencent.com ntp.ntsc.ac.cn time1.cloud.tencent.com
FallbackNTP=0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org 3.pool.ntp.org
RootDistanceMaxSec=5
PollIntervalMinSec=32
PollIntervalMaxSec=2048
  • 常用中国NTP服务器
    • ntp.aliyun.com(阿里云)
    • ntp.tencent.com(腾讯云)
    • ntp.ntsc.ac.cn(中国科学院国家授时中心)
    • time1.cloud.tencent.com(腾讯云备用)

4. 重启timesyncd服务

bash 复制代码
sudo systemctl restart systemd-timesyncd

5. 验证时间同步状态

bash 复制代码
timedatectl status

预期输出示例

复制代码
               Local time: 三 2024-05-15 14:30:00 CST
           Universal time: 三 2024-05-15 06:30:00 UTC
                 RTC time: 三 2024-05-15 06:30:00
                Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
  • 关键检查项:
    • System clock synchronized: yes → 已成功同步
    • NTP service: active → NTP服务正常运行

6. 检查NTP服务器连接

bash 复制代码
timedatectl timesync-status

预期输出示例

复制代码
       Server: 203.107.6.88 (ntp.aliyun.com)
Poll interval: 32s (min: 32s; max: 2048s)
         Leap: normal
      Version: 4
      Stratum: 2
    Reference: 8C017B54
    Precision: 1us (-25)
Root distance: 28.820ms (max: 5s)
       Offset: -23.474ms
        Delay: 37.481ms
       Jitter: 11.525ms
 Packet count: 12

7. 设置时区(可选)

若时区未自动设置为中国时区(Asia/Shanghai),执行:

bash 复制代码
sudo timedatectl set-timezone Asia/Shanghai

8. 防火墙配置(如启用)

确保UDP 123端口开放:

bash 复制代码
sudo ufw allow 123/udp

故障排查

  1. 检查日志

    bash 复制代码
    journalctl -u systemd-timesyncd -b
  2. 手动触发同步

    bash 复制代码
    sudo systemd-timesyncd --force-refresh
  3. 使用替代工具
    若问题持续,可安装chrony替代:

    bash 复制代码
    sudo apt install chrony
    sudo systemctl disable --now systemd-timesyncd
    sudo systemctl enable --now chrony

通过以上步骤,您的Ubuntu 24.04系统将准确同步到中国的NTP服务器,并显示正确的北京时间(CST)。

相关推荐
AII_IIA38 分钟前
Ubuntu误删libaudit.so.1 导致系统无法正常使用、崩溃
linux·ubuntu·selinux·audit·libaudit
---学无止境---41 分钟前
Linux内存映射构建艺术:VMA链接与管理的深度剖析
linux
MarcoPage3 小时前
Python 字典推导式入门:一行构建键值对映射
java·linux·python
未来之窗软件服务4 小时前
服务器运维(六)跨域配置 Preflight 问题——东方仙化神期
运维·服务器·服务器运维·仙盟创梦ide·东方仙盟
埃伊蟹黄面4 小时前
计算机的“身体”与“灵魂”:冯·诺依曼架构与操作系统
linux
AORO20255 小时前
智能三防手机哪款好?22000mAh+夜视+露营灯打造专业户外装备
服务器·网络·智能手机·电脑·1024程序员节
winner88816 小时前
Linux 软件安装 “命令密码本”:yum/apt/brew 一网打尽
linux·运维·服务器
九河云6 小时前
软件开发平台 DevCloud
运维·服务器·数据库·科技·华为云
firstacui6 小时前
DNS高速缓存&分离解析
服务器
思麟呀7 小时前
Linux的基础IO流
linux·运维·服务器·开发语言·c++