一,安装NTP

[root@localhost ~]# yum install ntp
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
cdrom | 4.1 kB ::
Resolving Dependencies
--> Running transaction check
---> Package ntp.x86_64 :4.2.6p5-.el7 will be installed
--> Processing Dependency: ntpdate = 4.2.6p5-.el7 for package: ntp-4.2.6p5-.el7.x86_64
--> Processing Dependency: libopts.so.()(64bit) for package: ntp-4.2.6p5-.el7.x86_64
--> Running transaction check
---> Package autogen-libopts.x86_64 :5.18-.el7 will be installed
---> Package ntpdate.x86_64 :4.2.6p5-.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved =============================================================================================
Package Arch Version Repository Size
=============================================================================================
Installing:
ntp x86_64 4.2.6p5-.el7 cdrom k
Installing for dependencies:
autogen-libopts x86_64 5.18-.el7 cdrom k
ntpdate x86_64 4.2.6p5-.el7 cdrom k Transaction Summary
=============================================================================================
Install Package (+ Dependent packages) Total download size: k
Installed size: 1.6 M
Is this ok [y/d/N]: y
Downloading packages:
---------------------------------------------------------------------------------------------
Total MB/s | kB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : autogen-libopts-5.18-.el7.x86_64 /
Installing : ntpdate-4.2.6p5-.el7.x86_64 /
Installing : ntp-4.2.6p5-.el7.x86_64 /
Verifying : ntpdate-4.2.6p5-.el7.x86_64 /
Verifying : autogen-libopts-5.18-.el7.x86_64 /
Verifying : ntp-4.2.6p5-.el7.x86_64 / Installed:
ntp.x86_64 :4.2.6p5-.el7 Dependency Installed:
autogen-libopts.x86_64 :5.18-.el7 ntpdate.x86_64 :4.2.6p5-.el7 Complete!

二,编辑NTP配置文件"/etc/ntp.conf"

[root@localhost ~]# vim /etc/ntp.conf 

# For more information about this file, see the man pages
# ntp.conf(), ntp_acc(), ntp_auth(), ntp_clock(), ntp_misc(), ntp_mon(). 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 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 :: # Hosts on local network are less restricted.
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap //允许"192.168.1.0"使用NTP服务,nomodify notrap 不允许客户端配置服务器或者作为同步时间的节点。 # Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server .rhel.pool.ntp.org iburst
#server .rhel.pool.ntp.org iburst
#server .rhel.pool.ntp.org iburst
#server .rhel.pool.ntp.org iburst
server 0.asia.pool.ntp.org //NTP官方服务器池:http://www.pool.ntp.org/zone/asia
server 1.asia.pool.ntp.org
server 2.asia.pool.ntp.org
server 3.asia.pool.ntp.org

server 127.127.1.0        
  fudge 127.127.1.0 stratum 8  //当NTP服务不可用时,使用NTP服务器当前时间同步给客户机

#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 # Enable public key cryptography.
#crypto includefile /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 # Specify the key identifier to use with the ntpdc utility.
#requestkey # Specify the key identifier to use with the ntpq utility.
#controlkey # Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats # Disable the monitoring facility to prevent amplification attacks using ntpdc
# monlist command when default restrict does not include the noquery flag. See
# CVE-- for more details.
# Note: Monitoring will not be disabled with the limited restriction flag.
disable monitor

logfile /var/log/ntp.log

三,验证NTP服务

1,验证NTP服务器从官方NTP服务器同步时间

[root@localhost ~]# ntpstat  //查看这台服务器是否连接到NTP官方服务器
synchronised to NTP server (160.16.201.66) at stratum
time correct to within ms
polling server every s

更改下时间,改为“错误”的时间。然后等待NTP服务自动同步准确的时间。

[root@localhost ~]# date
Wed Jan :: CST

使用命令"watch ntpq -p"查看NTP详细信息

Every .0s: ntpq -p                                                                                                                                Sat Jan  :: 

     remote           refid     st t when poll reach   delay   offset  jitter
