在树莓派是安装并配置NTP服务

我们都知道树莓派的小巧和省电节省空间等太多的优势,这里就不一一列举了,那么树莓派就需要长时间的运行,可以7×24的方式运行,那么我们就把树莓派当作一个小的服务器来运行,可以跑一些小的应用,例如可以在局域网中当作NTP服务器,哈哈,这个想法不错!

初步设想:

1)树莓派连接网络之后,时间通过网络自动同步,那么树莓派本身的时间就正常了。(不会的自己上网查,类似的文章一堆,不是本文重点)

2)在内部局域网中的其他计算机(包含win,Linux,mac等)都可以以树莓派作为ntp服务器进行时间同步了。

 

一、配置局域网NTP服务器

1.安装ntp服务

通过如下命令安装ntp服务
sudo apt-get install ntp

 

2.修改配置文件ntp.conf

安装完成后,打开/etc/ntp.conf文件,在命令处输入:

cd /
cd etc/
sudo nano 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 clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable# You do need to talk to an NTP server or two (or three).
#server ntp.your-provider.example# pool.ntp.org maps to about 1000 low-stratum NTP servers.  Your server will
# pick a different set every time it starts up.  Please consider joining the
# pool: <http://www.pool.ntp.org/join.html>
server 0.debian.pool.ntp.org iburst
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst# 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
restrict -6 default kod notrap nomodify nopeer noquery# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1# 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

以上是安装ntp服务完成后的默认配置。

我自己参考了网上其他人的配置参数,修改成了如下的样子,参考文章在最后给出了地址:

# /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 clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable# You do need to talk to an NTP server or two (or three).
#server ntp.your-provider.example# pool.ntp.org maps to about 1000 low-stratum NTP servers.  Your server will
# pick a different set every time it starts up.  Please consider joining the
# pool: <http://www.pool.ntp.org/join.html>
server 0.debian.pool.ntp.org iburst
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst
server time.asia.apple.com prefer
server ntp.sjtu.edu.cn prefer
server 127.127.1.0
fudge 127.127.1.0 stratum 10# 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
restrict -6 default kod notrap nomodify nopeer noquery
#restrictdefault nomodify# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1# 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

根据自己的网络情况,以及使用情况,请自行修改ntp配置,本文章末尾处给出了配置的参考连接。

3.重启NTP服务

使用命令重启ntp服务:sudo service ntp restart

4.本地测试

1)先确认ntp是否已启动,命令:ps -ef | grep ntp,应该可以看到两行内容(如果一行太长显示不完,会显示成两行,注意分辨!)

2)命令行输入:ntpq -p

结果如下,说明NTP服务器进程存在

pi@raspberrypi36:/ $ ntpq -premote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+cn.ntp.faelix.n 185.134.196.169  2 u    1   64  377  253.107   -7.402  23.282
+d.hnd.pobot.net 255.254.0.27     2 u   15   64  155  249.128   41.977   8.036static-5-103-13 .INIT.          16 u    -   64    0    0.000    0.000   0.000
*time5.aliyun.co 10.137.38.86     2 u    9   64  377   30.167    3.322   3.654

重启系统

重启命令:reboot

5.在其它PC同步树莓派上的时间

在其它PC端填入我的树莓派IP。
在Windows下即设置时间时选择Internet时间,并填入树莓派的IP。

=========================================================

参考:

https://blog.csdn.net/rk2900/article/details/8658110

https://www.linuxidc.com/Linux/2016-10/135945.htm

https://blog.csdn.net/gsls200808/article/details/51057359

https://www.cnblogs.com/quchunhui/p/7658853.html

https://blog.csdn.net/yjgithub/article/details/54613172

https://www.cnblogs.com/rongpmcu/p/7662141.html

转载于:https://www.cnblogs.com/mq0036/p/9362706.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/251152.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Oracle使用总结

1. 在ORACLE中Service Name即为数据库名称&#xff1b; 2. 在做删除操作时&#xff0c;需要加Commit进行操作提交&#xff1b; 3. 使用sqlldr将数据进行批量导入到ORACLE中&#xff1a; 3.1 Sqlldr命令的用法&#xff1a; sqlldr useridLoginName/PasswordTNSName controlC:\U…

ES5-17/18 错误信息、try_catch、严格模式

错误信息 语法错误 标识符名称&#xff08;变量、函数名&#xff09;不规范对关键字赋值基本语法错误&#xff0c;如分号打错 引用错误 变量、函数未声明给无法赋值的对象赋值var a 1 2 范围错误 数组长度为负数方法参数超出可行范围toFixed(-1) 类型错误 调用不存在…

vue --- v-text、v-show、v-if、v-else

