NTP服务器移植及应用
测试平台:S3C2410
内核版本:linux-3.10.1
1.下载源码
http://www.ntp.org/
2.配置及编译
$ ./configure --host=arm-linux --prefix=/opt/rootfs/
$ make
$ make install
部署说明:
1.复制生成的文件至开发板对应的目录;
2.对于生成的二进制文件最好先用strip命令优化一下,以提高运行速度和节省空间;
NTP时间服务器设置:
建立配置文件/etc/ntp.conf
# restrict 命令用于权限设定
# 格式:restrict {IP} [mask netmask] [parameter]
# ignore: 拒绝该地址的所有的NTP服务;
# nomodify: 客户端可通过服务器来授时,但不能使用 ntpc和ntpq这两个命令来修改服务器的时间参数;
# noquery: 不对该客户端提供授时服务;
# notrap: 不提供 trap 远端事件登陆 (remote event logging) 的服务;
# notrust: 拒绝没有认证的客户端;
# 没有参数项,表示不受任何限制;
# 权限设定,本机地址不受任何限制
restrict 127.0.0.1
# 允许192.168.0.0 网段的所有主机对时
restrict 192.168.0.0 mask 255.255.255.0 nomodify
# 允许192.168.100.20这台主机对时
restrict 192.168.100.20 mask 255.255.255.255 nomodify
# server 用于指定上层的时间服务器
# 格式:server {IP} [ prefer ]
# prefer表示优先使用的服务器
server 210.72.145.44
server time.nist.gov
server time.stdtime.gov.tw
# 对上层服务器开放所有权限
restrict 210.72.145.44
restrict time.nist.gov
restrict time.stdtime.gov.tw
# 指定自动更新时间(单位为分钟)
# fudge胡说八道??
fudge time.nist.gov stratum 60
配置完成,启动ntpd.
如果运行时出现错误:
Error resolving 210.72.145.44: Servname not supported for ai_socktype (-8) 1 Jan 02:58:36
ntpdate[1148]: Can't find host 210.72.145.44: Servname not supported for ai_socktype (-8) 1 Jan 02:58:36
ntpdate[1148]: no servers can be used, exiting
原因是未指定ntp端口号,修改/etc/services文件,添加以下两行
ntp 123/tcp
ntp 123/udp
客户端手动更新本地时间:
# ntpdata 210.72.145.44
将系统时间写入BIOS
# hwclock -w
几个常用的时间服务器:
time.nist.gov 美国国家标准与技术研究院
210.72.145.44 中国科学院国家授时中心