| 副标题[/!--empirenews.page--] 
 你可能设置过 cron 任务 来在特定时间备份重要文件或执行系统相关任务。也许你配置了一个日志服务器在特定时间间隔轮转日志。但如果你的时钟不同步,这些任务将无法按时执行。这就是要在  Linux 系统上设置正确的时区并保持时钟与互联网同步的原因。本指南介绍如何在 Ubuntu Linux 上设置时间同步。下面的步骤已经在  Ubuntu 18.04 上进行了测试,但是对于使用 systemd 的 timesyncd服务的其他基于 Ubuntu 的系统它们是相同的。 在 Ubuntu 上设置时间同步通常,我们在安装时设置时区。但是,你可以根据需要更改或设置不同的时区。 首先,让我们使用 date命令查看 Ubuntu 系统中的当前时区: $ date
 示例输出: Tue Jul 30 11:47:39 UTC 2019
 如上所见,date命令显示实际日期和当前时间。这里,我当前的时区是 UTC,代表协调世界时。 或者,你可以在 /etc/timezone文件中查找当前时区。 $ cat /etc/timezoneUTC
 现在,让我们看看时钟是否与互联网同步。只需运行: $ timedatectl
 示例输出: Local time: Tue 2019-07-30 11:53:58 UTCUniversal time: Tue 2019-07-30 11:53:58 UTCRTC time: Tue 2019-07-30 11:53:59Time zone: Etc/UTC (UTC, +0000)System clock synchronized: yessystemd-timesyncd.service active: yesRTC in local TZ: no
 如你所见,timedatectl命令显示本地时间、世界时、时区以及系统时钟是否与互联网服务器同步,以及systemd-timesyncd.service是处于活动状态还是非活动状态。就我而言,系统时钟已与互联网时间服务器同步。 如果时钟不同步,你会看到下面截图中显示的 System clock synchronized: no。 
 时间同步已禁用。 注意:上面的截图是旧截图。这就是你看到不同日期的原因。 如果你看到 System clock synchronized:值设置为no,那么timesyncd服务可能处于非活动状态。因此,只需重启服务并看下是否正常。 $ sudo systemctl restart systemd-timesyncd.service
 现在检查 timesyncd服务状态: $ sudo systemctl status systemd-timesyncd.service● systemd-timesyncd.service - Network Time SynchronizationLoaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)Active: active (running) since Tue 2019-07-30 10:50:18 UTC; 1h 11min agoDocs: man:systemd-timesyncd.service(8)Main PID: 498 (systemd-timesyn)Status: "Synchronized to time server [2001:67c:1560:8003::c7]:123 (ntp.ubuntu.com)."Tasks: 2 (limit: 2319)CGroup: /system.slice/systemd-timesyncd.service└─498 /lib/systemd/systemd-timesyncd Jul 30 10:50:30 ubuntuserver systemd-timesyncd[498]: Network configuration changed, trying to estabJul 30 10:50:31 ubuntuserver systemd-timesyncd[498]: Network configuration changed, trying to estabJul 30 10:50:31 ubuntuserver systemd-timesyncd[498]: Network configuration changed, trying to estabJul 30 10:50:32 ubuntuserver systemd-timesyncd[498]: Network configuration changed, trying to estabJul 30 10:50:32 ubuntuserver systemd-timesyncd[498]: Network configuration changed, trying to estabJul 30 10:50:35 ubuntuserver systemd-timesyncd[498]: Network configuration changed, trying to estabJul 30 10:50:35 ubuntuserver systemd-timesyncd[498]: Network configuration changed, trying to estabJul 30 10:50:35 ubuntuserver systemd-timesyncd[498]: Network configuration changed, trying to estabJul 30 10:50:35 ubuntuserver systemd-timesyncd[498]: Network configuration changed, trying to estabJul 30 10:51:06 ubuntuserver systemd-timesyncd[498]: Synchronized to time server [2001:67c:1560:800
 如果此服务已启用并处于活动状态,那么系统时钟应与互联网时间服务器同步。 你可以使用命令验证是否启用了时间同步: $ timedatectl
 如果仍然不起作用,请运行以下命令以启用时间同步: $ sudo timedatectl set-ntp true
 现在,你的系统时钟将与互联网时间服务器同步。 使用 timedatectl 命令更改时区如果我想使用 UTC 以外的其他时区怎么办?这很容易! (编辑:南平站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |