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 ...
随机推荐
- begin-end语句块在mysql中的使用问题
在最近在通过navicate连接mysql数据库时,进行查询操作: delimiter $$BEGIN SET @a=1; if (@a > 0) THEN SELECT COUNT(*) fr ...
- Centos安装lnmp环境
1:查看环境: [root@10-4-14-168 html]# cat /etc/redhat-release CentOS release 6.5 (Final) 2:关掉防火墙 [root@10 ...
- androidstudio 配置git和github
git是版本控制工具 github是一个网站,git可以把项目上传至这个网站 1:先下载git,并且安装,一般默认即可,安装成功可以点击电脑右键出现 2:生成id_rsa.pub, 配置账号和邮箱 点 ...
- Indent Guides 代码括号对齐工具
搜不到怎么办: 下载版本要正确.
- 《CoffeeScript应用开发》学习: CoffeeScript高级用法
正确的上下文 使用胖箭头=>表示将回调函数绑定到this对象. class t func: (callback)-> if callback? setTimeout callback(), ...
- Windows 2008 server IIS 7 中开启CGI, ISAPI
默认情况下,IIS是没有开启的,需要通过下面的步骤开启
- iOS图片模糊效果与阴影效果
/** 添加图片模糊效果 @parms 要添加模糊效果的view @return */ + (UIVisualEffectView *)addVisualEffectViewWithView:(UI ...
- SDRAM的主要参数
(1) 容量.SDRAM的容量经常用XX存储单元×X体×每个存储单元的位数来表示.例如某SDRAM芯片的容量为4M×4×8bit,表明该存储器芯片的容量为16 M字节.或128 M bit. (2) ...
- CSS3学习内容与心得
今天2005年7月9号,博客这个东西还真不懂,以前吧我不认识它,它也不认识我.没辙,汤老要我们写,就写吧. 写什么好呢?那就写今天学习的css3的一些要点吧. css这门课程几乎都学完了.而我觉得我还 ...
- etc这个目录
自己对他的记忆最深了,因为每次你添加新的软件向电脑里时,软件都会有一个自己的配置文件,那么你修改这个配置文件的某个选项,就可以改变软件的某个功能. 或者是某个外设都有自己的配置文件. 其实这个配置文件 ...