首页 > 其他分享 >Debian12配置NTP时间同步

Debian12配置NTP时间同步

时间:2023-07-21 13:34:18浏览次数:31  
标签:同步 ntp ntpsec NTP 服务器 Debian12 debian pool

环境

查看系统版本:lsb_release -a

配置NTP时间同步

下面的配置需要用到管理员权限,可以使用su切换到管理员权限。

查看/修正 时区

查看系统时区:timedatectl

如果时区不是Asia/Shanghai需要修改时区为东八区

root@debian:/home/test# timedatectl set-timezone "Asia/Shanghai"

查看本地时间

如果本地时间与NTP服务器时间误差太大(1000s以上),需要先手动校正本地系统时间,手动校正可以使用ntpdate命令强制修正本地时间

ntpdate NTPServerIP后面跟NTP服务器的IP地址

root@debian:/home/test# ntpdate -d ntp.ntsc.ac.cn
ntpdig: querying 114.118.7.163 (ntp.ntsc.ac.cn)
ntpdig: querying 114.118.7.161 (ntp.ntsc.ac.cn)
org t1: e86314a0.b6c0a000 rec t2: e8646973.584fce78
xmt t3: e8646973.58e812a7 dst t4: e86314a1.c05f7000
org t1: 1689818656.713877 rec t2: 1689905907.344968
xmt t3: 1689905907.347291 dst t4: 1689818657.751456
rec-org t21: 87250.631091  xmt-dst t34: 87249.595835
2023-07-21 10:18:27.347291 (+0800) +87250.113463 +/- 0.517644 ntp.ntsc.ac.cn 114.118.7.161 s1 no-leap
CLOCK: time stepped by 87250.113463
CLOCK: time changed from 2023-07-20 to 2023-07-21
root@debian:/home/test# date
2023年 07月 21日 星期五 10:18:44 CST

如果没有ntpdate命令,可以使用date -s "YYYY-MM-DD HH:MM:SS"手动修改本地时间

root@debian:/home/test# date -s "2023-7-20 10:00:00"
2023年 07月 20日 星期四 10:00:00 CST

配置NTP自动校时

