ntp client 移植到openwrt

一、硬件平台

    1、  控制器:MT7620(A9内核)

二、软件平台

   1、开发环境:ubuntu12.04 

   2、openwrt 版本:15.05
   3、ntp源码包版本:4.2.8p7
      ntp源码下载链接:http://www.ntp.org/downloads.html
   4、交叉编译工具链版本:openwrt 源码包配套的版本 toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_glibc-2.21

三、说明

      NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议。


四、编译步骤

       本文的ntp源码,放在目录 /home/sky/ntp/

      1、解压源码: tar -vxf ntp-4.2.8p7.tar.gz

       2、创建文件夹,用于存放ntp源码编译之后的文件: mkdir ntp_out

       3、进入源码目录:cd ntp-4.2.8p7

       4、编译源码

       (1)对源码进行配置,由于参数较多,采用 " \ " 分行。

        注意:

        a. 本文中的交叉编译工具链,路径为:/home/sky/develop/openWrt/openwrt/staging_dir/

        b. 由于openwrt的交叉编译工具链比较特别,许多库都在"target-mipsel_24kec+dsp_glibc-2.21"路径下,而不是在"toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_glibc-2.21"目录,所以需要特别指定openssl的路径,否则编译会提示找不到相应的文件,编译失败。

./configure --prefix=/home/sky/ntp/ntp_out \
--enable-shared \
--disable-static \
--with-yielding-select=manual \
--disable-main \
--host=mipsel-openwrt-linux \
CC=/home/sky/develop/openWrt/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_glibc-2.21/bin/mipsel-openwrt-linux-gnu-gcc \
--with-openssl-incdir=/home/sky/develop/openWrt/openwrt/staging_dir/target-mipsel_24kec+dsp_glibc-2.21/usr/include/

        (2)编译

          make


         (3) 安装

          make install

         执行完成之后,生成的文件都在../out_ntp/ 目录下,我们需要的文件为../out_ntp/bin/ntpdate


五、测试ntp client

将  ntpdate 下载到开发板上,进行测试。

1、修改系统时间,随意设置一个时间:  

root@OpenWrt:/tmp# date -s "2015-8-9 18:54:32"
        Sun Aug  9 18:54:32 UTC 2015

如此一来,时间修改为2015-8-9 18:54:32


2、查看当前时间,确认时间是否修改成功,如下所示,系统时间已经修改为Sun Aug  9 18:54:35 UTC 2015

root@OpenWrt:/tmp# date
       Sun Aug  9 18:54:35 UTC 2015


3、ntpdate 同步时间

(1)同步时间,可能需要几秒甚至更长才能有结果,视网络和ntp服务器而定。

root@OpenWrt:/tmp# ./ntpdate time.buptnet.edu.cn
      3 Jun 09:17:43 ntpdate[1270]: step time server 202.112.10.60 offset 25798865.779885 sec


(2)确认时间是否已经同步

root@OpenWrt:/tmp# date
       Fri Jun  3 09:22:46 UTC 2016

经过对比当前的UTC时间,和系统时间一致,说明ntpdate 可以移植成功。


(3)ntp服务器说明

说明:time.buptnet.edu.cn是北京时间的NTP服务器(IP202.112.10.60 

有时候该的ntp服务器ping不通,此时可以使用其他的ntp服务器。
     

当前已提供的各国NTP服务器列表

[INTERNATIONAL NTP server list.]

区域[zone] 域名[Domain] IP池[IP Pool]
中国[China] cn.ntp.org.cn [202.108.6.95] [202.112.29.82] [110.75.190.198] [115.28.122.198] [182.92.12.11] 
[120.25.108.11] [110.75.186.249] [110.75.186.248] [110.75.186.247]
中国台湾[ChinaTaiwan] tw.ntp.org.cn [120.119.28.1]
美国[America] us.ntp.org.cn [24.56.178.140] [131.107.13.100]
新加坡[Singapore] sgp.ntp.org.cn [139.162.20.174] [103.11.143.248]
韩国[korea] kr.ntp.org.cn [218.234.23.44] [211.233.40.78]
德国[Germany] de.ntp.org.cn [131.188.3.220] [131.188.3.223]
日本[Japan] jp.ntp.org.cn [133.243.238.243] [157.7.152.213]



          

猜你喜欢

转载自blog.csdn.net/xhoufei2010/article/details/51579950
NTP
今日推荐