zoukankan      html  css  js  c++  java
  • NTP服务安装

     

    NTP概要

    NTP要提供准确的时间,就必须有准确的时间来源,那可以用格林尼治时间吗?答案是否定的。因为格林尼治时间是以地球自转为基础的时间计量系统,但是地球每天的自转是有些不规则的,而且正在缓慢减速,因此,格林尼治时间已经不再被作为标准时间使用。

    新的标准时间,是由原子钟报时的国际标准时间UTCUniversal Time Coordinated,世界协调时)。所以NTP获得UTC的时间来源可以是原子钟、天文台、卫星,也可以从Internet上获取。

    有了准确而可靠的的时间源,那这个时间如何传播呢?在NTP中,定义了时间按照服务器的等级传播,按照离外部UTC源远近将所有的服务器归入不同的Stratum(层)中,例如把通过GPSGlobal Positioning System,全球定位系统)取得发送标准时间的服务器叫Stratum-1NTP服务器,而Stratum-2则从Stratum-1获取时间,Stratum-3Stratum-2获取时间,以此类推,但Stratum层的总数限制在15以内。所有这些服务器在逻辑上形成阶梯式的架构相互连接,而Stratum-1时间服务器是整个系统的基础,这种阶梯式的架构示意图如图1所示。

    图1 NTP阶梯式的架构示意图

    计算机主机一般同多个时钟服务器连接,利用统计学的算法过滤来自不同服务器的时间,以选择最佳的路径和来源以便校正主机时间。即使在主机长时间无法与某一时钟服务器联系的情况下,NTP服务依然可以有效运转。

    为了防止对时钟服务器的恶意破坏,NTP使用了识别机制,检查发送来的信息是否是真正来自所宣称的时钟服务器并检查信息的返回路径,以提供对抗干扰的保护机制。[1] 

    NTP时间同步报文中包含的时间是格林威治时间,是从1900年开始计算的秒数

    • NTP安装

    1.编译安装ntp源码包

    [root@server tools]# tar xf ntp-4.2.6p5.tar.gz

    [root@server tools]# cd ntp-4.2.6p5

    [root@server ntp-4.2.6p5]# ./configure --prefix=/usr/local/ntp --enable-all-clocks --enable-parse-clocks

    [root@server ntp-4.2.6p5]# make && make install

    2.修改配置文件

    [root@server ~]# cp /etc/ntp.conf /etc/ntp.conf.bak

    [root@server ~]# vi /etc/ntp.conf

    1)允许任何IP的客户机都可以进行时间同步

    将"restrict default kod nomodify notrap nopeer noquery"这行修改成:

    restrict default nomodify

    2)只允许192.168.1.*网段的客户机进行时间同步

    在"restrict default nomodify notrap noquery(表示默认拒绝所有IP的时间同步)"之后增加一行:

    restrict 192.168.1.0 mask 255.255.255.0 nomodify

    3、启动NTP服务并设置随机启动

    [root@server ~]# service ntpd start

    [root@server ~]# chkconfig --level 35 ntpd on

    4、查看ntp服务器工作情况

    [root@server ~]# netstat -unl |grep 123 #查看123端口,操作结果如图

    udp 0 0 192.168.1.41:123 0.0.0.0:*

    udp 0 0 127.0.0.1:123 0.0.0.0:*

    udp 0 0 0.0.0.0:123 0.0.0.0:*

    udp 0 0 fe80::20c:29ff:feb1:123 :::*

    udp 0 0 ::1:123 :::*

    udp 0 0 :::123 :::*

    5、查看ntp进程是否正常启动

    [root@server ~]# ps -ef|grep ntp

    ntp 17589 1 0 21:20 ? 00:00:00 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g

    root 17607 4441 0 21:26 pts/0 00:00:00 grep ntp

    PS:ntpd启动后,客户机要等几分钟再与其进行时间同步,否则会提示"no server suitable for synchronization found"错误。

    • 客户机验证

    [root@client ~]# date serverIP #查看服务器的ntp服务是否有响应

    [root@localhost ntp]# ntpdate -d 10.200.51.225

    21 Jan 09:57:39 ntpdate[2790]: ntpdate 4.2.6p5@1.2349-o Fri Jul 24 10:54:24 UTC 2015 (1)

    Looking for host 10.200.51.225 and service ntp

    host found : 10.200.51.225

    transmit(10.200.51.225)

    receive(10.200.51.225)

    transmit(10.200.51.225)

    receive(10.200.51.225)

    transmit(10.200.51.225)

    receive(10.200.51.225)

    transmit(10.200.51.225)

    receive(10.200.51.225)

    10.200.51.225: Server dropped: Leap not in sync

    server 10.200.51.225, port 123

    stratum 3, precision -24, leap 11, trust 000

    refid [10.200.51.225], delay 0.02856, dispersion 0.00009

    transmitted 4, in filter 4

    reference time: da4aae25.1bacb976 Thu, Jan 21 2016 9:08:53.108

    originate timestamp: da4aba6a.dd962e42 Thu, Jan 21 2016 10:01:14.865

    transmit timestamp: da4ab993.8900d9af Thu, Jan 21 2016 9:57:39.535

    filter delay: 0.02950 0.02870 0.02856 0.02882

    0.00000 0.00000 0.00000 0.00000

    filter offset: 215.3283 215.3287 215.3286 215.3286

    0.000000 0.000000 0.000000 0.000000

    delay 0.02856, dispersion 0.00009

    offset 215.328671 # offset有时间差即可

  • 相关阅读:
    Something I know about WebDynpro
    Details about support package implementation
    CRM Middleware Performance Topics
    Way to configure the logon navigaion layouts via Business Roles in CRM
    DOM 常用节点类型和方法
    第一届 xdef 会议日程
    去除百度音乐盒广告的chrome插件 持续更新
    从人人网抓取高校数据信息,包括,省份 高校 院系 (提供最终SQL文件下载)
    PHP 与 JSON
    解决HTTPS 发送请求走socket问题
  • 原文地址:https://www.cnblogs.com/sheng1255blog/p/5151876.html
Copyright © 2011-2022 走看看