==============================================================================
y.ns.gin.ntt.ne 249.224.99.213 u 110.259
time1.maxonline .GPS. u 330.752
send.mx.cdnetwo 133.100.8.2 u 87.927
*LOCAL() .LOCL. l 0.000 0.000 0.000

大约10分钟,同步成功。下面是同步成功的时间。时间同步成功后,并不会同步给硬件时间。系统重启后还会读取硬件时间同步给系统时间,所以需要重启前"clock -w"或者写入crontab。

Every .0s: ntpq -p                                                                                                                                Fri Feb  :: 

     remote           refid     st t when poll reach   delay   offset  jitter
==============================================================================
LOCAL() .LOCL. l 0.000 0.000 0.000
+218.189.210.4 118.143.17.82 u 80.928 4.568 0.000
*x.ns.gin.ntt.ne 249.224.99.213 u 84.978 -9.332 0.000
+31.193.144.2.ar 131.107.13.100 u 311.808 -52.737 0.000
----. 218.100.41.254 u 464.010 114.567 0.000

2,验证Linux客户端从NTP服务器(192.168.10.10)同步时间

手动同步时间成功,说明NTP服务没问题。可以在Linux客户机上建立crontab任务或者配置NTP服务来同步时间。

[root@localhost ~]# ntpdate -u 192.168.1.10
Feb :: ntpdate[]: adjust time server 192.168.1.10 offset -0.000051 sec
[root@localhost ~]# date
Thu Feb :: CST

四,配置Linux客户机自动同步时间的两种方法

1,使用crontab从NTP服务器同步时间

[root@localhost ~]# crontab -e

30 3 * * *  /usr/sbin/ntpdate -u  192.168.10.10; /usr/sbin/clock -w  //每天3:30从NTP服务器同步时间,并把系统时间同步给硬件时间。

2,使用NTP服务同步时间

安装NTP服务

[root@localhost ~]# yum install ntp
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package ntp.x86_64 :4.2.6p5-.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved ===========================================================================================================================================================================
Package Arch Version Repository Size
===========================================================================================================================================================================
Installing:
ntp x86_64 4.2.6p5-.el7 cdrom k Transaction Summary
===========================================================================================================================================================================
Install Package Total download size: k
Installed size: 1.4 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : ntp-4.2.6p5-.el7.x86_64 /
Verifying : ntp-4.2.6p5-.el7.x86_64 / Installed:
ntp.x86_64 :4.2.6p5-.el7

更改"/etc/ntp.conf",注释掉原有NTP服务器地址,加入"server 192.168.10.10"

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server .rhel.pool.ntp.org iburst
#server .rhel.pool.ntp.org iburst
#server .rhel.pool.ntp.org iburst
#server .rhel.pool.ntp.org iburst
server 192.168.10.10

将当前时间修改成“错误时间”,通过NTP服务来验证是否能够同步时间。

[root@localhost ~]# date
Sat Feb :: CST
[root@localhost ~]# date -s 20130123
Wed Jan :: CST
[root@localhost ~]# watch ntpq -p
Every .0s: ntpq -p Wed Jan :: remote refid st t when poll reach delay offset jitter
==============================================================================
192.168.10.10 211.233.84.186 u 0.707
Every .0s: ntpq -p                                                                                                                                Sat Feb  :: 

     remote           refid     st t when poll reach   delay   offset  jitter
==============================================================================
*192.168.10.10 194.225.150.25 u 0.746 98.114 70.556

