日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/13 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在树莓派是安装并配置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

總結

以上是生活随笔為你收集整理的在树莓派是安装并配置NTP服务的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。