Réalisez la synchronisation d'horloge NTP basée sur le LAN

 

1. Créez un environnement LAN

2. Sélectionnez un nœud comme serveur NTP

Par exemple, sélectionnez le nœud 192.168.1.149 pour déployer NTP et le configurer en tant que serveur NTP

#相关命令
sudo apt-get install ntp #安装
sudo systemctl enable ntpd #自启动
systemctl is-enabled ntp #检查自启动是否开启
sudo systemctl start ntp #手启动
service ntp status #ntp 状态
ntpq -p #ntp状态
netstat -tlunp | grep ntp #查看启动的端口(123)
firewall-cmd --zone=public --add-port=123/udp --permanent && firewall-cmd --reload #开放端口 123
#ntp.conf
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

driftfile /var/lib/ntp/ntp.drift

# Leap seconds definition provided by tzdata
leapfile /usr/share/zoneinfo/leap-seconds.list

# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/

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

# Specify one or more NTP servers.

# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
#pool 0.ubuntu.pool.ntp.org iburst
#pool 1.ubuntu.pool.ntp.org iburst
#pool 2.ubuntu.pool.ntp.org iburst
#pool 3.ubuntu.pool.ntp.org iburst

# Use Ubuntu's ntp server as a fallback.
#pool ntp.ubuntu.com

# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
# might also be helpful.
#
# 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 -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited

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

# Needed for adding pool entries
restrict source notrap nomodify noquery

# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 mask 255.255.255.0 notrust
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap #放行局域网来源,允许192.168.1.x网段中的服务器访问本ntp服务器进行时间同步


# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
#broadcast 192.168.123.255

# If you want to listen to time broadcasts on your local subnet, de-comment the
# next lines.  Please do this only if you trust everybody on the network!
#disable auth
#broadcastclient

#Changes recquired to use pps synchonisation as explained in documentation:
#http://www.ntp.org/ntpfaq/NTP-s-config-adv.htm#AEN3918

server time.cloudflare.com prefer    # Meinberg GPS167 with PPS
#fudge 127.127.8.1 time1 0.0042        # relative to PPS for my hardware

#server 127.127.22.1                   # ATOM(PPS)
#fudge 127.127.22.1 flag3 1            # enable PPS API
server 127.127.1.0   #local clock,和本地系统时间同步
fudge  127.127.1.0  stratum  10   #127.127.1.0为第10层。ntp和127.127.1.0同步完后,就变成了11层。ntp是层次阶级的。同步上层服务器的stratum大小不能超过或等于16
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor

 

3. Synchronisation manuelle des nœuds restants

ntpdate 192.168.1.149

4. Les nœuds restants sont synchronisés via chrony 

5. Exemple

mount -o remount -w / #挂载Linux系统外的文件,致其可修改
vi /etc/chrony.conf #修改配置文件
server 192.168.1.149 iburst minpoll 2 prefer
makestep 1.0 -1
sync # sync 指令会将存于 buffer 中的资料强制写入硬盘中。
ps -ef | grep chronyd
kill 4999
chronyd -d &
chronyc sources

6. Problèmes courants

  • ntp ne démarre pas automatiquement 
  • Désactiver chronyd; désactiver l'acquisition d'horloge dans les paramètres système Ubuntu

7. Références

Définissez la synchronisation de l' heure NTP LAN: https://blog.csdn.net/s_p_j/article/details/88386981

Je suppose que tu aimes

Origine blog.csdn.net/qq_41854291/article/details/108011650
conseillé
Classement