debian 11 时间同步chrony

debian 11 时间同步服务 chrony

实验环境

server 192.168.1.4
client 192.168.1.5

server配置

#安装chrony
apt install -y chrony
cat /etc/chrony/chrony.conf 
# Welcome to the chrony configuration file. See chrony.conf(5) for more
# information about usable directives.

# Include configuration files found in /etc/chrony/conf.d.
confdir /etc/chrony/conf.d

# Use Debian vendor zone.
#pool 2.debian.pool.ntp.org iburst

server 192.168.1.4 iburst
allow 192.168.1.0/24
local stratum 10

# Use time sources from DHCP.
sourcedir /run/chrony-dhcp

# Use NTP sources found in /etc/chrony/sources.d.
sourcedir /etc/chrony/sources.d

# This directive specify the location of the file containing ID/key pairs for
# NTP authentication.
keyfile /etc/chrony/chrony.keys

# This directive specify the file into which chronyd will store the rate
# information.
driftfile /var/lib/chrony/chrony.drift

# Save NTS keys and cookies.
ntsdumpdir /var/lib/chrony

# Uncomment the following line to turn logging on.
#log tracking measurements statistics

# Log files location.
logdir /var/log/chrony

# Stop bad estimates upsetting machine clock.
maxupdateskew 100.0

# This directive enables kernel synchronisation (every 11 minutes) of the
# real-time clock. Note that it can’t be used along with the 'rtcfile' directive.
rtcsync

# Step the system clock instead of slewing it if the adjustment is larger than
# one second, but only in the first three clock updates.
makestep 1 3

# Get TAI-UTC offset and leap seconds from the system tz database.
# This directive must be commented out when using time sources serving
# leap-smeared time.
leapsectz right/UTC
#重启服务
systemctl restart chrony.service 

client配置

#安装chrony
apt install -y chrony
cat /etc/chrony/chrony.conf 
# Welcome to the chrony configuration file. See chrony.conf(5) for more
# information about usable directives.

# Include configuration files found in /etc/chrony/conf.d.
confdir /etc/chrony/conf.d

# Use Debian vendor zone.
#pool 2.debian.pool.ntp.org iburst
server 192.168.1.4 iburst
# Use time sources from DHCP.
sourcedir /run/chrony-dhcp

# Use NTP sources found in /etc/chrony/sources.d.
sourcedir /etc/chrony/sources.d

# This directive specify the location of the file containing ID/key pairs for
# NTP authentication.
keyfile /etc/chrony/chrony.keys

# This directive specify the file into which chronyd will store the rate
# information.
driftfile /var/lib/chrony/chrony.drift

# Save NTS keys and cookies.
ntsdumpdir /var/lib/chrony

# Uncomment the following line to turn logging on.
#log tracking measurements statistics

# Log files location.
logdir /var/log/chrony

# Stop bad estimates upsetting machine clock.
maxupdateskew 100.0

# This directive enables kernel synchronisation (every 11 minutes) of the
# real-time clock. Note that it can’t be used along with the 'rtcfile' directive.
rtcsync

# Step the system clock instead of slewing it if the adjustment is larger than
# one second, but only in the first three clock updates.
makestep 1 3

# Get TAI-UTC offset and leap seconds from the system tz database.
# This directive must be commented out when using time sources serving
# leap-smeared time.
leapsectz right/UTC
#重启服务
systemctl restart chronyd

测试

chronyc clients   //在server上测试
Hostname                      NTP   Drop Int IntL Last     Cmd   Drop Int  Last
===============================================================================
192.168.1.4                     8      0   1   -    42       0      0   -     -
192.168.1.5                     5      0   4   -    21       0      0   -     -

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Debian上配置NTP,可以按照以下步骤进行操作: 1. 打开防火墙端口:使用iptables命令来允许NTP流量通过防火墙。例如,可以使用以下命令来允许UDP端口123的流量通过防火墙: ``` iptables -A INPUT -p udp --dport 123 -j ACCEPT iptables -A OUTPUT -p udp --sport 123 -j ACCEPT ``` 这将允许NTP服务器和客户端之间的通信。\[1\] 2. 安装和配置NTP服务:使用以下命令安装NTP软件包: ``` sudo apt-get install ntp ``` 安装完成后,可以编辑NTP的配置文件`/etc/ntp.conf`。可以根据需要修改以下行: ``` server 127.127.1.0 fudge 127.127.1.0 stratum 5 restrict 81.6.63.0 mask 255.255.255.0 ``` 其中,`server`指定了NTP服务器的地址,这里将当前主机作为时间服务器。`fudge`用于设置时间服务器的层级,`stratum`表示层级的值,可以根据需要进行调整。`restrict`用于限制哪些网段可以同步时间,可以根据需要进行修改。\[3\] 3. 重启NTP服务:完成配置后,可以使用以下命令重启NTP服务: ``` sudo service ntp restart ``` 这将使配置的更改生效。\[3\] 请注意,使用ntpdate命令来同步时间的方法已经不推荐使用,因为它存在安全性、精确性和优雅性方面的问题。相反,推荐使用ntpd来校准计算机的时间和时钟。\[2\] #### 引用[.reference_title] - *1* *3* [Debian 10 NTP 服务配置](https://blog.csdn.net/TXuing/article/details/126100620)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [debian-ntp服务器配置](https://blog.csdn.net/bmxch/article/details/129470123)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值