ntp时间同步,大体步骤是将服务器端和客户端配置好,然后设定同步的频率,记得重新运行ntp服务,重启即可。

步骤总结如下:

一 服务器端(server)

1. 安装ntp与ntpdate

$ sudo apt-get install ntp

$ sudo apt-get install ntpdate

2. server服务器端修改配置文件

$ sudo gedit /etc/ntp.conf

然后对照以下内容修改配置文件:

# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for helpdriftfile /var/lib/ntp/ntp.drift# Enable this if you want statistics to be logged.#statsdir /var/log/ntpstats/statistics loopstats peerstats clockstatsfilegen loopstats file loopstats type day enablefilegen peerstats file peerstats type day enablefilegen clockstats file clockstats type day enable# Specify one or more NTP servers.# 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.#linux自带的时间同步,需要注释掉#pool 0.ubuntu.pool.ntp.org iburst#pool 1.ubuntu.pool.ntp.org iburst#pool 2.ubuntu.pool.ntp.org iburst#pool 3.ubuntu.pool.ntp.org iburst# Use Ubuntu's ntp server as a fallback.#pool ntp.ubuntu.com# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for# details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions># might also be helpful.## Note that "restrict" applies to both servers and clients, so a configuration# that might be intended to block requests from certain clients could also end# up blocking replies from your own upstream servers.# By default, exchange time with everybody, but don't allow configuration.restrict -4 default kod notrap nomodify nopeer noquery limitedrestrict -6 default kod notrap nomodify nopeer noquery limited# Local users may interrogate the ntp server more closely.restrict 127.0.0.1restrict ::1#因为是内网,所以用本地时间做为服务器时间,注意这里不是127.0.0.1server 127.127.1.0fudge 127.127.1.0 stratum 8#开放192.168.8.0 整个网段,即在这个网段的所有机器都可以使用 214 作为时间同步服务端restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap# Needed for adding pool entriesrestrict source notrap nomodify noquery# Clients from this (example!) subnet have unlimited access, but only if# cryptographically authenticated.#restrict 192.168.123.0 mask 255.255.255.0 notrust# If you want to provide time to your local subnet, change the next line.# (Again, the address is an example only.)#broadcast 192.168.123.255# If you want to listen to time broadcasts on your local subnet, de-comment the# next lines.  Please do this only if you trust everybody on the network!#disable auth#broadcastclient#Changes recquired to use pps synchonisation as explained in documentation:#http://www.ntp.org/ntpfaq/NTP-s-config-adv.htm#AEN3918#server 127.127.8.1 mode 135 prefer    # Meinberg GPS167 with PPS#fudge 127.127.8.1 time1 0.0042        # relative to PPS for my hardware#server 127.127.22.1                   # ATOM(PPS)#fudge 127.127.22.1 flag3 1            # enable PPS API

3. 设置完成退出保存,然后重启ntp服务

$ sudo service ntp restart

至此,服务器端ntp配置完成。

二 客户端(client)

1. 与服务器端相同,需要ntp与ntpdate

$ sudo apt-get install ntp

$ sudo apt-get install ntpdate

2. 修改配置文件,client的配置相对简单

$ sudo gedit  /etc/ntp.conf

对照以下内容修改

# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for helpdriftfile /var/lib/ntp/ntp.drift# Enable this if you want statistics to be logged.#statsdir /var/log/ntpstats/statistics loopstats peerstats clockstatsfilegen loopstats file loopstats type day enablefilegen peerstats file peerstats type day enablefilegen clockstats file clockstats type day enable# Specify one or more NTP servers.# 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.#linux自带的时间同步,需要注释掉#pool 0.ubuntu.pool.ntp.org iburst#pool 1.ubuntu.pool.ntp.org iburst#pool 2.ubuntu.pool.ntp.org iburst#pool 3.ubuntu.pool.ntp.org iburst# Use Ubuntu's ntp server as a fallback.#pool ntp.ubuntu.com# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for# details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions># might also be helpful.## Note that "restrict" applies to both servers and clients, so a configuration# that might be intended to block requests from certain clients could also end# up blocking replies from your own upstream servers.# By default, exchange time with everybody, but don't allow configuration.restrict -4 default kod notrap nomodify nopeer noquery limitedrestrict -6 default kod notrap nomodify nopeer noquery limited# Local users may interrogate the ntp server more closely.restrict 127.0.0.1restrict ::1#增加214作为时间服务器即可server 192.168.0.214# Needed for adding pool entriesrestrict source notrap nomodify noquery# Clients from this (example!) subnet have unlimited access, but only if# cryptographically authenticated.#restrict 192.168.123.0 mask 255.255.255.0 notrust# If you want to provide time to your local subnet, change the next line.# (Again, the address is an example only.)#broadcast 192.168.123.255# If you want to listen to time broadcasts on your local subnet, de-comment the# next lines.  Please do this only if you trust everybody on the network!#disable auth#broadcastclient#Changes recquired to use pps synchonisation as explained in documentation:#http://www.ntp.org/ntpfaq/NTP-s-config-adv.htm#AEN3918#server 127.127.8.1 mode 135 prefer    # Meinberg GPS167 with PPS#fudge 127.127.8.1 time1 0.0042        # relative to PPS for my hardware#server 127.127.22.1                   # ATOM(PPS)#fudge 127.127.22.1 flag3 1            # enable PPS API