编辑/etc/ntpsec/ntp.conf配置NTP服务器地址,将默认的pool配置注释掉(前面加#号代表注释),添加新的配置,下面是ntp.conf文件的所有配置

root@debian:/home/test# cat /etc/ntpsec/ntp.conf 
# /etc/ntpsec/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

driftfile /var/lib/ntpsec/ntp.drift
leapfile /usr/share/zoneinfo/leap-seconds.list

# To enable Network Time Security support as a server, obtain a certificate
# (e.g. with Let's Encrypt), configure the paths below, and uncomment:
# nts cert CERT_FILE
# nts key KEY_FILE
# nts enable

# You must create /var/log/ntpsec (owned by ntpsec:ntpsec) to enable logging.
#statsdir /var/log/ntpsec/
#statistics loopstats peerstats clockstats
#filegen loopstats file loopstats type day enable
#filegen peerstats file peerstats type day enable
#filegen clockstats file clockstats type day enable

# This should be maxclock 7, but the pool entries count towards maxclock.
tos maxclock 11

# Comment this out if you have a refclock and want it to be able to discipline
# the clock by itself (e.g. if the system is not connected to the network).
tos minclock 4 minsane 3

# Specify one or more NTP servers.

# Public NTP servers supporting Network Time Security:
# server time.cloudflare.com nts
server 192.168.6.200                 #添加NTP服务器地址


# pool.ntp.org maps to about 1000 low-stratum NTP servers.  Your server will
# pick a different set every time it starts up.  Please consider joining the
# pool: <https://www.pool.ntp.org/join.html>
#pool 0.debian.pool.ntp.org iburst    #注释
#pool 1.debian.pool.ntp.org iburst    #注释
#pool 2.debian.pool.ntp.org iburst    #注释
#pool 3.debian.pool.ntp.org iburst    #注释


# Access control configuration; see /usr/share/doc/ntpsec-doc/html/accopt.html
# for details.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.
restrict default kod nomodify nopeer noquery limited

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1

重启ntpd服务

service ntpd restart

查看同步状态

ntpq -pn

 等待系统识别并选择后,在IP前面会标*/+如下图所示

服务器主机名前符号的含义

-意味着本地NTP服务不太喜欢此服务器
+表示本地 NTP 服务喜欢此服务器
x标记错误的主机
*指示当前收藏夹

附:每列的含义

remote
远程 NTP 服务器的名称。如果使用 -n 开关,您将看到这些服务器的 IP 地址,而不是它们的主机名。
refid
指示每个服务器现在从何处获取时间。它可以是服务器主机名或类似 .全球定位系统。 ,表示全球定位系统源。
st
tratum 是一个介于 1 到 16 之间的数字,表示远程服务器的精度。 1 表示最准确,16 表示“服务器无法访问”。您的层将等于精确的远程服务器加 1。切勿连接到第 1 层服务器,请使用第 2 层服务器!第 2 层服务器也适合我们的目的,此策略适用于减少第 1 层服务器的流量。
poll
时间请求之间的轮询间隔(以秒为单位)。该值的范围介于允许的最小和最大轮询值之间。最初,该值将较小,以便快速进行同步。时钟“同步”后,轮询值将增加,以减少网络流量和常用时间服务器上的负载。
reach
这是 8 位数组的八进制表示形式,表示本地计算机尝试到达服务器的最后 8 次。如果到达远程服务器,则设置该位。
delay
接收“现在几点了”请求的响应所需的时间(秒)。
offset
最重要的价值。本地服务器和远程服务器之间的时间差。在同步过程中,偏移时间降低,表明本地机器时间越来越准确。
jitter
离散(也称为抖动)是几个连续请求/响应对之间偏移的统计方差的度量。较低的色散值优于较高的色散值。较低的色散可实现更精确的时间同步。

ntpd服务加入开机启动

使用下面命令将ntpd服务加入开机启动

chkconfig --level 2345 ntpd on 

end。

标签:同步,ntp,ntpsec,NTP,服务器,Debian12,debian,pool
From: https://www.cnblogs.com/xujiecnblogs/p/17570579.html

相关文章

  • ntpdate
    ntpdate使用网络计时协议(NTP)设置日期和时间补充说明ntpdate命令是用来设置本地日期和时间。它从指定的每个服务器获得了一些样本,并应用标准NTP时钟过滤器和选择算法来选择最好的样本。此ntpdate命令使用以下方法进行时间调整:如果它确定时钟偏差超过0.5秒,它通过调用s......
  • 用rsync来同步mongodb的数据,可行吗?
    用rsync来同步mongodb的数据,可行吗?当涉及到数据的备份和同步时,rsync是一个非常常用的工具。那么,我们可以使用rsync来同步mongodb的数据吗?答案是肯定的。在本文中,我将介绍如何使用rsync来备份和同步mongodb的数据,并提供相应的代码示例。首先,让我们来了解一下rsync。rsync是一个......
  • 阻塞与非阻塞、同步与异步 I/O模型
    I/O模型Linux下的五种I/O模型阻塞I/O(blockingI/O)非阻塞I/O(nonblockingI/O)I/O复用(select和poll)(I/Omultiplexing)信号驱动I/O(signaldrivenI/O(SIGIO))异步I/O(asynchronousI/O(thePOSIXaio_functions))前四种都是同步,只有最后一种才是异步IO。 Winsock的异步IO模......
  • Discuz x3 UCenter实现同步登陆原理
    1、Discuzx3的登录页面URL是:/member.php?mod=logging&action=login2、这个登录页面,登录提交的地址是:<formmethod="post"autocomplete="off"name="login"id="loginform_LKsWY"class="cl"onsubmit="pwdclear=1;ajaxpo......
  • windows clion代码同步(rsync)
    代码同步原理简单说,客户端将代码上传到云端,利用云端环境进行编译,编译成功后将产物(符号表)拉取至本地进行加载,ide对符号表进行索引,则完成整个代码的加载。同步配置参考前置条件假设已经安装好gcc环境和cmake-3.6.x环境配置教程参考https://cloud.tencent.com/developer/articl......
  • STK之Commu模块之仿真同步卫星与地面站通信
    目录前言一、建立场景二、开展评估前言通过STK软件,建立了两个地面站北京和三亚通过同步轨道卫星之间开展通信的场景,并进行了通信链路性能仿真评估,通信链路顺序是北京->卫星->三亚。场景文件下载地址:https://download.csdn.net/download/juanhuokang2681/19861721?s......
  • OpenMLDB 发布线上到线下数据自动同步工具
    OpenMLDB正式发布线上到线下数据自动同步工具OpenMLDB作为一个线上线下一致的实时特征计算平台,通过合理的线上线下数据存储,确保线上到线下数据的一致性。由于线上和线下数据有不同性能和数据量的需求,通常情况下,OpenMLDB的线上和线下的数据在物理上是分开存储。在以前版本中,需......
  • Azure VM (43) Azure VM时钟同步
    《WindowsAzurePlatform系列文章目录》 本文主要介绍AzureLinuxVM时钟同步问题在CentOS8.x上,默认采用chrony配置为使用PTP源同步。Chrony所选时间来源是可以配置的,你可以选择让他从Azure物理机进行时间同步(也就是通过PTP时钟)。具体可以参考:https://l......
  • Ubuntu16.04配置NTP时间同步
    环境查看系统版本:lsb_release-a名词解释PDT是指太平洋夏令时(PacificDaylightTime),是美国西部地区和加拿大的一部分地区使用的时区。它位于UTC-7和UTC-8之间,根据不同年份和月份而有所不同。UTC是协调世界时(CoordinatedUniversalTime)的缩写,是一种全球通用的时间标准。......
  • 使用Canal同步mysql数据到es
    一、简介Canal主要用途是基于MySQL数据库增量日志解析,提供增量数据订阅和消费。当前的canal支持源端MySQL版本包括5.1.x,5.5.x,5.6.x,5.7.x,8.0.x二、工作原理MySQL主备复制原理MySQLmaster将数据变更写入二进制日志(binarylog,其中记录叫做二进制日志事件bin......