一,安装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. __thread关键字[转]

    自 http://blog.csdn.net/liuxuejiang158blog/article/details/14100897 __thread是GCC内置的线程局部存储设施,存取效率可以和全局 ...

  2. etc 安装及使用

    键值存储仓库,用于配置共享和服务发现. A highly-available key value store for shared configuration and service discover ...

  3. 通过innobackupex实现对MySQL的增量备份与还原

    备份 增量备份是基于完整备份的,所以我们需要先做一次完整备份: innobackupex --password=test /backup/ 备注:test是我的MySQL服务的root用户的密码,/b ...

  4. OpenVZ VPS加速方案–Final Speed

    body,td { font-family: 微软雅黑; font-size: 10pt }   OpenVZ VPS加速方案–Final Speed OpenVZ VPS加速方案–Final Spe ...

  5. JavaEE第一天知识点总结

    JavaEE第一天知识点总结 持久化是将程序中的数据在瞬时状态和持久状态间转换的机制 DAO: 英文全称: Date Access Object(数据存取对象) 位于业务逻辑和持久化数据之间 实现对持 ...

  6. Mysql binlog

    理解Mysql binlog 日志的三种模式   本文介绍下,mysql中binlog日志的三种模式,了解了各种模式的不同之处,才能更好地应用.有需要的朋友建议参考下.   一,模式1 Row Lev ...

  7. 第二次C语言作业

    实验一:判断成绩等级. 给定一百分制成绩,要求输出成绩的等级.90以上为A,80-89为B,70-79为C,60-69为D,60分以下为E,输入大于100或小于0时输出"输入数据错误&quo ...

  8. SQL Server 索引(index) 和 视图(view) 的简单介绍和操作

    --索引(index)和视图(view)-- --索引(index)----概述: 数据库中的索引类似于书籍的目录,他以指针形式包含了表中一列或几列组合的新顺序,实现表中数据库的逻辑排序.索引创建在数 ...

  9. Jquery--JS的函数包

    Jquery-----JS的函数包,直接来调用方法. 一.基本知识 用法:把jquery-1.7.2.js直接复制到要做的网站项目中,拖拽引用和JS用法一样. 二.选择器 [1]基本: 1.取ID:v ...

  10. dscp hftp

    http://blog.163.com/caipeipei_love@126/blog/static/25966032201142712856862/