NTP 服务可以用来当做客户端所在服务器的时间,也可以作为服务端当做时间校准的服务。

安装 NTP

$ yum -y install ntp
# 开机自启
$ systemctl enable ntpd
# 先同步一下时间,此处使用的是阿里云的 NTP 校准服务
$ ntpdate -u time1.aliyun.com

配置 NTP

  配置文件目录:/etc/ntp.conf
  

# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).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 ::1# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# 修改内容 --- 上级时间服务器,阿里云的时间服务
server time1.aliyun.com
server time2.aliyun.com
server time3.aliyun.com
server time4.aliyun.com
server time5.aliyun.com
server time6.aliyun.com
server time7.aliyun.com#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# 修改内容 --- 允许上层时间服务器主动修改本机时间
#restrict time1.aliyun.com nomodify notrap noquery
#restrict time2.aliyun.com nomodify notrap noquery
#restrict time3.aliyun.com nomodify notrap noquery# 修改内容 --- 只有在上级时钟源失效时,NTP 才会使用127.127.1.0的本地时钟,将local时间作为ntp服务器时间提供给ntp客户端。NTP把本地主机的时钟也看作外部时钟源来处理,分配的地址是127.127.1.0
server 127.127.1.0
# 修改内容 --- 设置本地时钟源的层次为 5,这样如果NTP服务从本地时钟源获取时间的话,NTP对外宣布的时间层次为 6
fudge  127.127.1.0 stratum 5# Enable public key cryptography.
#cryptoincludefile /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 4 8 42# Specify the key identifier to use with the ntpdc utility.
#requestkey 8# Specify the key identifier to use with the ntpq utility.
#controlkey 8# 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-2013-5211 for more details.
# Note: Monitoring will not be disabled with the limited restriction flag.
disable monitor

  配置完毕之后重启 NTP 服务

$ systemctl restart ntpd# 查看上级连通状态
$ ntpq -p

属性 作用
remote 本机和上层 NTP 的 ip 或主机名;+ 表示可用,- 表示不可用,* 表示推荐。
refid remote 的上一层 NTP 主机地址;
st Stratum(阶层);表示经过 n = 2 次 NTP 同步到当前服务器。
t 类型;u 表示单播(unicast)。其它值包括本地(local)、多播(multicast)、广播(broadcast)。
when 自从上次和服务器交互后经过的时间(以秒数计)。
poll 和服务器的轮询间隔,以秒数计。
reach 表示和服务器交互是否有任何错误的八进制数;每成功连接一次它的值就会增加,值 337 表示 100% 成功(即十进制的255)。
delay 从本地机发送同步要求到 NTP 服务器的往返时间。
offset 当前服务器通过 NTP 时钟同步与所同步时间源的时间偏移量,单位为毫秒,offset 越接近于 0,主机和 NTP 服务器的时间越接近。
jitter 统计了在特定个连续的连接数里 offset 的分布情况。简单地说这个数值的绝对值越小,主机的时间就越精确。
# 查看时间同步状态
$ ntpstat
synchronised to NTP server (203.107.6.88) at stratum 3time correct to within 50 mspolling server every 1024 s

  这里 NTP 服务配置已经完毕,它既是客户端也是服务端,如果要当服务端可以开放 123 端口,其他服务器上安装 NTP 服务并把上级时间服务器的配置项更改到本服务器的 IP/域名/主机名 即可。

