004.NTP多层级架设

一 环境需求

1.1 需求

User-client:局域网所有节点主机;

IN-NTP Server:隐藏于局域网内部的NTP服务器;

Border-NTP:边界NTP服务器,用于同步外部时钟,同时对内部IN-NTP服务器提供校对;

亚洲授时中心:公网NTP授时中心。

内部局域网所有节点client需要和IN-NTP Server同步,IN-NTP Server对外隐藏,同时通过 Border-NTP进行同步, Border-NTP边界NTP服务器实时同步公网授时中心。

1.2 架构


主机名

IP

备注

border_ntp

内网IP:172.24.8.71

边界NTP服务器

in_ntp01

172.24.8.72

内部NTP服务器01

in_ntp02

172.24.8.73

内部NTP服务器02

client

172.24.8.74

模拟局域网内部客户端节点

注意:

  • Border-NTP部署在边界上,作为和互联网(亚洲授时中心)同步,同时为局域网内部IN-NTP提供同步服务。
  • User-client,包括所有局域网内客户端等,从两台(一主一备)IN-NTP进行同步。

二 Border-NTP配置

2.1 服务包安装

  1 [[email protected]_ntp ~]# rpm -qa | grep ntp
  2 [[email protected]_ntp ~]# yum -y install ntp			#安装ntp服务

2.2 ntp配置

  1 [[email protected]_ntp ~]# vi /etc/ntp.conf
  2 driftfile /var/lib/ntp/drift
  3 #定义与上级时间服务器联系时所花费的时间,记录在driftfile参数后面的文件内。
  4 driftfile   /var/lib/ntp/drift
  5 pidfile     /var/run/ntpd.pid				#进程pid文件
  6 logfile     /var/log/ntp.log				#开启日志记录
  7 #定义与上级时间服务器联系时所花费的时间,记录在driftfile参数后面的文件内。
  8
  9 restrict default nomodify notrap nopeer noquery	        #默认拒绝所有NTP连接
 10 restrict 127.0.0.1
 11 restrict ::1 						#开启本地授权
 12
 13 restrict 172.24.8.72 mask 255.255.255.255 nomodify notrap	#添加IN-NTP Server允许校时
 14 restrict 172.24.8.73 mask 255.255.255.255 nomodify notrap	#添加IN-NTP Server允许校时
 15
 16 #server 0.cn.pool.ntp.org
 17 #server 1.asia.pool.ntp.org
 18 #restrict 0.cn.pool.ntp.org nomodify notrap noquery
 19 #restrict 1.asia.pool.ntp.org nomodify notrap noquery
 20 #添加Border-NTP的上一级时间中心,即亚洲授时中心服务器,此处建议注释,转而采用国内阿里云时钟,相对网络更稳定,如下。
 21 server ntp1.aliyun.com iburst minpoll 4 maxpoll 10
 22 restrict ntp1.aliyun.com nomodify notrap nopeer noquery
 23 server ntp2.aliyun.com iburst minpoll 4 maxpoll 10
 24 restrict ntp2.aliyun.com nomodify notrap nopeer noquery
 25 #允许阿里授时中心修改本地时间。
 26 server 127.127.1.0
 27 fudge 127.127.1.0 stratum 4
 28 #当授时不可用,采用本地时间,stratum级别为4。

2.3 其他配置

  1 [[email protected]_ntp ~]# chown ntp:ntp /var/log/ntp.log
  2 [[email protected]_ntp ~]# chcon -t ntpd_log_t /var/log/ntp.log
  3 [[email protected]_ntp ~]# firewall-cmd --permanent --add-service=ntp
  4 [[email protected]_ntp ~]# firewall-cmd --reload
  5 [[email protected]_ntp ~]# setenforce 0

提示:若开启日志功能,需要ntp进程具备写入日志权限。同时防火墙开放ntp服务,SELinux写入上下文授权。

建议:若没有特殊必要,建议关闭SELinux和防火墙。

2.4 开启服务

  1 [[email protected]_ntp ~]# systemctl start ntpd.service
  2 [[email protected]_ntp ~]# systemctl enable ntpd.service

提示:开启ntp server后,需要等待一定时间(通常为5分钟以内),才能实现和亚洲授时中心的同步。

2.5 验证

  1 [[email protected]_ntp ~]# ntpq -np

提示:ntpq相关含义见附录一。

三 IN-NTP Server配置

3.1 服务包安装

  1 [[email protected]_ntp01 ~]# rpm -qa | grep ntp			#查看是否安装ntp
  2 [[email protected]_ntp01 ~]# yum -y install ntp			#安装ntp服务

3.2 ntp配置

  1 [[email protected]_ntp01 ~]# vi /etc/ntp.conf
  2 driftfile   /var/lib/ntp/drift
  3 pidfile     /var/run/ntpd.pid				#进程pid文件
  4 logfile     /var/log/ntp.log				#开启日志记录
  5 #定义与上级时间服务器联系时所花费的时间,记录在driftfile参数后面的文件内。
  6 tinker stepout 0
  7 restrict    default ignore				        #默认拒绝所有连接
  8 restrict -6 default ignore				        #默认拒绝所有ipv6连接
  9 restrict    127.0.0.1
 10 restrict    -6 ::1					        #开启本地授权
 11
 12 restrict 172.24.8.0 mask 255.255.255.0 nomodify notrap	#允许局域网内网段校时
 13
 14 restirct 172.24.8.71 nomodify notrap nopeer noquery
 15 #允许根据上一级时间修改本地时间
 16 server 172.24.8.71  iburst minpoll 3 maxpoll 3 prefer
 17 #添加上一层Border-NTP服务地址
 18
 19 #peer 172.24.8.72 iburst minpoll 4 maxpoll 6
 20 #peer 172.24.8.73 iburst minpoll 4 maxpoll 6
 21 #服务器接收其他服务器的地址,同时也会为其他设备提供NTP服务器,即互相同步,用于在孤岛环境中,若同时具备上层时钟,可注释掉。
 22
 23 server 127.127.1.0
 24 fudge 127.127.1.0 stratum 8			#上一级不可用,使用本地时间,stratum为8

3.3 其他配置

参考2.3.

3.4 开启服务

  1 [[email protected]_ntp01 ~]# systemctl start ntpd
  2 [[email protected]_ntp01 ~]# systemctl enable ntpd

3.5 验证

  1 [[email protected]_ntp01 ~]# ntpq -np

注意:两台IN-NTP Server都需要配置。

四 user-client配置

4.1 服务包安装

  1 [[email protected] ~]# rpm -qa | grep ntp			#查看是否安装ntp
  2 [[email protected] ~]# yum -y install ntp			#安装ntp服务

4.2 ntp配置

  1 [[email protected] ~]# vi /etc/ntp.conf
  2 driftfile   /var/lib/ntp/drift
  3 pidfile     /var/run/ntpd.pid				#进程pid文件
  4 logfile     /var/log/ntp.log				#开启日志记录
  5 #定义与上级时间服务器联系时所花费的时间,记录在driftfile参数后面的文件内。
  6
  7 tinker panic 600
  8 #当client和server时差在600秒以内,使用渐变调整client时间,超过600秒,ntpd进程自动终止,需要手动进行调整。
  9 restrict    default ignore				        #默认拒绝所有连接
 10 restrict -6 default ignore				        #默认拒绝所有ipv6连接
 11 restrict    127.0.0.1					#开启本地授权
 12
 13 restrict 172.24.8.72 nomodify notrap noquery		#允许根据上一级时间修改本地时间
 14 restrict 172.24.8.73 nomodify notrap noquery		#允许根据上一级时间修改本地时间
 15
 16 server 172.24.8.72 iburst minpoll 4 maxpoll 6 prefer
 17 server 172.24.8.73 iburst minpoll 4 maxpoll 6

4.3 其他配置

参考2.3.

4.4 开启服务

  1 [[email protected] ~]# systemctl start ntpd
  2 [[email protected] ~]# systemctl enable ntpd

4.5 验证

  1 [[email protected] ~]# ntpq -np

  1 [[email protected] ~]# ntpstat

附录一

ntpq参数解释:

remote:本地服务器所连接的远程NTP服务器。

refid:NTP服务器使用的上一级ntp服务器,即给远程ntp服务器提供时间同步是服务器。。

st :remote远程服务器的级别,由于NTP是层型结构,有顶端的服务器,多层的Relay Server再到客户端。所以服务器从高到低级别可以设定为1-16,为了减

缓负荷和网络堵塞,原则上应该避免直接连接到级别为1的服务器的。

when: 上一次成功请求之后到现在的秒数。

poll : 本地机和远程服务器多少时间进行一次同步(单位为秒),在一开始运行NTP的时候这个poll值会比较小,那样和服务器同步的频率也就增加了,可以尽快调

整到正确的时间范围,之后poll值会逐渐增大,同步的频率也就会相应减小。

reach:这是一个八进制值,用来测试能否和服务器连接,每成功连接一次它的值就会增加

delay:从本地机发送同步要求到ntp服务器的round trip time

offset:主机通过NTP时钟同步与所同步时间源的时间偏移量,单位为毫秒(ms)。offset越接近于0,主机和ntp服务器的时间越接近。

jitter:这是一个用来做统计的值,它统计了在特定个连续的连接数里offset的分布情况,简单地说这个数值的绝对值越小,主机的时间就越精确。

『 * 』:代表目前正在作用当中的NTP,即主NTP Server;

『 + 』:代表辅助的NTP Server和带有*号的服务器一起为我们提供同步服务, 当主NTP Server服务器不可用时备服务器接管,即作为下一个提供时间更新的候

选者。

『 - 』:远程服务器被认为是不合格的NTP Server。

『 x 』:远程服务器不可用。

附录二

ntp服务,默认只会同步系统时间。若需要ntp同时同步硬件时间,可以在/etc/sysconfig/ntpd文件中,添加 SYNC_HWCLOCK=yes ,则可以让硬件时间与系统时间一起同步。

SYNC_HWCLOCK=yes

注意:允许BIOS与系统时间同步,也可以通过hwclock -w 命令。

原文地址:https://www.cnblogs.com/itzgr/p/10342262.html

时间: 2024-08-29 16:44:13

004.NTP多层级架设的相关文章

分布式系统卫星时钟服务器(NTP服务器)架设与设计

分布式系统卫星时钟服务器(NTP服务器)架设与设计 分布式系统卫星时钟服务器(NTP服务器)架设与设计 本文由安徽京准科技提供支持和原资料——更多阐述可参考微♥ ahjzsz  分布式系统由Tanenbaum定义,“分布式系统是一组独立的计算机,在”分布式系统?—?原理和范例“中作为用户的单一,连贯的系统出现”. 区块链通过构建全球分布式系统,尝试实现分散的新数据存储和组织结构. 首先,定位到分布式系统的原因主要是可扩展性,位置和可用性.区块链也不例外.地理可扩展性,形成全球价值存储网络/信息保

CentOS6.5系统搭建NTP服务器

在进入到我们的主题之前首先我们可以简单了解一下这几个名词 Atomic Clock: 现在计算时间最准确的是使用 原子震荡周期 所计算的物理时钟(Atomic Clock),因此也被定义为标准时间(International Atomic Time) UTC(coordinated Universal Time): 协和标准时间 就是利用 Atomic Clock 为基准定义出来的正确时间 (世界统一时间,世界标准时间,国际协调时间) 硬件时钟: 硬件时钟是指嵌在主板上的特殊的电路, 它的存在就

Linux下NTP服务器搭建

一.搭建准备 1.确定自己的时区 #date命令可以查看当前系统时间,中国的时区为CST.使用tzselect命令进行配置时区 配置文件的修改:/etc/sysconfig/clock 2.检查NTP服务程序 #rpm -qa |grep ntp fontpackages-filesystem-1.41-1.1.el6.noarch ntpdate-4.2.4p8-3.el6.x86_64 如果没有,则需要安装ntp程序 #yum -y install ntp ntpdate 需要配置好yum源

NTP时间服务器搭建及配置

网络时间协议NTP(Network Time Protocol)是用于互联网中时间同步的标准互联网协议.NTP的用途是把计算机的时间同步到某些时间标准.目前采用的时间标准是世界协调时UTC(Universal Time Coordinated).NTP的主要开发者是美国特拉华大学的David L. Mills教授.其精度在局域网内可达0.1ms,在互联网上绝大多数的地方其精度可以达到1-50ms. NTP服务的安装 [[email protected] ~]# yum install ntp [

搭建IPA服务器与SSH服务器

一.NTP服务器的架设 1.1 先关闭工作站的DHCP服务 systemctl stop dhcpd systemctl disable dhcpd 1.2 在所有机器上安装NTP程序 yum install ntp -y 1.3 修改服务器的配置文件 vim /etc/ntp.conf 注释.添加 server asia.pool.ntp.org iburst 1.4 修改客户端的配置文件. vim /etc/ntp.conf 注释.添加 server 192.168.203.100 ibur

JavaScript提高:004:JS获取Gridview单元格时层级问题

使用javascript获取页面中元素的属性,或者对元素进行操作.这种使用是非常多的.不过对于获取那些在页面中单一的元素,诸如,页面上的某个文本框,下拉列表,按钮等可以直接用ID获取到的这种元素,用法自然简单.这里就不多说了,太简单了.一般比较复杂的是,获取元素中的元素,比如动态生成的那些元素.这里就拿表格中的元素为例吧.知道如何获取表格中的单元格内的元素了,其他的复杂元素也就不在话下了.下面举个简单的例子,获取GridView的单元格元素.平常使用比较多的也就是这种的.行中有个操作按钮,然后对

Linux与云计算——第二阶段 第一章:NTP服务器架设

Linux与云计算--第二阶段Linux服务器架设 第一章:NTP服务器架设 1.NTP Server(NTPd)安装NTPd并且配置NTP服务器来完成时间调节. [1] 安装NTPd. [[email protected] ~]# yum -y install ntp [[email protected] ~]# vim /etc/ntp.conf 参考17行,在第18行添加哪个网段内的主机允许访问你的NTP服务器: restrict 192.168.96.0 mask 255.255.255

鸟哥服务器架设——NTP服务器搭建

NTP服务器搭建 一.NTP通信协议 实际上,Linux操作系统的计时方式主要从1970年1月1日开始计算总秒数,因此,如果你还记得date这个命令的话,会发现他有个+%s的参数,可以去的总秒数,这个就是软件时钟.但是,如同前面说的,计算机硬件主要是以BIOS内部的时间为主要的时间依据(硬件时钟),而偏偏这个时间可能因为BIOS内部芯片本身的问题,而导致BIOS时间与标准时间(UTC)存在一点点的差异.所以,为了避免主机时间因为长期运行而导致时间偏差,进行时间同步(synchronize)的工作

在隔离的局域网内部架设基于CentOS7的NTP服务器

局域网内部由于不能跟外部的时间服务器相连,在NTP服务器设置的时候若将NTP服务器本身作为根时间服务器,则需要进行如下设置: 以CentOS7系统为例 # >vim /etc/ntp.conf 将如下行注释掉 # server 0.centos.pool.ntp.org iburst # server 1.centos.pool.ntp.org iburst # server 2.centos.pool.ntp.org iburst # server 3.centos.pool.ntp.org