ntp time server

搭建时钟同步服务器

这里选择 cdh1 节点为时钟同步服务器,其他节点为客户端同步时间到该节点。安装ntp:

$ yum install ntp

修改 cdh1 上的配置文件 /etc/ntp.conf :

restrict default ignore   //默认不允许修改或者查询ntp,并且不接收特殊封包
restrict 127.0.0.1        //给于本机所有权限
restrict 192.168.56.0 mask 255.255.255.0 notrap nomodify  //给于局域网机的机器有同步时间的权限
server  192.168.56.121     # local clock
driftfile /var/lib/ntp/drift
fudge   127.127.1.0 stratum 10

启动 ntp:

#设置开机启动
$ chkconfig ntpd on

$ service ntpd start

ntpq用来监视ntpd操作,使用标准的NTP模式6控制消息模式,并与NTP服务器通信。

ntpq -p 查询网络中的NTP服务器,同时显示客户端和每个服务器的关系。

$ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*LOCAL(1)        .LOCL.           5 l    6   64    1    0.000    0.000   0.000
  • ”* “:响应的NTP服务器和最精确的服务器。
  • ”+”:响应这个查询请求的NTP服务器。
  • “blank(空格)”:没有响应的NTP服务器。
  • “remote” :响应这个请求的NTP服务器的名称。
  • “refid “:NTP服务器使用的更高一级服务器的名称。
  • “st”:正在响应请求的NTP服务器的级别。
  • “when”:上一次成功请求之后到现在的秒数。
  • “poll”:当前的请求的时钟间隔的秒数。
  • “offset”:主机通过NTP时钟同步与所同步时间源的时间偏移量,单位为毫秒(ms)。

客户端的配置

在cdh2和cdh3节点上执行下面操作:

$ ntpdate cdh1

Ntpd启动的时候通常需要一段时间大概5分钟进行时间同步,所以在ntpd刚刚启动的时候还不能正常提供时钟服务,报错”no server suitable for synchronization found”。启动时候需要等待5分钟。

如果想定时进行时间校准,可以使用crond服务来定时执行。

# 每天 1:00 Linux 系统就会自动的进行网络时间校准
00 1 * * * root /usr/sbin/ntpdate 192.168.56.121 >> /root/ntpdate.log 2>&1

3 Responses so far.

  1. Quest bars says:
    I have been surfing online more than 2 hours today,
    yet I never found any interesting article like yours. It’s pretty worth enough for
    me. Personally, if all webmasters and bloggers made good
    content as you did, the web will be much more useful than ever before.
  2. Quest bars says:
    Its like you read my mind! You appear to know so much about this,
    like you wrote the book in it or something. I think that you can do
    with a few pics to drive the message home a little bit, but other than that, this is fantastic blog.
    A great read. I will certainly be back.
  3. Great – I should definitely pronounce, impressed with your web site. I had no trouble navigating through all the tabs as well as related information ended up being truly easy to do to access. I recently found what I hoped for before you know it at all. Quite unusual. Is likely to appreciate it for those who add forums or something, website theme . a tones way for your client to communicate. Excellent task.

LEAVE A COMMENT