NTP 服务的配置和使用相关推荐

  1. linux如何禁用ntp服务,Linux系统下NTP服务的配置注意要点

    在Linux系统下NTP的标准配置中,许多关于同步的方式不同,注意以下要点: 如果不想让其它任何服务器访问本机的NTP服务:此配置也将造成本地的NTP无法访问外部的NTP服务: If you want ...

  2. centos7 校正linux系统时间_基于centos7系统部署NTP服务及配置时间定时同步

    概述 linux服务器在提供服务时,要和其他机器进行请求的交互,实际生产环境中,可能因为时间不同步,导致了服务异常. 下面介绍下怎么部署NTP服务来解决这个问题. ps:强烈吐槽下头条这个新排版功能, ...

  3. linux ntp时间立即同步命令_记一次生产环境部署NTP服务及配置时间同步

    概述 linux服务器在提供服务时,要和其他机器进行请求的交互,实际生产环境中,可能因为时间不同步,导致了服务异常. 下面介绍下怎么部署NTP服务来解决这个问题. ps:强烈吐槽下头条这个新排版功能, ...

  4. ntp 服务端配置(/etc/ntp.conf配置详解) -小白实操记录

    1 ntp 安装查看 1.1 安装命令 apt-get install ntp 1.2 查看服务是否启动 service --status-all 或者 ps -aux | grep ntp 1.3 ...

  5. 【Windows Server 2019】NTP服务的配置和管理——使用GUI与CLI设置

    目录 1. 理论 2. GUI 配置 2.1 调整服务器时间与时区 (1)打开[Date and Time] (2)更改时区 2.2 配置NTP (1)打开注册表 (2)修改W32Time配置 (3) ...

  6. linux设置ntp后不生效,Linux时间设置与NTP服务配置

    第一部分:时间设置 一.时间和时区 格林威治时间(GMT),是0时区时间.计算机中是UTC.它是Coordinated Universal Time的简写.虽然UTC和GMT的值相等(误差相当之小), ...

  7. Ubuntu/CentOS 配置部署 时间同步、NTP服务(chronyd,ntpd,ntpdate)

    一.概述 NTP服务器的阶层概念 网络时间按照NTP服务器的等级进行传播,根据离基准时间的远近将不同服务器归纳到不同的层中(Stratum),单个Stratum层的总数限制在15 0层(Stratum ...

  8. linux debian ntp,Debian下面的ntp服务(ntpdate)的安装

    NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议.它的用途是把计算机的时钟同步到世界协调时UTC,其精度在局域网内 /********** ...

  9. NTP服务被利用做流量攻击以及检测预防手段

    被攻击服务器相关配置: ip: eth0: 172.28.9.2 eth1: 192.168.0.2 eth3: 外网IP 某一天发现这台WEB服务器流量一直很高. 开始一直以为是WEB服务的流量很高 ...

最新文章

  1. 面试官问为什么新生代不用标记清除算法
  2. 王瑜琪:数据科学助力我捕捉研究生教育的宏观效应 | 提升之路系列
  3. Flutter开发之ListView添加HeaderView和FooterView-2(39)
  4. 一个详细的JTable使用例子
  5. 开学测试代码——需求征集系统
  6. 盘点PHP编程常见失误
  7. Python中class的简单介绍
  8. c 连接mysql错误信息_使用C语言访问MySQL数据 —— 连接和错误处理
  9. 今生一定娶美女 不遇美女终生不娶
  10. 通过ODBC实现ACCESS与SQL数据互导(临安人才网 )
  11. [BZOJ 3207] 花神的嘲讽计划Ⅰ【Hash + 可持久化线段树】
  12. 用webpack打包加密静态配置文件
  13. lg android平台驱动程序,lg g3刷KDZ教程-KDZ线刷工具及USB驱动下载
  14. 关于中标麒麟系统出现“网络管理器未响应”这件事的解决办法
  15. 基于JavaWEB+MySQL的宾馆管理系统设计与实现
  16. edm邮件直投_EDM邮件直投专家 :直接投递Email到收件人邮箱 Version 4.0.9 Build 503
  17. 怎么把m4a文件变成mp3格式
  18. python面试题 网络编程和并发(34道题)
  19. clover写入efi_把clover复制到EFI之后电脑不认clover的解决方法(UEFI Shell强制写入)
  20. 电商用户行为实时分析系统(Flink1.10.1)

热门文章

  1. HDU——2546 饭卡
  2. 【懒懒的Python学习笔记九】
  3. 几款好用证件照制作工具推荐
  4. PrimeNG p-tree 手动添加勾选
  5. 【中创算力】第六届优秀员工表彰大会暨四月中创生日会
  6. 拨开零售电商数字化转型迷雾,电商RPA应用揭秘
  7. web术语chm_笨客户端的20个Web设计行业术语
  8. python编程应用中级_如何利用Python辅助开发HSK中级课程-数据统计篇
  9. 重拾Java基础知识:网络编程
  10. 08-02-loggin-模块