3. 修改完以后退出,重启ntp服务

$ sudo service ntp restart

三 链接服务器端与客户端

1. 首先在客户端使用ping命令查看能否连接到服务器端

$ ping 192.168.0.3(这里是服务器IP)

2. 如果能否ping通,首先在客户端上关闭ntp服务,然后测试一下手动同步能否成功

$ sudo /etc/init.d/ntp stop

$ ntpdate 192.169.……(ntp 服务器地址)

这里注意,每次手动同步之前都要先停止ntp服务,即以上两行指令必须成对输入,因为ntp服务一般会随机自动启动。第一次对时可能误差较大,重复以上指令几次,直到命令行显示的差值接近0,即算完成同步

3. 如果手动同步测试成功,就可以进行自动同步的配置了。

方法一(不推荐):如果etc目录下存在ntp.conf文件,输入指令$ sudo gedit /etc/ntp.conf,在文件中添加以下语句

server 192.168.……(ntp服务器地址)

保存并退出,电脑中会有一个进程自动去读取该配置文件,并跟随服务器间隔一定时间进行一次对时。具体间隔时间不可查,正常情况下服务器是一台工控机,属性由机器本身决定。

方法二(推荐,更新频率可选)如果etc目录下不存在ntp.conf文件,或者想自己决定同步的频率,可输入指令$ sudo gedit /etc/crontab,在最后一行文本,文本内容如下:

***** user command

第1个 * 表示分钟:取值范围为1~59,当需要一分钟执行一次时,可表示为 * /1,以下均同;
第2个 * 表示小时:取值范围0~23
第3个 * 表示日期:取值范围1~31
第4个 * 表示月份:取值范围1~12
第5个 * 表示星期:取值范围:0~6(0表示星期天)
user为需要执行该命令的用户,command表示要运行的命令

例如,我需要在root用户下一分钟自动对时一次,则命令为:

*/1 * * * * root ntpdate 192.168.……(ntp服务器地址)

保存退出,重启客户端即可。

四 其他(随时补充)

1. 如果想看一下连接情况,可以在服务器端或者客户端输入以下命令

$ sudo ntpq -p

该命令列出了所有作为时钟源校正过本地NTP服务器时钟上层NTP服务器的列表,详细解读 https://www.cnblogs.com/zxiaozhou/p/13355415.html

2. 几个ntp服务的相关命令

启动     $ sudo service ntpstart

停止     $ sudo service ntp stop

重新启动     $ sudo service ntprestart

