一,安装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. NodeJs 连接mysql一例。

    var mysql = require('mysql'); var connection = mysql.createConnection({ host :'127.0.0.1', user :'ro ...

  2. DHCP snooping

    DHCP snooping 技术介绍   DHCP监听(DHCP Snooping)是一种DHCP安全特性.Cisco交换机支持在每个VLAN基础上启用DHCP监听特性.通过这种特性,交换机能够拦截第 ...

  3. android Spinner的简单用法

    上代码: spinner = (Spinner) findViewById(R.id.spinner); tv = (TextView) findViewById(R.id.tv); final Ar ...

  4. HTTP权威协议笔记-3.Http报文

    3.1 报文流 http使用流入和流出来描述事物处理方向,报文包含:起始行.首部和主体. 3.2 起始行 起始行包含:请求行和回应行. 3.2.1请求行 请求行包含:方法.请求URL(描述了对哪个资源 ...

  5. mysql计算时间差函数

    MySql计算两个日期的时间差函数TIMESTAMPDIFF用法,只要用一句SQL语句就可以办到了. MySql计算两个日期的时间差函数TIMESTAMPDIFF用法: 语法: TIMESTAMPDI ...

  6. sqlserver 查看正在执行sql

    SELECT    [session_id],  [request_id],  [cpu_time],  [start_time] AS '开始时间',  [status] AS '状态',  [co ...

  7. 利用docker compose启动gitlab及runner

    添加docker compose配置文件 新建文件docker-compose.yml,输入如下内容: gitlab: image: 'gitlab/gitlab-ce:latest' contain ...

  8. WampServer Apache 服务无法启动解决办法

    问题:WampServer 安装后mysql服务可以启动,但Apache服务启动不了(前提是已经安装Apache Server) 解决办法: 1.端口冲突,改Apache里httpd.conf中的端口 ...

  9. ORACLE临时表空间

    ORACLE临时表空间总结 2014-10-05 11:35 by 潇湘隐者, 临时表空间概念 临 时表空间用来管理数据库排序操作以及用于存储临时表.中间排序结果等临时对象,当ORACLE里需要用到S ...

  10. Android Runtime

    [Android Runtime] Every Android application runs in its own process, with its own instance of the Da ...