一.检查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
相关推荐
威伦通NTP服务器搭建流程(计算机时间与触摸屏时间同步).pdf
简易ntp服务器搭建,步骤不多,NTP服务器搭建 10.181.16.52 服务器端 10.181.16.5客户端 10.181.16.6客户端 10.181.16.7客户端
Win7搭建局域网NTP服务器全文共5页,当前为第1页。Win7搭建局域网NTP服务器全文共5页,当前为第1页。近日,本人想在局域网内通过普通的windows 7 PC搭建一台NTP服务器,可看似简单的配置却给我捣腾了了半天。初期,...
NTP服务器搭建
Window10 NTP服务器搭建,用以为设备提供NTP时间校正服务。
做了3个小程序,一键搭建NTP服务器小软件
我自己总结的如何搭建ntp服务器,希望大家也能从中学到知识.
本文主要讲述了对于NTP服务器和客户端如何进行配置,本文主要以LINUX和CISCO交换机为例,详细的介绍了配置过程和操作步骤,下面文章将会使你受益匪浅。 出于网管的目的,我们架设了syslog,来监控交换机日志,同时也...
Window搭建局域网NTP服务器借鉴.pdf
Suselinux11NTP服务器端搭建设置宣贯.pdf
自行搭建NTP服务器,Windows xp NTP服务器的配置(2003配置方式一样) 1) 首先需要关闭作为NTP服务器的windows系统自带的防火墙,否则将同步不成功。 2) 单击“开始”,单击“运行”,键入 regedit,然后单击...
centos 下搭建ntp时间服务器,centos 下搭建ntp时间服务器,centos 下搭建ntp时间服务器,
搭建时间服务器NTP
安装ntp程序后服务器即使ntp服务器端又是ntp客户端,启用了ntp服务,同时在本机执行ntpdate 同步时间会出现问题”the NTP socket is in use, exiting”,解决办法是停止本机的ntp服务程序。 NTP (server,client) ...
只有两个配置文件 一个服务器 一个客户端 替换就可以了
ntp时间服务器搭建详细文档
Win7搭建局域网NTP服务器.pdf
windows搭建NTP服务器说明
Suselinux11NTP服务器端搭建设置.pdf
NTP时间服务器可用于需要同步时间的服务器之间,以一台服务器作为标准时间,让其他服务器与这台服务器统一时间。