嵌入式ntp服务器的移植
嵌入式ntp服务器的移植
二、编译源码文件
1.输入:tar -xzvf ntp-4.2.6p5.tar.gz
2.进入解压目录配置
输入: cd ntp-4.2.6p5/
3.指定编译器安装路径
./configure --host=arm-linux CC=arm-none-linux-gnueabi-gcc --prefix=/home//ntp/
4.make和[make install]
5.安装完之后在安装目录下会有三个文件夹产生
/bin(ntpd,ntpdate,ntpdc,ntp-******,ntpd,ntptime,sntp,tickadj...)
/lib
/sbin
/share (man)
将bin目录下的文件拷贝到目标文件系统bin目录下
1、保证网络能正常使用(否则ntpdate程序可能会被阻塞在获取网络时间的地方,同时启动ntpdate时也要注意ntpdate的阻塞不能影响其他程序的启动)
[email protected]:/# ntpdate time.buptnet.edu.cn(或者ntpdate 202.112.10.60)
说明:time.buptnet.edu.cn是北京时间的NTP服务器(IP:202.112.10.60)
1.pool.ntp.org
2.pool.ntp.org
3.pool.ntp.org
则解决办法:在安装交叉编译工具的目录arm-arago-linux-gnueabi/usr/lib中有文件libcap.so.2和libattr.so.1直接拷贝到开发板/lib目录下即可
(本人arm开发板内已经有了这两个库,故没有出现上面的错误,直接时间同步成功)
3、拷贝完以上两个文件即可完成时间同步
[email protected]:/# ntpdate time.buptnet.edu.cn
24 Jan 07:39:12 ntpdate[2352]: step time server 202.112.10.30 offset -28758.575296 sec
[email protected]:/# date
Thu Jan 24 07:39:18 UTC_2013
4、设置时区为CST时间
(1)把redhat或者ubuntu系统目录/usr/share/zoneinfo/Asia中的文件Shanghai拷贝到开发板目录/etc中并且改名为localtime之后,用命令reboot重启即可,如下:
[email protected]:~# date
Thu Jan 24 15:55:29 CST 2013
5、如果想显示UTC时间可以使用命令
[email protected]:~# date –u
6、如果想将从网络上获取到的系统时间写入硬件时钟中,则使用命令
[email protected]:~# hwclock -w
四、ntp服务器 (因为用不着,所以暂时没有测试)
1、保证做ntp服务器的开发板和ntp客户端的系统的网络连接正常
2、在要做服务器的开发板上编辑文件/etc/ntp.conf
执行命令:
[email protected]:~# vi /etc/ntp.conf
#restrict default nomodify notrap noquery
restrict 127.0.0.1
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 5
driftfile /var/lib/ntp/drift
broadcastdelay 0.008
keys /etc/ntp/keys Qiyang