在樹莓派是安裝并配置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.pswp.cn/news/251152.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/251152.shtml
英文地址,請注明出處:http://en.pswp.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…