1. 概述

大数据产生与处理系统是各种计算设备集群的,计算设备将统一、同步的标准时间用于记录各种事件发生时序,如E-MAIL信息、文件创建和访问时间、数据库处理时间等。大数据系统内不同计算设备之间控制、计算、处理、应用等数据或操作都具有时序性,若计算机时间不同步,这些应用或操作或将无法正常进行。大数据系统是对时间敏感的计算处理系统,时间同步是大数据能够得到正确处理的基础保障,是大数据得以发挥作用的技术支撑。大数据时代,整个处理计算系统内的大数据通信都是通过网络进行。时间同步也是如此,利用大数据的互联网络传送标准时间信息,实现大数据系统内时间同步。网络时间同步协议(NTP)是时间同步的技术基础。

NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。它的用途是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可达0.1ms,在互联网上绝大多数的地方其精度可以达到1-50ms。它可以使计算机对其服务器或时钟源(如石英钟,GPS等等)进行时间同步,它可以提供高精准度的时间校正,而且可以使用加密确认的方式来防止病毒的协议攻击。

2. Linux Ntp服务器的安装和配置

笔者使用的操作系统是CentOS,其中使用的是yum源进行软件的包的安装和配置,对于Ubuntu操作系统使用apt-get进行软件的安装和配置是一样的。笔者这里使用一台NTP主服务器,两天从服务器同步主服务器的时间进行配置和测试。

2.1 确认当前服务器是否安装Ntp

确认是否已安装ntp

【命令】rpm –qa | grep ntp

若只有ntpdate而未见ntp,则需删除原有ntpdate。如:

ntpdate-4.2.6p5-22.el7_0.x86_64
fontpackages-filesystem-1.44-8.el7.noarch
python-ntplib-0.3.2-1.el7.noarch

删除已安装ntp

【命令】yum –y remove ntpdate-4.2.6p5-22.el7.x86_64

重新安装ntp

【命令】yum –y install ntp

3. 配置NTP服务器

3.1 配置所有NTP节点的IP地址和网关(可以不配置)

【命令】vim /etc/ntp.conf

restrict 11.11.0.25 nomodify notrap nopeer noquery  //当前节点IP地址
restrict 11.11.2.1 mask 255.255.0.0 nomodify notrap  //集群所在网段的网关(Gateway),子网掩码(Genmask)

3.2 配置NTP主服务器

选择一个主节点node24,修改其/etc/ntp.conf

【内容】在server部分添加一下部分,并注释掉server 0 ~ n。主服务器可以不用全部注释,可以保证一个有一个外网的同步时间服务器(比如0.rhel.pool.ntp.org)

server 127.127.1.0
Fudge 127.127.1.0 stratum 10
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).driftfile /var/lib/ntp/drift# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.rhel.pool.ntp.org
#server 1.rhel.pool.ntp.org
#server 2.rhel.pool.ntp.org#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient            # broadcast client
#broadcast 224.0.1.1 autokey        # multicast server
#multicastclient 224.0.1.1      # multicast client
#manycastserver 239.255.254.254     # manycast server
#manycastclient 239.255.254.254 autokey # manycast client# 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  # Enable public key cryptography.
#cryptoincludefile /etc/ntp/crypto/pw# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys# Specify the key identifiers which are trusted.
#trustedkey 4 8 42# Specify the key identifier to use with the ntpdc utility.
#requestkey 8# Specify the key identifier to use with the ntpq utility.
#controlkey 8# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats

3.3 配置NTP从服务器

配置node25,node26,node27 NTP从服务器。用来同步到node24主服务器,从服务器不断的发送同步请求给主服务器进行时间同步。

【命令】vi /etc/ntp.conf

【内容】在server部分添加一下部分,并注释掉server 0 ~ n。

【内容】在server部分添加如下语句,将server指向主节点。

server node24
Fudge node24 stratum 10
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).driftfile /var/lib/ntp/drift# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.rhel.pool.ntp.org
#server 1.rhel.pool.ntp.org
#server 2.rhel.pool.ntp.org#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient            # broadcast client
#broadcast 224.0.1.1 autokey        # multicast server
#multicastclient 224.0.1.1      # multicast client
#manycastserver 239.255.254.254     # manycast server
#manycastclient 239.255.254.254 autokey # manycast client# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
server  node24  # local clock
fudge   node24 stratum 10   # Enable public key cryptography.
#cryptoincludefile /etc/ntp/crypto/pw# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys# Specify the key identifiers which are trusted.
#trustedkey 4 8 42# Specify the key identifier to use with the ntpdc utility.
#requestkey 8# Specify the key identifier to use with the ntpq utility.
#controlkey 8# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats

4. NTP服务器相关命令

4.1 启动ntp服务

ssh node$val "/etc/init.d/ntpd start"

4.2 关闭ntp服务

ssh node$val "/etc/init.d/ntpd stop"

4.3 查看ntp服务器有无和上层ntp连通

ssh node$val "ntpstat"

4.4 查看ntp服务器与上层ntp的状态

【命令】ntpq -p

  • remote:本机和上层ntp的ip或主机名,“+”表示优先,“*”表示次优先
  • refid:参考上一层ntp主机地址
  • st:stratum阶层
  • when:多少秒前曾经同步过时间
  • poll:下次更新在多少秒后
  • reach:已经向上层ntp服务器要求更新的次数
  • delay:网络延迟
  • offset:时间补偿
  • jitter:系统时间与bios时间差

4.5 查看ntpd进程的状态

【命令】watch "ntpq -p"
【终止】按 Ctrl+C 停止查看进程。

第一列中的字符指示源的质量。星号 ( * ) 表示该源是当前引用。

  • remote:列出源的 IP 地址或主机名。
  • when:指出从轮询源开始已过去的时间(秒)。
  • poll:指出轮询间隔时间。该值会根据本地时钟的精度相应增加。
  • reach:是一个八进制数字,指出源的可存取性。值 377 表示源已应答了前八个连续轮询。
  • offset:是源时钟与本地时钟的时间差(毫秒)。

4.6 设置开机启动

【命令】chkconfig ntpd on

5. /etc/ntp.conf 配置内容

# 1. 先处理权限方面的问题,包括放行上层服务器以及开放局域网用户来源:
restrict default kod nomodify notrap nopeer noquery     <==拒绝 IPv4 的用户
restrict -6 default kod nomodify notrap nopeer noquery  <==拒绝 IPv6 的用户
restrict 220.130.158.71   <==放行 tock.stdtime.gov.tw 进入本 NTP 的服务器
restrict 59.124.196.83    <==放行 tick.stdtime.gov.tw 进入本 NTP 的服务器
restrict 59.124.196.84    <==放行 time.stdtime.gov.tw 进入本 NTP 的服务器
restrict 127.0.0.1        <==底下两个是默认值,放行本机来源
restrict -6 ::1
restrict 192.168.100.0 mask 255.255.255.0 nomodify <==放行局域网用户来源,或者列出单独IP# 2. 设定主机来源,请先将原本的 [0|1|2].centos.pool.ntp.org 的设定批注掉:
server 220.130.158.71 prefer  <==以这部主机为最优先的server
server 59.124.196.83
server 59.124.196.84# 3.默认的一个内部时钟数据,用在没有外部 NTP 服务器时,使用它为局域网用户提供服务:
# server    127.127.1.0     # local clock
# fudge     127.127.1.0 stratum 10# 4.预设时间差异分析档案与暂不用到的 keys 等,不需要更动它:
driftfile /var/lib/ntp/drift
keys      /etc/ntp/keys

6. NTP 时间同步 层次(stratum)

stratum根据上层server的层次而设定(+1)。对于提供network time service provider的主机来说,stratum的设定要尽可能准确。而作为局域网的time service provider,通常将stratum设置为10。

0层的服务器采用的是原子钟、GPS钟等物理设备,stratum 1与stratum 0 是直接相连的,往后的stratum与上一层stratum通过网络相连,同一层的server也可以交互。ntpd对下层client来说是service server,对于上层server来说它是client。

ntpd根据配置文件的参数决定是要为其他服务器提供时钟服务或者是从其他服务器同步时钟。所有的配置都在/etc/ntp.conf文件中。

7. 配置NTP服务器相关问题

查看ntp状态时,可能会出现如下所示情况

① unsynchronised time server re-starting polling server every 8 s
② unsynchronised polling server every 8 s

这种情况属于正常,ntp服务器配置完毕后,需要等待5-10分钟才能与/etc/ntp.conf中配置的标准时间进行同步。等一段时间之后,再次使用ntpstat命令查看状态,就会变成如下正常结果:

