ubuntu16.04 已经内置了网络时间同步服务systemd-timesyncd.service

NTP服务器设置

查看 man systemd-timesyncd.service,里面有一句

The NTP servers contacted are determined from the global settings in timesyncd.conf(5),

由此可见,timesyncd.conf可配置NTP服务器。再次 man timesyncd.conf,默认的路径为/etc/systemd/timesyncd.conf

timesyncd.conf 文件内容如下:

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See timesyncd.conf(5) for details.

[Time]
#NTP=
#FallbackNTP=ntp.ubuntu.com
NTP=time1.aliyun.com
FallbackNTP=time2.aliyun.com

建议NTP使用内网NTP服务器,NTP服务器上游设置为time[1-5].aliyun.com,另外值得一提的是,默认轮询时间为10s。

时间控制命令 timedatectl

时间控制命令 timedatectl,这个命令旧的系统不知道有没有,反正以前没注意过。

参数:

  status                   Show current time settings #显示当前时间设置
  set-time TIME            Set system time #设置当前时间为指定时间
  set-timezone ZONE        Set system time zone #设置时区
  list-timezones           Show known time zones #列出可用时区
  set-local-rtc BOOL       Control whether RTC is in local time 
  set-ntp BOOL             Enable or disable network time synchronization