- http://www.ntp.org/downloads.html 下載源碼
-
- 解壓縮
- 進入源碼目錄,建立arm文件夾
- 執行命令:
-
./configure --prefix=$PWD/arm --exec-prefix=$PWD/arm --host=arm-fsl-linux-gnueabi CC=arm-fsl-linux-gnueabi-gcc --with-yielding-select=yes
請按照上面執行,否則會有錯誤,錯誤如下
- 編譯make
- 安裝make install,會生成下圖中的文件夾
- 把bin目錄下的需要的命令文件拷貝到開發板的/bin目錄下,或者全部拷貝過去 ntp客戶端需要用到的命令有ntpdate,ntp服務器需要用到的命令有ntpd
以下我的服務器配置腳本ntp.conf
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
driftfile /var/lib/ntp/drift
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
#下面兩行默認是拒絕所有來源的任何訪問 要註釋掉
#restrict default kod nomodify notrap nopeer noquery
#restrict -6 default kod nomodify notrap nopeer noquery
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
#ntpd 需要有 loopback 的參與,而默認是拒絕所有,將 loopback 放行就好了
restrict 127.0.0.1 #開放本機的任何訪問
restrict -6 ::1
# 允許內網其他機器同步時間
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
#restrict 192.168.8.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# 註釋掉默認的 這裏參數指時間服務器向誰同步時間 一般指定國內時間服務器
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
#server ntp1.aliyun.com
#server time.nist.gov
#server 172.16.0.1
#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 autokey # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 autokey # manycast client
# 允許上層時間服務器主動修改本機時間
#restrict 172.16.0.1 nomodify notrap noquery
# 外部時間服務器不可用時,以本地時間作爲時間服務
server 127.127.1.0 #local clock
fudge 127.127.1.0 stratum 10
# Enable public key cryptography.
#crypto
includefile /etc/ntp/crypto/pw
# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys
# Specify the key identifiers which are trusted.
#trustedkey 4 8 42
# Specify the key identifier to use with the ntpdc utility.
#requestkey 8
# Specify the key identifier to use with the ntpq utility.
#controlkey 8
# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats