一.交叉编译
1.官网下载http://www.ntp.org/点击download选项页
我的版本是ntp-4.2.6p5.tar.gz
2.解压
tar -zxvf ntp-4.2.6p5.tar.gz
3.进入解压目录配置
./configure --host=arm-linux CC=arm-none-linux-gnueabi-gcc
或者指定安装路径
./configure --host=arm-linux CC=arm-none-linux-gnueabi-gcc --prefix=/home/m/3rd/tmp
4.make和[make install]
5.生成
/bin(ntpd,ntpdate,ntpdc,ntp-keygen,ntpd,ntptime,sntp,tickadj...)
/lib
/sbin
/share (man)
目录拷贝到目标文件系统
二.配置测试ntp服务器
拷贝host系统/etc目录下的ntp.conf文件到目标系统/etc下,没有的话就先安装ntp服务就会有了(ubuntu 下sudo apt-get install ntp)
或者拷贝我的文件内容
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help driftfile /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.ubuntu.com # 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
测试
date 命令查看时间日期,
date 11111111修改时间
Mon Nov 11 11:11:00 UTC 2013
运行ntpdate 64.4.10.33更新时间 ip是ntp服务器的地址
11 Sep 05:13:21 ntpdate[1851]: adjust time server 64.4.10.33 offset -0.037363 sec
再次运行date
Wed Sep 11 04:49:01 UTC 2013
ntp时间服务器可以查看windows的时间设置
ping 一下ping time.windows.com
正在 Ping time.microsoft.akadns.net [64.4.10.33] 具有 32 字节的数据:
试了一下 直接ntpdate time.windows.com也行的
(外网要能连通 设置DNS
vi /etc/resolv.conf添加
nameserver 【dns地址】
)