AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1046214
Accepted
BEWARB
BEWARB
Asked: 2018-06-14 04:43:36 +0800 CST2018-06-14 04:43:36 +0800 CST 2018-06-14 04:43:36 +0800 CST

启用系统时钟同步

  • 772

'timedatectl' 给出以下输出 -

                      Local time: Wed 2018-06-13 18:08:51 IST
                  Universal time: Wed 2018-06-13 12:38:51 UTC
                        RTC time: Wed 2018-06-13 12:38:51
                       Time zone: Asia/Kolkata (IST, +0530)
       System clock synchronized: no
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

如何将系统时钟同步设置为是?

time 18.04
  • 8 8 个回答
  • 96318 Views

8 个回答

  • Voted
  1. Max Robbertze
    2019-01-02T04:44:58+08:002019-01-02T04:44:58+08:00

    无需像这样部署 NTP 即可完成:

    sudo nano /etc/systemd/timesyncd.conf  
    

    编辑 NTP 服务器详细信息

    [Time]
    NTP=ur.ntp.srv
    FallbackNTP=ur.fallbackntp.srv
    

    然后

    sudo systemctl daemon-reload
    sudo timedatectl set-ntp off
    sudo timedatectl set-ntp on
    

    你可以检查一下

    timedatectl status
    
    • 34
  2. Best Answer
    Terrance
    2018-06-14T04:58:26+08:002018-06-14T04:58:26+08:00

    一种方法是使用ntp在 Ubuntu 18.04 中仍然有效的方法。运行以下命令进行安装ntp。

    sudo apt install ntp
    

    安装后,您可以运行ntpq -p以确保它正常工作。

    ~$ ntpq -p
         remote           refid      st t when poll reach   delay   offset  jitter
    ==============================================================================
     0.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
     1.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
     2.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
     3.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
     ntp.ubuntu.com  .POOL.          16 p    -   64    0    0.000    0.000   0.000
    

    然后在您的/etc/crontab文件中添加@reboot root /usr/sbin/ntpd -n,以便ntpd在系统重新启动时自动启动。使用你最喜欢的编辑器gedit,或者mousepad你喜欢的任何东西:

    pkexec gedit /etc/crontab
    

    添加该行时,它应该看起来像这样:

    # /etc/crontab: system-wide crontab
    # Unlike any other crontab you don't have to run the `crontab'
    # command to install the new version when you edit this file
    # and files in /etc/cron.d. These files also have username fields,
    # that none of the other crontabs do.
    
    SHELL=/bin/sh
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    
    # m h dom mon dow user  command
    17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
    25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
    47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
    52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
    @reboot     root    /usr/sbin/ntpd -n
    #
    

    然后重新启动计算机以使设置生效。

    ~$ timedatectl status
                          Local time: Wed 2018-06-13 06:55:35 MDT
                      Universal time: Wed 2018-06-13 12:55:35 UTC
                            RTC time: Wed 2018-06-13 12:55:36
                           Time zone: America/Denver (MDT, -0600)
           System clock synchronized: yes
    systemd-timesyncd.service active: yes
                     RTC in local TZ: no
    

    如果您想将您的服务器更改为Asia Pool服务器,请将它们添加到文件的# Use servers from the NTP Pool Project.部分,/etc/ntp.conf如下所示:

    # Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
    # on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
    # more information.
    server 0.asia.pool.ntp.org
    server 1.asia.pool.ntp.org
    server 2.asia.pool.ntp.org
    server 3.asia.pool.ntp.org
    

    希望这可以帮助!

    • 19
  3. tgogos
    2019-06-13T01:23:34+08:002019-06-13T01:23:34+08:00

    以下对我有用:

    timedatectl set-ntp true
    

    接着...

    systemctl restart systemd-timesyncd
    

    例子:

    在此处输入图像描述

    • 13
  4. teuber789
    2019-10-25T18:02:49+08:002019-10-25T18:02:49+08:00

    对于在 AWS EC2 实例上使用 Ubuntu 18+ 的用户,我发现这非常有效。它利用 AWS 的内部时间同步服务:

    sudo apt install chrony
    sudo nano /etc/chrony/chrony.conf
    

    在任何其他服务器条目之前添加以下行:

    server 169.254.169.123 prefer iburst minpoll 4 maxpoll 4
    

    接着

    sudo /etc/init.d/chrony restart
    

    对于 EC2 实例,这种方法最好的部分是您不必修改安全组规则,即使您的实例未连接到 Internet :)

    资源

    • 8
  5. user973021
    2019-08-05T11:48:23+08:002019-08-05T11:48:23+08:00

    一个不完全是这个的相关案例,但我想在某处添加它:

    就像我的情况一样,此timedatectl输出可能对应于被防火墙阻止的 NTP 端口。

    在 Ubuntu 上,您可以通过运行以下命令明确允许 NTP 端口 123 上的通信:

    sudo ufw allow out from any to any port 123
    

    这将允许来自使用任何端口/网络协议组合的 PC 上运行的服务的出站流量到使用端口 123 和任何网络协议的远程计算机上运行的服务。这包括在实现网络时间协议的远程机器上运行的服务,这是能够从远程机器请求时间所必需的。

    • 5
  6. TheArchitecta
    2019-06-11T03:44:21+08:002019-06-11T03:44:21+08:00

    Gui选项:转到“设置”->“详细信息”->“日期和时间”->打开“自动日期和时间”。

    systemctl restart systemd-timesyncd可能有帮助

    • 4
  7. why it doesnt work
    2021-06-04T04:23:49+08:002021-06-04T04:23:49+08:00

    对于那些遵循max的答案但失败的人。转到NTP,选择您的特定池区域,然后将至少两个池区域添加到您的/etc/systemd/timesyncd.conf. 例如,对于亚洲,添加:

    [Time]
    NTP=0.asia.pool.ntp.org 1.asia.pool.ntp.org
    FallbackNTP=0.pool.ntp.org 1.pool.ntp.org
    

    然后运行推荐答案中的其余命令。

    • 1
  8. chsymann
    2022-01-14T04:23:28+08:002022-01-14T04:23:28+08:00

    我在某处读到,您必须使系统时间与同步服务器时间最多相差 1000 秒才能进行同步。如果您当前的系统时间超过 1000 秒,它将无法正常工作。所以尝试先手动更改时间:

    timedatectl set-ntp false
    timedatectl set-timezone 'Europe/Berlin'
    timedatectl set-time 2022-01-13
    timedatectl set-time 13:16
    timedatectl set-ntp true
    

    这样做之后,我在 timedatectl 中得到了“是”

                   Local time: Thu 2022-01-13 13:16:16 CET
               Universal time: Thu 2022-01-13 12:16:16 UTC
                     RTC time: n/a                        
                    Time zone: Europe/Berlin (CET, +0100) 
    System clock synchronized: yes  # <----------- it's synced                        
                  NTP service: active                     
              RTC in local TZ: no   
    

    有关更多信息,请参阅-g此处的选项https://linux.die.net/man/8/ntpd

    • 1

相关问题

  • 时钟走得太快

  • 当我的服务器自动使用 DST 时,如何使用 cron 来安排在不支持 DST 的应用程序上实现夏令时的脚本?

  • 如何从命令行更改时区设置

  • 时钟在不活动时停止滴答,导致漂移

  • ureadahead 似乎在启动时阻止了系统

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve