ubuntu设定时间与外部ntp同步

前言

在 Ubuntu 上,你可以通过配置 systemd-timesyncd 服务来与外部 NTP 服务器同步系统时间。下面是设置的步骤:

安装 NTP 工具:

如果你的系统中没有安装 ntpdate 工具,可以使用以下命令安装:

sudo apt-get update
sudo apt-get install -y ntpdate

停用 systemd-timesyncd 服务:


sudo systemctl stop systemd-timesyncd
sudo systemctl disable systemd-timesyncd

这是为了确保 ntpdate 和 systemd-timesyncd 不会同时运行。

设定本地时区

这是为了保证虽然时间同步了,时区不同而差几个小时。

sudo timedatectl set-timezone Asia/Shanghai

使用 ntpdate 同步时间:

选择一个可靠的 NTP 服务器,例如 time.google.com,并运行以下命令:

sudo ntpdate time1.cloud.tencent.com

这会立即将系统时间与所选 NTP 服务器同步。

配置 systemd-timesyncd:

打开 /etc/systemd/timesyncd.conf 文件:

sudo nano /etc/systemd/timesyncd.conf

确保文件中的 NTP 行未注释,并将其设置为所选的 NTP 服务器,例如:

[Time]
NTP=time1.cloud.tencent.com

保存并关闭文件。

启用并启动 systemd-timesyncd 服务:

sudo systemctl enable systemd-timesyncd
sudo systemctl start systemd-timesyncd

这将使 systemd-timesyncd 在系统启动时自动运行,并与所选的 NTP 服务器同步时间。

检查时间同步状态:

使用以下命令检查 systemd-timesyncd 服务的状态:

sudo systemctl status systemd-timesyncd

如果一切正常,你应该看到服务处于活动状态(active)且已同步时间。

现在,你的 Ubuntu 系统应该能够与外部 NTP 服务器同步时间。请确保你的计算机能够访问互联网,以便能够连接到所选的 NTP 服务器。

查看当前时间

date

相关推荐

  1. ubuntu设定时间外部ntp同步

    2024-01-13 02:10:08       55 阅读
  2. NTP时间同步服务器@客户端时钟同步设置

    2024-01-13 02:10:08       54 阅读
  3. Ubuntu设置时区和时间同步

    2024-01-13 02:10:08       53 阅读
  4. ubuntu同步网络时间

    2024-01-13 02:10:08       38 阅读
  5. Chrony工具强制NTP时间同步

    2024-01-13 02:10:08       60 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-13 02:10:08       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-13 02:10:08       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-13 02:10:08       82 阅读
  4. Python语言-面向对象

    2024-01-13 02:10:08       91 阅读

热门阅读

  1. 69、python - 利用向量内积来优化卷积运算

    2024-01-13 02:10:08       49 阅读
  2. 如何解决TCP拥塞问题?

    2024-01-13 02:10:08       61 阅读
  3. LeetCode878. Nth Magical Number

    2024-01-13 02:10:08       53 阅读
  4. vue3中el-table实现表格合计行

    2024-01-13 02:10:08       66 阅读
  5. [ECE]1.3 Basic logic operations

    2024-01-13 02:10:08       47 阅读
  6. 3 微信小程序

    2024-01-13 02:10:08       51 阅读
  7. 面试题-回溯算法解法模板

    2024-01-13 02:10:08       55 阅读
  8. 数据库面经---10则

    2024-01-13 02:10:08       60 阅读