从官网上下载ntp源码,我下的是ntp-4.2.6p5.tar.gz
1.解压缩 tar zxvf ntp-4.2.6p5.tar.gz
cd ntp-4.2.6p5
2../configure --host=mips-linux --prefix=/opt/ntp/ --exec-prefix=/opt/ntp/ 生成makefile
3.make >& host_make.txt 编译,并将编译过程重定向到一个文件以便于错误分析
出现错误
/opt/cross-compile/LSDK/build/gcc-4.3.3/build_mips/staging_dir/usr/include/linux/a.out.h:4:26: error: #include nested too deeply
328 make[3]: *** [tickadj.o] 错误 1
329 make[3]: Leaving directory `/home/linux/ntp-4.2.6p5/ntp-4.2.6p5/util'
330 make[2]: *** [all] 错误 2
331 make[2]: Leaving directory `/home/linux/ntp-4.2.6p5/ntp-4.2.6p5/util'
332 make[1]: *** [all-recursive] 错误 1
333 make[1]: Leaving directory `/home/linux/ntp-4.2.6p5/ntp-4.2.6p5'
334 make: *** [all] 错误 2
发现原因是a.out.h 这个头文件嵌套包含 ,故转到./util/tickadj.c 186行注释掉 #include <a.out.h>
make >& host_make.txt 重新编译 通过
4.make install 安装
5.查看/opt/ntp 目录下,将bin,lib下的文件拷贝到板子上(lib目录下貌似没有东西)
6.windows机器作为服务器端需要运行ntp系统服务,从网上下载一个ntp.exe,还需编写配置文件ntp.conf
restrict 127.0.0.1
restrict 127.0.0.1 mask 255.255.255.0 nomodify notrap
server 192.168.44.199
fudge 192.168.44.199 stratum 5
将配置文件考到相应的目录下,我的是(D:\Program Files (x86)\ntp\etc\ntp.conf)
windows机器下ip是192.168.44.199 ,以windows 机器作为时间服务器
7.chmod u+x ntpd
chmod u+x ntpdate
./ntpd & 开启ntpd服务一般要等几分钟的时间才能起来,可以用 netstat -anp | grep ntpd 查看服务是否起来
date 查看板子当前时间
date 111111112011.30 设置时间
./ntpdate 192.168.44.199 更新时间使得与时间服务器同步
若是出现 the NTP socket is in use ,exting
则要将ntpd服务杀死, pkill ntpd
date 再查看时间 已经与windows机器同步了,时间是UTC 国际标准时。
8.若希望客户端与服务器进行自动同步,编写一个脚本ntpdaemon,内容如下:
#!/bin/sh
while true
do
/mips-linux-strip/bin/ntpdate 192.168.44.199
sleep 10
done
9.将其拷到/bin目录下边,chmod u+x ntpdaemon
10.将/bin/ntpdaemon & 加到/etc/rc.d/rcS最后一行,这样板子上电即开始运行nptdate服务,每隔10秒客户端便和windows机器同步一次,这样就完成ntp的简单移植。