RHEL7学习之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.
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配置的更多相关文章
- RHEL7学习之ISCSI配置
ISCSI服务器:192.168.10.10 ISCSI客户端:192.168.10.20 在ISCSI服务器添加两块硬盘:/dev/sdb /de/sdc 一,在服务端安装 [root@localh ...
- haproxy学习之https配置
haproxy学习之https配置 原文 http://www.cnblogs.com/ilanni/p/4941056.html 如何配置https,以及https在实际生产环境中的应用. ...
- 深度学习主机环境配置: Ubuntu16.04 + GeForce GTX 1070 + CUDA8.0 + cuDNN5.1 + TensorFlow
深度学习主机环境配置: Ubuntu16.04 + GeForce GTX 1070 + CUDA8.0 + cuDNN5.1 + TensorFlow 最近在公司做深度学习相关的学习和实验,原来一直 ...
- 1 python学习——python环境配置
1 python学习--python环境配置 要学习python语言,光看书看教程还是不好,得动手去写.当然,不管学习什么编程语言,最佳的方式还在于实践. 要实践,先得有一个Python解释器来解释执 ...
- AgileEAS.NET SOA 中间件平台5.2版本下载、配置学习(三):配置ActiveXForm运行环境
一.前言 AgileEAS.NET SOA 中间件平台是一款基于基于敏捷并行开发思想和Microsoft .Net构件(组件)开发技术而构建的一个快速开发应用平台.用于帮助中小型软件企业建立一条适合市 ...
- JMeter学习-002-JMeter环境配置
本节主要介绍 JMeter 本地环境配置(JMeter 版本为 apache-jmeter-2.12),详细配置如下: 一.JDK配置 默认用户本地已经安装且配置好 JDK.若未配置,敬请参阅我的博客 ...
- (转)深度学习主机环境配置: Ubuntu16.04+Nvidia GTX 1080+CUDA8.0
深度学习主机环境配置: Ubuntu16.04+Nvidia GTX 1080+CUDA8.0 发表于2016年07月15号由52nlp 接上文<深度学习主机攒机小记>,这台GTX10 ...
- NTP配置实践
前言 NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议.不管是平时使用的私人计算机还是在工作中搭建的服务器集群.时间的统一性和准确性是十分 ...
- 深度学习python的配置(Windows)
Windows下深度学习python的配置 1.安装包的下载 (1)anaconda (2)pycharm 2.安装教程 (1)anaconda a.降版本 b.换源 (2)pycharm a.修改h ...
随机推荐
- R语言获取国内的股票数据
quantmod 包默认是访问 yahoo finance 的数据,其中包括上证和深证的股票数据,还有港股数据. 上证代码是 ss,深证代码是 sz,港股代码是 hk 例如苏宁云商 setSymbol ...
- 学校系统快速js代码
var select_arr=document.getElementById("iframeautoheight").contentWindow.document.getEleme ...
- ThinkPHP升级指导
升级指导 http://www.kancloud.cn/manual/thinkphp5/163239 从V5.0.1升级到V5.0.2 从V5.0.1升级到V5.0.2需要注意如下事项: 下列模型属 ...
- centos6升级python2.7
#下载python #wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2 #安装支持https yum install opens ...
- JQuery笔记汇总
jQuery相关资料 官网: jQuery官网 在线API: jQuery在线API W3School:W3School-jQuery教程(中文版哦) 下载jQuery:jQuery各版本下载 jQu ...
- 【转】jqGrid 各种参数 详解
[原文]http://www.cnblogs.com/younggun/archive/2012/08/27/2657922.htmljqGrid 各种参数 详解 JQGrid JQGrid是一个 ...
- C# iis错误配置信息( 500.21 - Internal Server Error )
新电脑安装完开发环境后,还需要注册framework4.0到IIS.不然会报错: HTTP 错误 500.21 - Internal Server Error 处理程序"Extensionl ...
- Ajax的基本使用
AJAX AJAX即"Asynchronous Javascript And XML"(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术. AJAX = ...
- diamond专题(一)– 简介和快速使用
(转自 http://blog.csdn.net/zh_winer/article/details/50395024) 一.概况 diamond是淘宝内部使用的一个管理持久配置的系统,它的特点是简单 ...
- VC++ 迭代器 iterator, const_iterator, const iterator
迭代器 iterator, const_iterator, const iterator 迭代器iterator的作用类似于指针. (1)iterator只有针对制定<类型>的容器才有效. ...