Linux基础:配置ntp时间服务器相关推荐

  1. linux系统安装ntp,Linux系统安装配置NTP时间服务器

    NTP(The Network Time Protocol) 是网络时间协议,用以同步网络内计算机的时间. 它通过udp包交换,用特定算法进行协商,从而把计算机上的时间与时间服务器上的 时间保持一致. ...

  2. Linux下配置NTP时间服务器

    2019独角兽企业重金招聘Python工程师标准>>> Linux下配置NTP服务器 一.前言: Network Time Protocol(NTP)是用来使计算机时间同步化的一种协 ...

  3. Linux下 配置NTP时间服务器

    多台linux服务器时间同步 时间服务器作用: 若计算机时间不同步,如E-MAIL信息.文件创建和访问时间.数据库处理时间等这些应用或操作或将无法正常进行. 时间同步是业务能够得到正确处理的基础保障. ...

  4. Linux配置ntp时间服务器

    Linux配置ntp时间服务器 时间服务器作用: 大数据产生与处理系统是各种计算设备集群的,计算设备将统一.同步的标准时间用于记录各种事件发生时序, 如E-MAIL信息.文件创建和访问时间.数据库处理 ...

  5. centos 7 配置ntp时间服务器

    文章目录 centos 7 配置ntp时间服务器 参考地址: 1. 服务端 1.1 安装ntp服务和ntpdate工具 1.2 修改配置文件 1.3 设置开机自启(初始化) 1.4 启用ntp服务 1 ...

  6. Redhat6.5下配置NTP时间服务器

    Redhat6.5下配置NTP时间服务器 在配置服务之前需要知道的一些概念: [整篇文章有很多是借鉴别人的,少部分是自己编写的,希望能对大家有所裨益] 1.时间和时区 如果有人问你说现在几点? 你看了 ...

  7. 配置ntp时间服务器,确保客户端主机能和服务主机同步时间

    配置ntp时间服务器,确保客户端主机能和服务主机同步时间 1配置Chrony服务器 先下载chrony dnf install -y chrony 查看和配置chrony.conf文件 rpm -qc ...

  8. Linux下配置rdate时间服务器

    本文出自:http://www.linuxsong.org/2011/11/time-server/ 配置多台服务器时,经常需要让各个服务器之间的时间保持同步,如果服务器有外网环境,可以直接同外部的时 ...

  9. Linux配置ntp时间服务器(全)

    时间服务器作用: 大数据产生与处理系统是各种计算设备集群的,计算设备将统一.同步的标准时间用于记录各种事件发生时序, 如E-MAIL信息.文件创建和访问时间.数据库处理时间等. 大数据系统内不同计算设 ...

最新文章

  1. Cocos Creator里localStorage的使用
  2. 最新!中国内地大学ESI排名出炉:362所高校上榜,南方科技大学、深圳大学、暨南大学表现出色!...
  3. 解决sdk manager无法更新的问题
  4. HTML5 audio与video标签实现视频播放,音频播放
  5. Pycharm-列出代码结构
  6. 页面编码和被请求的资源编码如果不一致如何处理
  7. 科室鄙视链最低端,居然是这类人
  8. linux的进程/线程/协程系列5:协程的发展复兴与实现现状
  9. django 1.8 官方文档翻译: 2-1-1 模型语法(初稿)
  10. TWebBrowser 与 MSHTML(3): window 对象的属性、方法、事件纵览
  11. 成功是需要付出代价的: 32个成功观念分享
  12. WinCE学习系列(1)——在VS2008的环境下安装WinCE 5.0仿真模拟器
  13. MacBook Pro 进入屏保 发热严重
  14. p值小于0.05拒绝还是接受_干货:关乎你的实验成败,0.05这个值不容小觑!
  15. 数据库mongodb效率测试
  16. Python之路(一)
  17. 【渝粤题库】陕西师范大学200611 英语修辞 作业
  18. JIAR安装报错IRA Startup Failed
  19. 软件测试如何分类?又有哪些类别?
  20. 微信发照片怎么在服务器上删除,我们发现微信发送原图,确实会暴露位置信息!但你可以这么解决...

热门文章

  1. centos WOL唤醒win10、win10定时任务
  2. UT163/UT165打开隐藏功能&常见问题代码解决方法
  3. 第五章 Java的基础类之String、StringBuffer、StringBuilder(下)
  4. ArcGIS for Desktop创建“内部缓冲区”
  5. Native 内存wrap
  6. vgpu服务器显卡性能,共享虚拟 GPU (vGPU)
  7. html圆圈点选择,如何用html5点击相应链接时用颜色填充圆圈
  8. oracle 恢复几种方法,重装系统后ORACLE的恢复的几种方法(转载)
  9. 服务器宕机是什么原因
  10. 公司使用的阿里云服务器宕机了,瞬间系统瘫痪