'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
Run Code Online (Sandbox Code Playgroud)
如何将系统时钟同步设置为是?
小智 25
它可以在不部署 NTP 的情况下完成,如下所示:
sudo nano /etc/systemd/timesyncd.conf
Run Code Online (Sandbox Code Playgroud)
编辑 NTP 服务器详细信息
[Time]
NTP=ur.ntp.srv
FallbackNTP=ur.fallbackntp.srv
Run Code Online (Sandbox Code Playgroud)
然后
sudo systemctl daemon-reload
sudo timedatectl set-ntp off
sudo timedatectl set-ntp on
Run Code Online (Sandbox Code Playgroud)
你可以检查它
timedatectl status
Run Code Online (Sandbox Code Playgroud)
Ter*_*nce 16
一种方法是使用ntp
它在 Ubuntu 18.04 中仍然有效。运行以下命令安装ntp
.
sudo apt install ntp
Run Code Online (Sandbox Code Playgroud)
安装后,您可以运行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
Run Code Online (Sandbox Code Playgroud)
然后在您的/etc/crontab
文件中添加,@reboot root /usr/sbin/ntpd -n
以便ntpd
在系统重新启动时自动启动。用你喜欢的编辑器类似gedit
或mousepad
或任何你喜欢:
pkexec gedit /etc/crontab
Run Code Online (Sandbox Code Playgroud)
添加该行后,它应该看起来像这样:
# /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
#
Run Code Online (Sandbox Code Playgroud)
然后重新启动计算机以使设置生效。
~$ 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
Run Code Online (Sandbox Code Playgroud)
如果您想将您的服务器更改为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
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
tgo*_*gos 10
以下对我有用:
timedatectl set-ntp true
Run Code Online (Sandbox Code Playgroud)
进而...
systemctl restart systemd-timesyncd
Run Code Online (Sandbox Code Playgroud)
例子:
对于在 AWS EC2 实例上使用 Ubuntu 18+ 的用户,我发现这非常有效。它利用 AWS 的内部时间同步服务:
sudo apt install chrony
sudo nano /etc/chrony/chrony.conf
Run Code Online (Sandbox Code Playgroud)
在任何其他服务器条目之前添加以下行:
server 169.254.169.123 prefer iburst minpoll 4 maxpoll 4
Run Code Online (Sandbox Code Playgroud)
进而
sudo /etc/init.d/chrony restart
Run Code Online (Sandbox Code Playgroud)
EC2 实例的这种方法的最佳部分是您不必修改安全组规则,即使您的实例未连接到 Internet :)
小智 5
一个相关的案例不完全是这个,但我想在某处添加它:
与我的情况一样,此timedatectl
输出可能对应于被防火墙阻止的 NTP 端口。
在 Ubuntu 上,您可以通过运行以下命令明确允许 NTP 端口 123 上的通信:
sudo ufw allow out from any to any port 123
Run Code Online (Sandbox Code Playgroud)
这将允许从使用任何端口/网络协议组合的 PC 上运行的服务到使用端口 123 和任何网络协议在远程计算机上运行的服务的出站流量。这包括在实现网络时间协议的远程机器上运行的服务,这是能够从远程机器询问时间所必需的。
归档时间: |
|
查看次数: |
60217 次 |
最近记录: |