v-text: <div id "app"><p v-text"msg"></p> </div> <script>let app new Vue({el:#app,data:{msg:Hello Vue}}) </script>// 可见v-text在某种程度上等价于 {{}}v-show: <div id "app"><div…

查找mac下腾讯视频下载地址

mac 腾讯视频下载的视频是不可见的&#xff0c;也许是因为版权原因吧。使用以下方法可以在文件中找到缓存的视频&#xff08;不过都是被断开的很多短视频&#xff09;。 在terminal输入&#xff1a; cd Library/Containers/ 然后ls查看。查看当前的所有文件夹&#xff0c;你会看…

JS 新建web sql 数据表

//新建web sql数据库数据表var tbName"tableName";var strSQL"create table if not exists tableName (id unique,th1,th2,th3)";function creatBDTable(strSQL,tbName){db openDB();db.transaction(function(tr) {tr.executeSql(strSQL,[],//SQL语句出成…

vue --- v-for、v-on、v-model、v-once

v-for: <div id "app"><ul><li v-for"item in list">{{item}}</li></ul> </div> <script>let app new Vue({el:#app,data:{list:[B,A,T]}}) </script>拿到索引index: <div id"app">&…

ES5-19 变量声命周期、垃圾回收原理、arguments

变量声命周期 垃圾回收 找出不再使用的变量释放其占用内存固定的时间间隔运行 解除由于闭包产生的对fn AO的引用 标记清除 排除全局变量、排除闭包引用的AO中的变量进入环境 → 离开环境常用 引用计数 引用计数为0时清除对循环引用的情况&#xff0c;如果不手动接触引用…

bzoj 1801: [Ahoi2009]chess 中国象棋【dp】

注意到一行只能放012个炮&#xff0c;我们只需要知道列的状态&#xff0c;不用状压行 所以设f[i][j][k]表示前i行有j列有1个炮&#xff0c;有k列有2个炮的方案数 然后分情况讨论转移就行了 #include<cstdio> #include<iostream> using namespace std; const int N1…

vue --- compoent妙用

首先利用写一个静态模板的组件 <div id "app"><my-arti></my-arti> </div> <script>Vue.component(my-arti,{template:<div style"border:1px solid black"><span>date:2019年06月14日</span><br>…

ES5-20 复习

3-1 变量单一声明方式String Boolean undefined Number nullundefined nulltypeof(null) ‘object’typeof(方法) ‘function’typeof() 是运算符&#xff0c;不是数据类型 报错0 -0 trueInfinity -Infinity falseNaN和谁都不等原始值没有属性 要打印属性、调用方法得经过基…

eclipse中去掉警告提示

有时候我们要去掉这些不必要的提示 下面我们来设置去掉这些警告提示 转载于:https://www.cnblogs.com/xiaostudy/p/9370016.html

vue --- vue-router

vue-router的CDN <script src "https://unpkg.com/vue-router2.5.3/dist/vue-router.js"></script>// 当然还需要导入vue的cdn <script src"https://cdn.jsdelivr.net/vue/2.1.3/vue.js"></script>使用router-link(to)添加点击链…

django-restframework使用

安装restframework: pip install djangorestframework 修改项目settings.py: INSTALLED_APPS [django.contrib.admin,django.contrib.auth,django.contrib.contenttypes,django.contrib.sessions,django.contrib.messages,django.contrib.staticfiles,rest_framework, ]修改项…

JSON基础与数据解析、JSON方法、AJAX初识

JSON JavaScript Object Notation js对象标记是对象&#xff0c;是轻量级数据交互的格式&#xff0c;不能有方法它基于 JavaScript 语法&#xff0c;但与之不同&#xff1a;JavaScript不是JSON&#xff0c;JSON也不是JavaScript映射用:隔开并列数据用,隔开映射的集合用{}包裹键…

iOS开发经验总结

在iOS开发中经常需要使用的或不常用的知识点的总结&#xff0c;几年的收藏和积累&#xff08;踩过的坑&#xff09;。 一、 iPhone Size 二、 给navigation Bar 设置 title 颜色 123UIColor *whiteColor [UIColor whiteColor];NSDictionary *dic [NSDictionary dictionaryWit…

http --- 缓存

Web缓存: // 是可以自动保存常见文档副本的HTTP设备. // 当Web请求抵达缓存时,如果本地有"已缓存的"副本,就可以从本地存储设备而不是原始服务器中提取这个文档.冗余的数据传输: // 有很多客户端访问一个流行的原始服务器页面时,服务器会多次传输同一份文档 // 每次…

Django 下添加左侧字段显示和搜索

在对应的apps下建立xadmin.py from .models import EmailVerifyRecord import xadminclass EmailVerifyRecordAdmin(object): list_display [code,email,send_type,send_time]//字段显示 search_fields [code,email,send_type]//搜索 xadmin.site.register(EmailVerify…

免费分享老男孩全栈9期视频,共126天

免费分享老男孩全栈9期视频&#xff0c;共126天。 及时保存避免失效&#xff1a;http://mihon.cn/article/26.html/ 转载于:https://www.cnblogs.com/mihon/p/9372881.html

ES5 数组扩展方法 forEach/filter/map的使用与重写

ES3 splice slice join sort &#xff08;IE5、IE6&#xff09; 数组扩展方法 ES5&#xff08;在ES3的基础上增加、修正&#xff09; forEach 可能会改变原数组(直接操作了arr[i]&#xff0c;没有使用深拷贝)参数1&#xff1a;回调函数&#xff08;如果不使用箭头函数&#xf…

http --- 网关、隧道、中继

网关: // 作为某种翻译器使用,抽象出了一种能够到达的资源 // 应用程序可以请求网关来处理某条请求. // 在HTTP和其他协议及其应用程序之间起到接口作用FTP URL的HTTP请求: GET ftp://ftp.irs.gov/pub/00-index.txt HTTP/1.0 Host: ftp.irs.gov User-agent: SuperBrowser 4.2…