centos7 ntp服务器配置
一、ntp服务是什么
1. 定义
NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议。
2. 发展
首次记载在Internet Engineering Note之中,其精确度为数百毫秒。
稍后出现了首个时间协议的规范RFC-778,它被命名为DCNET互联网时间服务,这种服务还是借助于Internet control Message Protocol (ICMP)中的时间戳和时间戳应答消息作为NTP。
名称的首次出现是在RFC-958之中,该版本也被称为NTP v0,其目的是为ARPA网提供时间同步。已脱离ICMP,作为独立协议运行,
美国特拉华大学的David L.Mills主持了网络时间同步项目,成功的开发出了NTP协议的第1, 2, 3版。
v1:出现于1988年6月,在RFC-1059中描述了首个完整的NTP的规范和相关算法。这个版本已经采用了client/server模式以及对称操作,但是它不支持授权鉴别和NTP的控制消息。
v2:1989年9月推出了取代RFC-958和RFC-1059的NTP v2版本即RFC-1119。
v3:在1992 年3月,NTP v3版本RFC-1305问世,该版本总结和综合了NTP先前版本和DTSS,正式引入了校正原则,并改进了时钟选择和时钟滤波的算法,而且还引入了时间消息发送的广播模式,这个版本取代了NTP的先前版本。NTP v 3 发布后,一直在不断地进行改进,NTP实现的一个重要功能是对计算机操作系统的时钟调整。
v4:截止到2010年6月,最新的NTP版本是第4版(NTPv4),其标准化文档为 RFC 5905,它继承自RFC 1305所描述的NTP v3。网络时间同步技术也将向更高精度、更强的兼容性和多平台的适应性方向发展。网络时间协议NTP是用于互联网中时间同步的标准之一,它的用途是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可达0.lms,在Internet上绝大多数的地方其精度可以达到1- 50ms.
值得提一下的是,简单的NTP(SNTP)version4已经在RFC2030描述了。
3. 主要结构
(1) 时间来源
现在的标准时间是由原子钟报时的国际标准时间UTC(Universal Time Coordinated,世界协调时),所以NTP获得UTC的时间来源可以是原子钟、天文台、卫星,也可以从Internet上获取。
(2) 传播
在NTP中,定义了时间按照服务器的等级传播,按照离外部UTC源远近将所有的服务器归入不同的Stratum(层)中,例如把通过GPS取得发送标准时间的服务器叫Stratum-1的NTP服务器,而Stratum-2则从Stratum-1获取时间,Stratum-3从Stratum-2获取时间,以此类推,但Stratum层的总数限制在15以内。所有这些服务器在逻辑上形成阶梯式的架构相互连接,而Stratum-1的时间服务器是整个系统的基础,这种阶梯式的架构示意图如下图所示:
计算机主机一般同多个时钟服务器连接,利用统计学的算法过滤来自不同服务器的时间,以选择最佳的路径和来源以便校正主机时间。即使在主机长时间无法与某一时钟服务器联系的情况下,NTP服务依然可以有效运转。
二、架构及安装
1. 架构
如上图所示,对于一些服务依赖于时间的集群(如hadoop集群),需要有一部主机作为ntp服务器,其他客户端主机从这部主机进行时间同步,另外ntp服务主机从更高一层的服务器获得时间信息。
2. 安装
centos系统,直接用yum进行安装就可以了:
yum -y install ntp
三、主要配置
1. 配置文件
centos7的ntp配置文件存放路径为:/etc/ntp.conf。
2. restrict 控制相关权限。
语法为: restrict IP地址 mask 子网掩码 参数
其中IP地址也可以是default ,default 就是指所有的IP。
参数有以下几个:
ignore :关闭所有的 NTP 联机服务
nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。
notrust :客户端除非通过认证,否则该客户端来源将被视为不信任子网
noquery :不提供客户端的时间查询:用户端不能使用ntpq,ntpc等命令来查询ntp服务器
notrap :不提供trap远端登陆:拒绝为匹配的主机提供模式 6 控制消息陷阱服务。陷阱服务是 ntpdq 控制消息协议的子系统,用于远程事件日志记录程序。
nopeer :用于阻止主机尝试与服务器对等,并允许欺诈性服务器控制时钟
kod : 访问违规时发送 KoD 包。
restrict -6 表示IPV6地址的权限设置。
3. server 设定NTP主机来源
语法为:server 主机ip或域名 参数
参数有以下几个:
burst:When the server is reachable, send a burst of eight packets instead of the usual one. The packet spacing is nor‐mally 2 s; however, the spacing between the first and second packets can be changed with the calldelay command to allow additional time for a modem or ISDN call to complete. This option is valid only with the server command and type s addressesa. It is a recommended option when the maxpoll option is greater than 10 (1024 s).
iburst:When the server is unreachable, send a burst of eight packets instead of the usual one. The packet spacing is normally 2 s; however, the spacing between the first and second packets can be changed with the calldelay command to allow additional time for a modem or ISDN call to complete. This option is valid only with the server command and type s addresses. It is a recommended option with this command.
prefer:Mark the server as preferred. All other things being equal, this host will be chosen for synchronization among a set of correctly operating hosts. See the Mitigation Rules and the prefer Keyword page for further information. This option is valid only with the server and peer commands.
true:Mark the association to assume truechimer status; that is, always survive the selection and clustering algorithms. This option can be used with any association, but is most useful for reference clocks with large jitter on the serial port and precision pulse-per-second (PPS) signals. Caution: this option defeats the algorithms designed to cast out falsetickers and can allow these sources to set the system clock. This option is valid only with the server and peer commands.
因为翻译捉急就不翻译了。
例如:以下表示优先连接192.168.7.49这部主机进行时间同步。
server 192.168.7.49 prefer
4. fudge 主机ip stratum 层数
这个配置主要用来设定本机作为为其他机器的时间源的时候,其层数为多少,层数必须在15层之内,一般取10。
四、服务端与客户端配置
1. 服务端配置
driftfile /var/lib/ntp/drift restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict :: server .cn.pool.ntp.org
server .asia.pool.ntp.org
server .asia.pool.ntp.org
server 127.0.0.1 fudge 127.0.0.1 stratum includefile /etc/ntp/crypto/pw keys /etc/ntp/keys disable monitor
实际上修改的地方不多,主要是修改了几个时间源:
server .cn.pool.ntp.org
server .asia.pool.ntp.org
server .asia.pool.ntp.org
server 127.0.0.1
前面一个是中国的时间源,后面两个是亚洲洲际的时间源,最后一个表示允许在前面同步失败的情况从本机同步。
然后就是设定本机的时间服务层次为10:
fudge 127.0.0.1 stratum
2. 客户端配置
driftfile /var/lib/ntp/drift restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict :: server host1 includefile /etc/ntp/crypto/pw keys /etc/ntp/keys disable monitor
客户端只改了一个地方,就是将时间源服务器定为host1,这是时间服务主机的域名,也可以直接指定ip地址。
3. 检查状态
以服务端为例子,设置完之后启动服务:
systemctl start ntpd.service
检查是否成功,用ntpstat命令查看同步状态,出现以下状态代表启动成功:
synchronised to NTP server (85.199.214.101) at stratum
time correct to within ms
polling server every s
如果出现异常请等待几分钟,一般等待5-10分钟才能同步。
如果客户端无法连接服务端,请禁用防火墙和selinux后再试试。
五、参考
1. 百度百科:NTP
(完)
centos7 ntp服务器配置的更多相关文章
- Centos7 Ntp 时间服务器
Centos7 Ntp 时间服务器 安装环境 [root@m02 ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) 安装 ...
- CentOS7 NTP 安装配置
NTP 网络时间协议用来同步网络上不同主机的系统时间.你管理的所有主机都可以和一个指定的被称为 NTP 服务器的时间服务器同步它们的时间.而另一方面,一个 NTP 服务器会将它的时间和任意公共 NTP ...
- NTP 服务器配置
1.yum安装ntp 1 yum install ntp* 2.更新时间 1 ntpdate 202.120.2.101 3.加入任务计划 1 2 crontab -e */10 * * * * nt ...
- Linux下NTP服务器配置
简介 原理 配置ntp服务器 进行同步 一.简介 在计算时间的时候,最准确的计算应该是使用『原子震荡周期』所计算的物理时钟了( Atomic Clock, 也被称为原子钟 ),这也被定义为标准时间(I ...
- CentOS之NTP服务器配置
本文使用CentOS 6.5作为搭建环境 一.服务器端配置 1.安装所需软件包 yum -y install ntp ntpdate---------------------------------- ...
- NTP服务器配置
#/etc/ntp.conf# driftfile /var/lib/ntp/ntp.drift logfile /var/log/ntpd.log statistics loopstats peer ...
- centos7 ntp server & samba
最近公司内部一个需求:必须 Linux建个 ntp server ,并且 Windows可以net time \\ip 访问. 想要解决问题,还得解决前置问题. 服务器不能上网,无法直接访问外部 yu ...
- 企业内部在centos7.2系统中必杀技NTP时间服务器及内网服务器时间同步(windows和linux客户端同步)
网络时间协议NTP(Network Time Protocol)是用于互联网中时间同步的标准互联网协议.NTP的用途是把计算机的时间同步到某些时间标准.目前采用的时间标准是世界协调时UTC(Unive ...
- Centos7部署ntp服务器同步时间以及直接将本地时间同步为北京时间
一.查看配置 查看时区列表: timedatectl list-timezones|grep Asia 查看当前时间: date 查看当前设置: [root@localhost ~]# timedat ...
随机推荐
- C++ readdir、readdir_r函数
readdir, readdir_r - 读一个目录 readdir函数: struct dirent *readdir(DIR *dirp); The data returned by read ...
- HDU 2807
http://acm.hdu.edu.cn/showproblem.php?pid=2807 把矩阵相乘放在第二重循环,第三重循环只进行比较可以水过,优化的方法不懂 主要用这题练习floyd的写法 # ...
- php 递归读取目录
看到很多面试题有这个,今天有机会写了一下. 要注意的是: 在opendir这个函数用完后,要注意closedir,因为安全问题,打开的目录依然存在于内存中,在并发情况下最好关闭,不然容易被破坏. &l ...
- 如何搭建Spring MVC 框架---Hello World
传送门 现在的Web框架基本都采用了MVC(model-view-Controller)设计模式,其中,Servlet和Filter都可以充当控制器.Spring MVC采用一个Servlet作为控制 ...
- BZOJ4372: 烁烁的游戏【动态点分治】
Description 背景:烁烁很喜欢爬树,这吓坏了树上的皮皮鼠. 题意: 给定一颗n个节点的树,边权均为1,初始树上没有皮皮鼠. 烁烁他每次会跳到一个节点u,把周围与他距离不超过d的节点各吸引出w ...
- Redis学习笔记-数据操作篇(Centos7)
一.基本操作 1.插入数据 127.0.0.1:6379> set name cos1eqlg0 OK 这样就在redis中设置了一个key-value键值对 2.查询数据 127.0.0.1: ...
- 【liunx】nslookup命令
“nslookup”域名解析是什么? 假设我们要开个网站,首先我们要去提供域名申请的机构申请域名,然后绑定一个IP地址, 域名比较容易记忆,不像IP地址都是数字,申请完域名,绑定域名,DNS就写入域名 ...
- VUE的使用方法
vueInit: function() { var _this = this; this.vue = new Vue({ el: '#pa', data: { //存放初始化数据 sourceData ...
- mysql学习--基本使用
一旦安装完毕,MySQL 服务器应该自己主动启动. sudo start mysql #手动的话这样启动 sudo stop mysql #手动停止 当你改动了配置文件后,你须要重新启动 mysqld ...
- 全面剖析Smarty缓存机制一[三种缓存方式]
今天主要全面总结下Smarty模板引擎中强大的缓存机制,缓存机制有效减少了系统对服务器的压力,而这也是很多开发者喜欢Smarty的原因之一,由于篇幅较大,便于博友阅读,这篇文章将剖析Smarty缓存的 ...