Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1284553
  • 博文数量: 161
  • 博客积分: 10192
  • 博客等级: 上将
  • 技术积分: 2165
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-27 17:09
文章分类

全部博文(161)

文章存档

2012年(2)

2011年(13)

2010年(137)

2009年(5)

2008年(4)

我的朋友

分类: LINUX

2010-07-21 00:10:50

Network Time Protocol(NTP,网络时间协议)用于同步它所有客户端时钟的服务。
NTP服务器将本地系统的时钟与一个公共 的NTP服务器同步然后作为时间主机提供服务,使本地LAN网络的所有客户端能同步时钟。

1。配置/etc/ntp.conf:
   restrict default nomodify notrap noquery
  restrict 127.0.0.1
   restrict 10.0.0.0 mask 255.255.255.0 nomodify notrap
  restrict 10.0.1.0 mask 255.255.255.0 nomodify notrap
  server 0.centos.pool.ntp.org
  server 1.centos.pool.ntp.org
  server 2.centos.pool.ntp.org
  server 3.centos.pool.ntp.org
  server 127.127.1.0
  fudge 127.127.1.0 stratum 10

注释:restrict、default 定义默认访问规则,
     nomodify禁止远程主机修改本地服务器配置,
     notrap拒绝特殊的ntpdq捕获消息,
     noquery拒绝btodq/ntpdc查询(这里的查询是服务器本身状态查询)。
     配置文件的最后两行作用是当服务器与公用的时间服务器失去联系时以本地时间为客户端提供时间服务。

2。端口
  ntp使用udp 协议,记得开放其123端口。
iptables -t filter -A INPUT -p udp --destination-port 123 -j ACCEPT

3。启动NTPD
  service ntpd start
4。在客户端安装NTP,安装过 程同NTP在服务器端。

    客户端开启ntp服务

    #service ntpd start

    与ntp服务器同步

    #ntpdate (ntp服务器地址)

接下来编辑 /etc/ntp.conf

ntp.conf
#############################################################################################
#restrict default ignore
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10

server stdtime.gov.hk # A stratum 1 server at server.org
server 192.168.x.y #x.y为你前面所装NTP SERVER机器在局域网里的IP
driftfile /etc/ntp/drift
broadcastdelay 0.008
authenticate no
keys /etc/ntp/keys

restrict 192.168.x.0 mask 255.255.255.0 notrust nomodify notrap//x.0为你
所在局域网段
restrict 127.0.0.1
restrict 192.168.x.y #x.y为你前面所装NTP SERVER机器在局域网里的IP

#############################################################################################

同时配置
#/sbin/service ntpd start //启动ntpd 参数可为restart start stop
#/sbin/chkconfig --add ntpd
#/sbin/chkconfig --level 234 ntpd on //配置在开机时运行

如何检查?
#netstat -unl | grep 123 //查看123端口
#ndptrace 192.168.x.y //看校对时间过程,出现offset即为正常 否则为time out

# ntpq -p
如果出现 jitter的值 为4000则是防火墙或者网络问题
正常为
remote refid st t when poll reach delay offset jitter
==============================================================================

*clock.nc.fukuok .GPS. 1 u 43 64 37 19.067 -6.884 10.339
+clock.tl.fukuok .GPS. 1 u 36 64 35 19.670 -3.259 2.341
LOCAL(0) LOCAL(0) 5 l 45 64 37 0.000 0.000 0.001
阅读(632) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~