2020/12/17 ubuntu16.04 NTP时间同步配置相关推荐

  1. Faster R-CNN python版在Ubuntu16.04环境下配置编译

    Faster R-CNN python版在Ubuntu16.04环境下配置编译 1 电脑配置 2 安装显卡驱动 3 安装CUDA 3.1 安装CUDA 3.2 安装CUDNN 3.3 Samples测 ...

  2. 服务器ubuntu16.04安装Miniconda配置pytorch环境

    服务器ubuntu16.04安装Miniconda配置pytorch环境 刚进入实验室时配置过服务器node1节点,node1节点有4张p100,但是总是被占满,几个月后申请了node2节点,但是完全 ...

  3. 阿里云服务器ECS Ubuntu16.04 初次使用配置教程(图形界面安装)

    阿里云服务器ECS Ubuntu16.04 初次使用配置教程(图形界面安装) 2019-01-23 22:55:50 laugh12321 阅读数 851更多 分类专栏: ECS Ubuntu 版权声 ...

  4. 2020.12.17

    2020.12.17 1.无重复字符的最长子串(leetcode3) 思路:使用滑动窗口机制 设置右指针移动,其实就是一个队列,比如例题中的 abcabcbb,进入这个队列(窗口)为 abc 满足题目 ...

  5. Linux热点无网络,Linux网络配置:手提在连接WIFI热点情况下,Ubuntu16.04中怎样配置网络?...

    Linux网络配置:手提在连接WIFI热点情况下,Ubuntu16.04中怎样配置网络?,范佩西致敬温格:你是我的足球父亲,是你塑造了我,磷菩屹倨竿,布加迪推出Chiron Sport特别版,百公里加 ...

  6. 4.Ubuntu16.04中SNMP配置

    Ubuntu16.04中SNMP配置 SNMP服务配置 zabbix在监控网络设备或者打印机等设备时,需要用到SNMP,单独在被监控的客户端配置SNMP即可 端口:161 1.安装SNMP 服务端:s ...

  7. Linux怎么接移动热点,Linux网络配置:手提在连接WIFI热点情况下,Ubuntu16.04中怎样配置网络?...

    Linux网络配置:手提在连接WIFI热点情况下,Ubuntu16.04中怎样配置网络?,八维资本近期战略投资重磅项目MobileCoin.Libra Credit,橇凑站肆俏,吉利首款新能源SUV来 ...

  8. linux ntp时间同步配置,Linux ntp 时间同步服务配置

    一.基础环境 1.操作系统:CentOS 7.3 2.ntp:4.2.6 3.机器,服务端(192.168.1.210)客户端(192.168.1.211) 二.安装ntp yum -y instal ...

  9. Ubuntu16.04 LTS安装配置安装CUDA8.0、CUDNN5.1

    前言 1.前面已经装好了显卡驱动,那接下来开始配置CUDA8.0.CUDNN5.1. 2.我的安装的环境是DELL的G7 ,CPU是i7 8代,显卡是GTX 1060,系统环境是Ubuntu16.04 ...

最新文章

  1. android jason动画,Android 动画之Lottie动画使用
  2. android用什么包管理器,android – 包管理器已经死了
  3. 你不曾见过的酷炫地图可视化作品(一)
  4. 转:MFC中常用类,宏,函数介绍
  5. boost::mp11::mp_map_contains相关用法的测试程序
  6. windows下连接db2数据库
  7. HTML5来到,原生Native APP是否还有市场
  8. 机器学习-集成学习:随机森林(Random Forest)
  9. 华软计算机网络技术,[计算机硬件及网络]计算机网络技术专业自评报告华软.doc...
  10. 边缘计算是流行词还是风口?开发者怎样选开源项目?
  11. html 3d坐标,HTML3D
  12. (亲测)使用cmd结束进程的3种方法
  13. 扫描仪显示没有服务器,扫描仪安装好了,点击显示寻找扫描仪怎么显示未找出扫描仪...
  14. 蓝桥杯2014java_【图片】2014-2016蓝桥杯java本科B组省赛题_蓝桥杯吧_百度贴吧
  15. 【组合逻辑电路】——通用译码器
  16. QQ 居然被盗了?原因在这......
  17. build.prop文件详细赏析
  18. 靠智慧教育“飞升”,科大讯飞前路漫漫
  19. vue脚手架和html,vue脚手架的作用是什么?
  20. 电子通讯秤对接配置详解!

热门文章

  1. A Two-step Method for Extrinsic Calibration between a Sparse 3Dand a Thermal Camera 笔记
  2. 那周余嘉熊掌将得队——用户使用调查报告
  3. 安装 torch-scatter,torch-sparse 出现error: Command errored out with exit status 1
  4. 运筹说 第10期|敲黑板!学习运筹学,怎么能不知道相关的运筹学组织呢?
  5. 夜访阿里总部:实拍双11背后神秘的程序员!
  6. SVN、CVS、VSS区别
  7. 74160ENT引脚设计法+同步置数法接成365进制加法计数电路
  8. 爬取豆瓣电影中各种类型电影名称与评分
  9. VR系列——Oculus Audio sdk文档:三、Oculus对于Unity天然的声场定位技术(3)——空间定位的应用
  10. linux运维工程分多少种,运维工程师划分的三种层次都是什么