timedatectl

根据Ubuntu的说法:

ntpdate is considered deprecated in favor of timedatectl (or chrony) andthereby no more installed by default. timesyncd will generally do the rightthing keeping your time in sync, and chrony will help with more complexcases.

timedatectl 用起来非常简单,默认配置文档在/etc/systemd/timesyncd.conf

最简化内容:

[Time]
NTP=
FallbackNTP=pool.ntp.org
RootDistanceMaxSec=5
PollIntervalMinSec=32
PollIntervalMaxSec=2048

通常不需要做任何改动,如果要增加自定义的ntp服务器写在第一行,空格分隔

启用:

timedatectl set-ntp true

如果报错:Failed to set ntp: NTP not supported.
自己动手干掉已有的ntpd或者ntp再来,还是不行自己动手装chrony

查看状态:

timedatectl status

大概这样就是启用成功并同步成功了,据说需要一些时间

Local time: Fri 2019-06-14 14:28:52 CST
Universal time: Fri 2019-06-14 06:28:52 UTC
RTC time: n/a
Time zone: Asia/Shanghai (CST, +0800)
Network time on: yes
NTP synchronized: yes
RTC in local TZ: no

设置时区:

timedatectl set-timezone Asia/Shanghai

虽然似乎有点ZZ不正确的样子(从小到大都只知道北京时间),据说是因为:

The reason why Asia/Shanghai is used instead of Beijing is because Shanghai is the most populous location in the zone.

印象中以前折腾Ubuntu时候还有Asia/Chongqing,也被backzone了

Asia/Kashgar, Asia/Chongqing, and Asia/Harbin, are kept in the “backzone” file of the IANA timezone database for backward compatibility.

重启:systemctl restart systemd-timedated

Debian通过,Centos不知道为什么死活不同步,不管了

ref:

https://wiki.archlinux.org/index.php/Systemd-timesyncd

https://en.wikipedia.org/wiki/Tz_database

https://en.wikipedia.org/wiki/Time_in_China