配置树莓派3和局域网NTP服务器实现内网时间校准
一、配置局域网NTP服务器
1.安装ntp-4.2.8p5-win32-setup.exe
下载地址:https://www.meinbergglobal.com/english/sw/ntp.htm
按默认步骤安装即可。
2.修改配置文件ntp.conf
配置文件默认路径为:C:\Program Files (x86)\NTP\etc\ntp.conf
去掉
- #server 127.127.1.0
- #fudge 127.127.1.0 stratum 12
前的#
保存
笔者改完后的配置文件内容如下
- # NTP Network Time Protocol
- # **** ATTENTION ****: *You have to restart the NTP service when you change this file to activate the changes*
- # PLEASE CHECK THIS FILE CAREFULLY AND MODIFY IT IF REQUIRED
- # Configuration File created by Windows Binary Distribution Installer Rev.: 1.27 mbg
- # please check http://www.ntp.org for additional documentation and background information
- # restrict access to avoid abuse of NTP for traffic amplification attacks
- # see http://news.meinberg.de/244 for details
- restrict default noquery nopeer nomodify notrap
- restrict -6 default noquery nopeer nomodify notrap
- # allow status queries and everything else from localhost
- restrict 127.0.0.1
- restrict -6 ::1
- # if you need to allow access from a remote host, you can add lines like this:
- # restrict <IP OF REMOTE HOST>
- # Use drift file
- driftfile "D:\Program Files (x86)\NTP\etc\ntp.drift"
- # your local system clock, could be used as a backup
- # (this is only useful if you need to distribute time no matter how good or bad it is)
- server 127.127.1.0
- # but it should operate at a high stratum level to let the clients know and force them to
- # use any other timesource they may have.
- fudge 127.127.1.0 stratum 12
- # Use a NTP server from the ntp pool project (see http://www.pool.ntp.org)
- # Please note that you need at least four different servers to be at least protected against
- # one falseticker. If you only rely on internet time, it is highly recommended to add
- # additional servers here.
- # The 'iburst' keyword speeds up initial synchronization, please check the documentation for more details!
- server 0.asia.pool.ntp.org iburst minpoll 6 maxpoll 7
- server 1.asia.pool.ntp.org iburst minpoll 6 maxpoll 7
- server 2.asia.pool.ntp.org iburst minpoll 6 maxpoll 7
- server 0.us.pool.ntp.org iburst minpoll 6 maxpoll 7
- server 1.us.pool.ntp.org iburst minpoll 6 maxpoll 7
- server 2.us.pool.ntp.org iburst minpoll 6 maxpoll 7
- # End of generated ntp.conf --- Please edit this to suite your needs
3.重启服务
计算机--右键 管理--服务与应用程序--服务,找到Network Time Protocol Daemon,右键重启
或者通过开始菜单重启。两者作用一样
开始--Meinberg--Network Time Protocol--Service Control--Restart NTP Service
4.本地测试
命令行输入
ntpq -p
结果中的第一行如果出现LOCAL,说明NTP服务器进程存在
- Microsoft Windows [版本 6.3.9600]
- (c) 2013 Microsoft Corporation。保留所有权利。
- C:\Windows\system32>ntpq -p
- remote refid st t when poll reach delay offset jitter
- ==============================================================================
- LOCAL(0) .LOCL. 12 l 201 64 10 0.000 0.000 0.000
- +ntp2.aliyun.com 10.137.38.86 2 u 61 64 7 55.655 1.918 7.038
- *118.189.211.186 .PPS. 1 u 62 64 7 117.009 10.206 3.703
- +shim.active-app 218.186.3.36 2 u 124 64 2 105.239 -4.597 2.797
- -104.156.99.226 192.12.19.20 2 u 61 64 5 256.067 -2.231 7.130
- -y.ns.gin.ntt.ne 249.224.99.213 2 u 10 64 5 138.076 11.235 8.025
- C:\Windows\system32>
5.添加防火墙例外
将ntp.exe添加到防火墙例外或者将UDP的123端口添加到防火墙例外
6.再次重启服务
步骤同第三步
二、配置树莓派同步时间
首先熟悉几个关于时间命令
- date #查看当前时间
- date -s "2016-03-31 10:18:00" #设置当前时间为2016年3月31日10:18:00
- date -s 2016-03-31 #设置当前日期为2016年3月31日0:00:00
- date -s 10:18:00 #设置当前时间为10:18:00
1.安装ntpdate
- sudo apt-get install ntpdate
2.对时
- sudo ntpdate 172.26.69.87
其中172.26.69.87为局域网NTP服务器的IP地址
对时后可用date命令查看时间
tip1:如果遇到the NTP socket is in use, exiting的提示,这是因为ntpd也是用的UDP123端口更新时间,我们先将ntp这个服务关掉
- sudo service ntp stop
然后再执行
- sudo ntpdate 172.26.69.87
tip2:如果遇到no server suitable for synchronization found的提示,多半是因为网络不通或者对应的NTP服务器没有启动。
3.修改时区
默认情况下树莓派使用的是UTC时间,与北京时间相差8小时,所以需要修改时区
tzselect命令并不能真正的修改
正确的做法是替换掉时区文件
- sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
修改之后用date查看到的是CST时间
4.添加局域网NTP服务器地址
修改配置文件ntp.conf
- sudo nano /etc/ntp.conf
在server项目前面添加如下内容
- server 172.26.69.87 prefer
- server 192.168.42.254 iburst
- server cn.pool.ntp.org iburst
- server asia.pool.ntp.org iburst
- server pool.ntp.org iburst
这个配置文件用于ntpd程序同步时间,每次树莓派开机启动后都会启动这个程序,同步的时间需要5分钟。
5.查看时间
- date
三、配置开机自启
在实际运行中,如果计算机的时间与网络时间相差超过30分钟,那么ntpd就不会自动同步了,笔者处于每天断电7~8个小时的校园网,所以每次开机必须先用ntpdate强制同步时间,但这个进程不能执行得太早,太早的话可能还没联网。所以加了个延迟40秒启动。
编辑
- sudo nano /usr/bin/synctime
内容
- #! /bin/sh
- #延迟40秒启动
- sleep 40s
- #停止ntpd服务
- killall ntpd
- #对时
- ntpdate -u 202.199.131.1
- #开启ntpd服务器
- ntpd -c /etc/ntp.conf
保存
修改脚本执行权限
- sudo chmod a+x /usr/bin/synctime
加入开机启动
- sudo nano /etc/rc.local
#在exit 0前面添加
- sudo /usr/bin/synctime > /dev/null 2>&1
保存
修改执行权限
- sudo chmod +x /etc/rc.local
重启
- reboot
附:
DJTU内网推荐NTP配置
- server 222.26.224.216 prefer
- server 202.199.131.1 iburst
- server 202.120.2.100 iburst
- server cn.pool.ntp.org iburst
转载于:https://www.cnblogs.com/Pond-ZZC/p/6680257.html
配置树莓派3和局域网NTP服务器实现内网时间校准相关推荐
- 北斗时钟服务器(NTP服务器)让高考时间更加精准
北斗时钟服务器(NTP服务器)让高考时间更加精准 北斗时钟服务器(NTP服务器)让高考时间更加精准 安徽京准电子科技原创 [摘要]时钟系统是一个大型标准计时系统,随着网络的普及,许多校园都建了自己的校 ...
- OpenWrt路由配置Openνρη服务器访问内网资源
OpenWrt路由配置Openνρη服务器访问内网资源(LuCI界面实现) 本篇文章想表达的意思是把OpenWrt路由器作为Openνρη服务端,就相当于一个服务器,然后手机/iPad/电脑需作为客户 ...
- 修改内网服务器数据,内网服务器拷数据
内网服务器拷数据 内容精选 换一换 本节定义了云耀云服务器上报云监控的监控指标的命名空间,监控指标列表,各项监控指标的具体含义与使用说明,用户可以通过云监控检索云耀云服务器服务产生的监控指标和告警信息 ...
- 在安卓上部署服务器 - 解决内网穿透
原文地址:在安卓上部署服务器 - 解决内网穿透 本系列其他文章: 在安卓上部署服务器 在安卓上部署服务器 – 应用程序的配置 在安卓上部署服务器 – 解决内网穿透问题 在安卓上部署服务器 – 部署脚本 ...
- 云服务器的内网IP和公网IP应该怎么理解?有什么用?
在配置小鸟云服务器的过程中,因为在新手期,遇到一些有关于内网IP和公网IP的问题,包括: 1.内网IP和公网IP是什么? 2.内网IP和公网IP有什么用? 3.可以使用外网IP访问内网服务器吗? 4. ...
- 【vscode远程开发】使用SSH远程连接服务器 「内网穿透」
文章目录 视频教程 1.安装OpenSSH 2.vscode配置ssh 3. 局域网测试连接远程服务器 4. 公网远程连接 4.1 ubuntu安装cpolar 4.2 创建隧道映射 4.3 测试公网 ...
- 远程公司内网服务器【内网穿透】
当遇到在家休假,却需要远程处于公司内网服务器的场景时,我们可以通过内网穿透将本地端口映射到公网,使用所生成的公网地址来进行远程连接. 这里推荐一款可以永久免费使用,还不限制流量的内网穿透工具----c ...
- 如何在自己的电脑开服务器(内网穿透)
如何在自己的电脑开服务器(内网穿透) 如何在自己电脑开服务器 1.Utools插件 2.内网穿透插件 3.花生壳的登陆与注册 4.内网穿透配置 5.测试 感谢大家看到这里,如果觉得我写得好的话麻烦大家 ...
- 【外网访问学校服务器】阿里云服务器+frp+内网服务器
寒假将至,为了在家能继续用学校的服务器,通过云服务器的公网ip作为桥梁进行内网渗透,来访问学校的服务器. 设备:服务端(阿里云轻量服务器) 客户端( Ubuntu 20.04.1) 阿里云先设置密码 ...
最新文章
- 一篇简单易懂的原理文章,让你把JVM玩弄与手掌之中
- Centos6.7安装docker1.7.1
- FTP的主动模式和被动模式,你应该用那种?
- Android JNI 第三篇 Java参数类型与本地参数类型对照
- 《从零开始学Swift》学习笔记(Day 26)——可选链
- PMCAFF微课堂 | 京东零售平台资深PM深度揭秘京东的订单体系
- Redis的 key 和 value大小限制
- Web 的MSN,可以不用装客户端
- hadoop中的helloword
- WIFI加密技术介绍
- 解决win10 蓝牙设备只能配对无法连接 ,并且删除设备无效的问题
- 4 合并grid列_在 Power BI Desktop 中合并数据
- 怎么判断间隙过渡过盈配合_什么是间隙配合、过盈配合、过渡配合?它们在汽车上有哪些应用?...
- 【NeatUpload】大附件上传配置文件
- r语言熵权法求权重(真实案例完整流程)
- 红帽linux中文系统下载iso,红帽子9.0版下载-redhat linux 9.0 iso下载 简体中文正式版-IT猫扑网...
- 新建文本html,创建邮件模板时html内容和文本内容哪种好
- jdk版本问题:hour_day_of 0 -1
- 在ASF中使用On Demand生产DEM等产品时使用不同参考DEM的区别
- 全卷积神经网络(FCN)