RHEL7学习之NTP配置的更多相关文章

  1. RHEL7学习之ISCSI配置

    ISCSI服务器:192.168.10.10 ISCSI客户端:192.168.10.20 在ISCSI服务器添加两块硬盘:/dev/sdb /de/sdc 一,在服务端安装 [root@localh ...

  2. haproxy学习之https配置

    haproxy学习之https配置   原文  http://www.cnblogs.com/ilanni/p/4941056.html   如何配置https,以及https在实际生产环境中的应用. ...

  3. 深度学习主机环境配置: Ubuntu16.04 + GeForce GTX 1070 + CUDA8.0 + cuDNN5.1 + TensorFlow

    深度学习主机环境配置: Ubuntu16.04 + GeForce GTX 1070 + CUDA8.0 + cuDNN5.1 + TensorFlow 最近在公司做深度学习相关的学习和实验,原来一直 ...

  4. 1 python学习——python环境配置

    1 python学习--python环境配置 要学习python语言,光看书看教程还是不好,得动手去写.当然,不管学习什么编程语言,最佳的方式还在于实践. 要实践,先得有一个Python解释器来解释执 ...

  5. AgileEAS.NET SOA 中间件平台5.2版本下载、配置学习(三):配置ActiveXForm运行环境

    一.前言 AgileEAS.NET SOA 中间件平台是一款基于基于敏捷并行开发思想和Microsoft .Net构件(组件)开发技术而构建的一个快速开发应用平台.用于帮助中小型软件企业建立一条适合市 ...

  6. JMeter学习-002-JMeter环境配置

    本节主要介绍 JMeter 本地环境配置(JMeter 版本为 apache-jmeter-2.12),详细配置如下: 一.JDK配置 默认用户本地已经安装且配置好 JDK.若未配置,敬请参阅我的博客 ...

  7. (转)深度学习主机环境配置: Ubuntu16.04+Nvidia GTX 1080+CUDA8.0

      深度学习主机环境配置: Ubuntu16.04+Nvidia GTX 1080+CUDA8.0 发表于2016年07月15号由52nlp 接上文<深度学习主机攒机小记>,这台GTX10 ...

  8. NTP配置实践

    前言 NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议.不管是平时使用的私人计算机还是在工作中搭建的服务器集群.时间的统一性和准确性是十分 ...

  9. 深度学习python的配置(Windows)

    Windows下深度学习python的配置 1.安装包的下载 (1)anaconda (2)pycharm 2.安装教程 (1)anaconda a.降版本 b.换源 (2)pycharm a.修改h ...

随机推荐

  1. Image 抠图,背景透明处理

    import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.File; import javax.i ...

  2. Python-lambda函数,map函数,filter函数

    lambda函数主要理解: lambda 参数:操作(参数). lambda语句中,冒号前是参数,可以有多个,用逗号隔开,冒号右边的返回值.lambda语句构建的其实是一个函数对象 map函数: ma ...

  3. .NET (上传的)文件下载

    string strPath = “//UploadFiles/Equipment/QQ截图.png” // 文件有效地址 FileInfo fileInfo = new FileInfo(strPa ...

  4. Node入门(转)

    原文链接:http://www.nodebeginner.org/index-zh-cn.html Node入门 作者: Manuel Kiessling翻译: goddyzhao & Gra ...

  5. maven构建过程

    [转载]原地址:http://www.cnblogs.com/xdp-gacl/p/4051690.html 上一篇只是简单介绍了一下maven入门的一些相关知识,这一篇主要是体验一下Maven高度自 ...

  6. jsPlumb的简单使用

    jsPlumb概述jsPlumb是一个在dom元素之间绘制连接线的javascript框架,它使用svg技术绘制连接线. 基本概念很明显,一个连线主要要解决的问题包括谁和谁连,在哪里连(连接点在哪里) ...

  7. 第十五课:奇葩的元素节点iframe

    iframe一般用来加载一个页面,然后嵌入到主页面中.创建起来消耗资源,而且消耗连接数.但是它是一个物超所值的东西,可以实现无缝刷新,模拟onhashchange跨域,安全的加载第三方资源与广告,实现 ...

  8. AngularJS作出简单聊天机器人

    简单聊天机器人 很初级的对话框形式.以前做对话框使用js,今天尝试使用AngularJS做出来 这里直接使用自己写的JSON数据. <!DOCTYPE html> <html lan ...

  9. hbase scan 的例子

    /** * Created by han on 2016/1/28. */ import org.apache.hadoop.conf.Configuration; import org.apache ...

  10. x-editable 的使用方法

    1.首先在html网页中定义一个a标签(如下<%#%>是asp.net的语法) <a href="#"  data-pk="<%#Eval(&qu ...