`
eksliang
  • 浏览: 592270 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

NTP服务器的搭建

阅读更多

一.检查ntpd服务是否安装

centos6以后的操作系统,默认已经安装了ntp服务,查看命令如下:

[root@master ~]# rpm -qa |grep ntp
ntpdate-4.2.6p5-1.el6.centos.x86_64
fontpackages-filesystem-1.41-1.1.el6.noarch
ntp-4.2.6p5-1.el6.centos.x86_64

 如上,就表示NTP正确安装了

 

二.检查上层NTP服务器是否正常连通

    如下三个地址是目前国内使用比较通用的上层NTP服务器地址

210.72.145.44 	 # 中国国家受时中心
202.112.10.36    # 1.cn.pool.ntp.org
59.124.196.83    # 0.asia.pool.ntp.org

 按照网上例子去测试,与外网ntp服务器打交道,我这里都失败了,如下所示。

 

[root@slave1 ~]# ntpdate 210.72.145.44
 6 Jul 09:43:06 ntpdate[29799]: no server suitable for synchronization found
[root@slave1 ~]# ntpdate -q 210.72.145.44
server 210.72.145.44, stratum 0, offset 0.000000, delay 0.00000
 6 Jul 09:43:45 ntpdate[29934]: no server suitable for synchronization found
[root@slave1 ~]#  ntpdate -q 1.cn.pool.ntp.org
server 202.118.1.81, stratum 0, offset 0.000000, delay 0.00000
server 110.75.190.198, stratum 0, offset 0.000000, delay 0.00000
server 182.92.12.11, stratum 0, offset 0.000000, delay 0.00000
server 115.28.122.198, stratum 0, offset 0.000000, delay 0.00000
 6 Jul 09:44:07 ntpdate[29953]: no server suitable for synchronization found
 后来在网上找了些资料,说出现这样的原因就是现在的官方ntp服务器做了限制,不能使用ntpdate直接去同步时间了,要使用rdate -s serviceip这个命令与官方ntp服务器同步时间

 

 

目前的解决方案?

答:在内网一台服务器上面搭建NTP服务器,其他机器与这台服务器,进行同步时间,而NTP服务这台机器应该能够与外网进行通讯,这台服务器使用rdate -s serviceip与外网定时同步时间。

这种方案的好处就是,实际项目中我们其实要做的就是保证集群中所有机器时间同步就可以了(而且通常情况下,集群是部署在内网的,不能与外网进行通讯),并不一定要保证与标准的时间进行同步;这个时候我们只需要去掉rdate -s serviceip的定时任务而已。

 

三、具体实现细节

3.1.配置rdate与外网进行时间同步

执行命令如下:

[root@slave1 ~]# rdate -s 1.cn.pool.ntp.org
#每隔15分钟去上层服务器同步一次时间
[root@slave1 ~]# */15 * * * * rdate -s 0.asia.pool.ntp.org

 

温馨提示: 

中国官方提供的对时服务器地址如下所示:http://www.pool.ntp.org/zone/cn

 

 3.2.搭建内网的ntp服务器

  • 修改配置

搭建内网ntp服务非常简单,只需要修改/etc/ntp.conf这个文件就可以了,改动如下,依葫芦画瓢就可以了。

 

#允许192.168.238.0/n网段的主机来进行对时,但不允许客户端来修改,登录我的NTP服务器,在我的实验环境中,内网使用 192.168.238.0/12网段.
# Hosts on local network are less restricted.
restrict 192.168.238.0 mask 255.255.255.0 nomodify notrap
#允许任何IP的客户机都可以进行时间同步
restrict default nomodify

#屏蔽上层的对时服务器,因为我这里对外时使用rdate
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org
#server 1.centos.pool.ntp.org
#server 2.centos.pool.ntp.org

# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available. 
# 外部时间服务器不可用时,以本地时间作为时间服务
server  127.127.1.0     # local clock
fudge   127.127.1.0 stratum 10

 

  •  启动ntp服务
[root@slave1 ~]# service ntpd start
Starting ntpd: [  OK  ]

 

  •  开机自动启动
[root@slave1 ~]# chkconfig ntpd on
[root@slave1 ~]# chkconfig --list ntpd
ntpd            0:off   1:off   2:on    3:on    4:on    5:on    6:off

 

 温馨提示:

此时启动ntpd服务器,客户端立刻使用ntpdate来同步时间,会报如下错误

"no server suitable for synchronization found "

原因分析:

在ntp server上启动ntp服务后,ntp server自身或者与其server的同步的须要一个时候段(我这种配置屏蔽了与外部的时间同步,以本身时间作为时间服务),这个过程可能是5分钟,在这个时候之内涵客户端运行ntpdate号令时会产生no server suitable for synchronization found的错误。 

 

3.3.客户端同步时间

[root@master ~]# ntpdate  192.168.238.133
 5 Jul 18:34:35 ntpdate[8667]: adjust time server 192.168.238.133 offset -0.013669 sec
#在crontab例行任务中添加没15分钟同步一次时间,如下所示
*/15 * * * * /usr/sbin/ntpdate 192.168.27.35;hwclock -w  

 

按照如下博客配置ntp.conf,以前是可以的,现在master与外网同步时间不行了,不知道是不是我的网络问题

http://acooly.iteye.com/blog/1993484

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics