美文网首页
NTP 服务搭建

NTP 服务搭建

作者: 哎呦666 | 来源:发表于2020-06-24 14:12 被阅读0次

一、NTP简介:

NTP协议全称网络时间协议(Network Time Procotol),它的目的是在国际互联网上传递统一、标准的时间。具体的实现方案是在网络上指定若干时钟源网站,为用户提供授时服务,并且这些网站间应该能够相互比对,提高准确度。

NTP是一个跨越广域网或局域网的复杂的同步时间协议,它通常可获得毫秒级的精度。RFC2030描述了SNTP(Simple Network Time Protocol),目的是为了那些不需要完整NTP实现复杂性的主机,它是NTP的一个子集。通常让局域网上的若干台主机通过因特网与其它的NTP主机同步时钟,接着再向局域网内其他客户端提供时间同步服务。

NTP协议是OSI参考模型的高层协议,符合UDP传输协议格式,拥有专用端口123.

随着时间的推移,计算机的时钟会倾向于漂移。网络时间协议(NTP)是一种确保您的时钟保持准确的方法。它为路由器、交换机、工作站和服务器之间提供了一种时间同步的机制。所以NTP Server经常应用于一些有时间同步要求的IT系统环境中

二、搭建NTP服务器

1、查看服务器是否安装ntp,系统默认安装ntpdate

[root@localhost ~]# rpm -qa |grep ntp

ntpdate-4.2.6p5-28.el7.centos.x86_64

ntp-4.2.6p5-28.el7.centos.x86_64

2、安装ntp,ntpdate已经系统默认安装过了

centos: yum install -y ntp

ubuntu: sudo apt-get install ntp

3、修改ntp配置文件

利用server设定上层NTP服务器,上层NTP服务器的设定方式为:

server [IP OR HOSTNAME] [PREFER]

参数说明:

ip or hostname :上层ntp服务器的ip地址或者域名

prefer : 表示最高优先级

driftfile :记录时间差异

[root@localhost ~]# 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 iburst

然后在下面添加这几行:

server 0.cn.pool.ntp.org iburst

server 1.cn.pool.ntp.org iburst

server 2.cn.pool.ntp.org iburst

server 3.cn.pool.ntp.org iburst

4、启动ntp服务,并开机自启动

centos:

[root@localhost ~]# systemctl start|restart ntpd

[root@localhost ~]# systemctl enable ntpd

ubuntu:

sudo /etc/init.d/ntp restart

5、查询ntp是否同步

[root@localhost ~]# ntpq -p

    remote          refid      st t when poll reach  delay  offset  jitter==============================================================================*119.28.206.193100.122.36.1962u12812837719.711-0.4685.363

ntp -p 返回参数含义

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

refid : 指的是参考的上一层NTP主机的地址

st : 远程服务器的级别。由于NTP是层型结构,有顶端的服务器,多层的Relay Server再到客户端.所以服务器从高到低级别可以设定为1-16.为了减缓负荷和网络堵塞,原则上应该避免直接连接到级别为1的服务器的

when : 用做计时,用来告诉我们还有多久本地机器就需要和远程服务器进行一次时间同步

poll : 本地主机和远程服务器多少时间进行一次同步(单位为秒)

reach : 这是一个八进制值,表示已经向上层NTP服务器要求更新的次数。每成功连接一次,它的值就加1

delay : 网络传输过程中延迟的时间,单位为微秒

offset : 我们本地机和服务器之间的时间差别。单位为毫秒

jitter : Linux系统时间与BIOS硬件时间的差异时间,单位为微秒

6、开启防火墙ntp默认端口udp123

centos:

[root@localhost ~]# firewall-cmd --permanent --zone=public --add-port=123/udp

success

[root@localhost ~]# firewall-cmd --reload

success

ubuntu:

三、NTP客户端配置

1、安装ntp

centos: yum install -y ntp

ubuntu: sudo spt-get install ntp

2、修改ntp配置文件,将上面的NTP服务器作为客户端同步NTP时间服务器

[root@localhost ~]# vim /etc/ntp.conf

#配置允许NTP Server时间服务器主动修改本机的时间

restrict 192.168.0.15 nomodify notrap noquery

#注释掉其他时间服务器

#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 iburst

#配置时间服务器为本地搭建的NTP Server服务器

server 192.168.0.15

3、与NTP server服务器同步一下时间:

同步之前可以先看一下当前的时间

通过ntpdate与ntp server同步时间

[root@localhost ~]# ntpdate -u192.168.0.15

4、查看ntp同步状态

能看到已经成功同步,要记得开启ntpd这个服务器

[root@localhost ~]# ntpq -p

    remote          refid      st t when poll reach  delay  offset 

5、参考文档:

centos搭建ntp服务器

ubuntu搭建ntp服务器

ntp官方网站

关于 ntp 的一些参数详解

相关文章

  • 使用dokcer镜像快速搭建ntp服务器实现时间同步

    使用镜像搭建ntp服务器,并在客户端调用进行定时时间同步。 一、 ntp服务器搭建 查询到有现成的ntp服务器do...

  • 笔记 时间同步服务器搭建

    ntp配置 需要搭建本地的时间同步服务器(非授时)参考:1.CentOS 6 安装 NTP Server 时间服务...

  • 第十三周

    1、搭建时间服务器,日志服务器并简述sudo安全切换 1)安装ntp服务器 yum install ntp 配置文...

  • 搭建ntp服务

    ntp简介 ntp全称Network Time Protocol(NTP)是用来使计算机[时间同步化的一种协议,它...

  • NTP 服务搭建

    一、NTP简介: NTP协议全称网络时间协议(Network Time Procotol),它的目的是在国际互联网...

  • 第十三周作业

    1、搭建时间服务器,日志服务器并简述sudo安全切换。 1)搭建时间服务器: 早期是用ntp服务: #yum in...

  • Linux-16 ntpdate单台服务器同步网络时间

    生产中服务器时间同步还是比较重要的,一般都不会去专门搭建NTP服务器,可以直接使用公网上的NTP服务器去同步服务器...

  • 同步服务器时间

    生产中服务器时间同步还是比较重要的,一般都不会去专门搭建NTP服务器,可以直接使用公网上的NTP服务器去同步服务器...

  • ntp服务器搭建

    1. NTP简介 NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间...

  • NTP服务器搭建

    当本机时间不准确时,我们需要对时间进行校准,那么我们就需要在互联网上找到一个可以提供我们准确时间的服务器然后通过一...

网友评论

      本文标题:NTP 服务搭建

      本文链接:https://www.haomeiwen.com/subject/anyrfktx.html