User Tools

Site Tools


ntp_date

NTP / date

Généralités

Network Time Protocol (NTP, protocole horaire en réseau), est un protocole permettant de synchroniser les horloges des systèmes informatiques à travers un réseau de paquets, dont la latence est variable.

Hardware Clock

hwclock -c
hwclock --systohc
hwclock --hctosys

Time zone

La commande tzselect permet de trouver le time zone mais timedatectl permet de tout gérer.

timedatectl
timedatectl status
timedatectl list-timezones
timedatectl set-timezone Europe/Amsterdam
timedatectl show
timedatectl set-ntp true

Sous Red Hat 5 et 6

Changer le fuseau horaire de l'OS.

/etc/sysconfig/clock Configuration GMT sans changement d'heure.

ZONE="Etc/GMT" ou ZONE="Europe/Paris"
UTC=false
ARC=false

Configuration UTC avec changement d'heure.

ZONE="Europe/Paris"
UTC=true
ARC=false

Le fichier réellement utilisé est /etc/localtime. C'est une copie d'un des fichiers de timezone dans l'espace suivant.

/usr/share/zoneinfo/<arbo de dossier des zones de temps>

Pour passer une machine en GMT ou en UTC.

ln -sf /usr/share/zoneinfo/Etc/GMT /etc/localtime
ln -sf /usr/share/zoneinfo/Etc/UTC /etc/localtime
date

Pour passer une machine en UTC+1.

ln -sf /usr/share/zoneinfo/Europe/Paris /etc/localtime
date

Ne nécessite pas de redémarrer l'OS.

Sous Debian

Pour passer une machine en GMT.

cp /usr/share/zoneinfo/Etc/GMT /etc/localtime
date

On peut utiliser la commande suivante.

dpkg-reconfigure tzdata

Sélectionner le bon timezone dans la liste et valider.

chrony

apt install chrony

/etc/chrony/chrony.conf

# Welcome to the chrony configuration file. See chrony.conf(5) for more
# information about usuable directives.
pool 1.debian.pool.ntp.org iburst
pool 2.debian.pool.ntp.org iburst

# 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

# 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 tells 'chronyd' to parse the 'adjtime' file to find out if the
# real-time clock keeps local time or UTC. It overrides the 'rtconutc' directive.
hwclockfile /etc/adjtime

# 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
systemctl restart chrony
chronyc sources -v

ntpd

Emplacement Fonction
/etc/ntp.conf Fichier de configuration général avec la liste des serveurs NTP, les restrictions…
/etc/ntp/step-tickers Fichier avec la liste des serveurs NTP.
/etc/ntp/ntpservers Fichier avec la liste des serveurs NTP.
/etc/ntp/keys Fichier des clés.

Configuration spécifique

En partant du principe qu'on dispose de deux serveurs NTP au sein de notre structure avec les adresses suivantes.

  • Serveur NTP 1 : 172.20.15.1
  • Serveur NTP 2 : 172.20.15.2

Édition de /etc/ntp.conf

# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.

restrict default ignore

# 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


# -- CLIENT NETWORK -------
# Permit systems on this network to synchronize with this
# time service.  Do not permit those systems to modify the
# configuration of this service.  Also, do not use those
# systems as peers for synchronization.
# restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

restrict 172.20.15.1 mask 255.255.255.255
restrict 172.20.15.2 mask 255.255.255.255

# --- OUR TIMESERVERS -----

server  172.20.15.1
server  172.20.15.2


# --- NTP MULTICASTCLIENT ---
#multicastclient                        # listen on default 224.0.1.1
# restrict 224.0.1.1 mask 255.255.255.255 nomodify notrap
# restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# --- GENERAL CONFIGURATION ---
#
# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available. The
# default stratum is usually 3, but in this case we elect to use stratum
# 0. Since the server line does not have the prefer keyword, this driver
# is never used for synchronization, unless no other other
# synchronization source is available. In case the local host is
# controlled by some external source, such as an external oscillator or
# another protocol, the prefer keyword would cause the local host to
# disregard all other synchronization sources, unless the kernel
# modifications are in use and declare an unsynchronized condition.
#
#server 127.127.1.0
#fudge  127.127.1.0 stratum 10

#
# Drift file.  Put this in a directory which the daemon can write to.
# No symbolic links allowed, either, since the daemon updates the file
# by creating a temporary in the same directory and then rename()'ing
# it to the file.
#
driftfile /var/lib/ntp/drift
broadcastdelay  0.008

#
# Keys file.  If you want to diddle your server at run time, make a
# keys file (mode 600 for sure) and define the key number to be
# used for making requests.
#
# PLEASE DO NOT USE THE DEFAULT VALUES HERE. Pick your own, or remote
# systems might be able to reset your clock at will. Note also that
# ntpd is started with a -A flag, disabling authentication, that
# will have to be removed as well.
#
#keys           /etc/ntp/keys

ntpd.conf basique

tinker panic 0
restrict default nomodify notrap noquery
restrict 127.0.0.1
driftfile /var/lib/ntp/drift
broadcastdelay  0.008
keys            /etc/ntp/keys
server <nom-server>.<domaine> burst iburst

Édition de /etc/ntp/step-tickers

Liste des sources de temps utilisées dès l'initialisation.

172.20.15.1
172.20.15.2

Édition de /etc/ntp/ntpservers

172.20.15.1
172.20.15.1
clock.redhat.com
clock2.redhat.com

Par souci de sécurité, je rajoute des serveurs ntp membre du pool.ntp.org (http://www.pool.ntp.org/) au cas où nos deux serveurs soient en panne! La différence entre le fichier ntpservers et step-tickers est que le dernier est lu au démarrage du service ntpd lancé au démarrage et permet donc la vérification et la correction directe d'un éventuel écart d'horaire.

Édition de /etc/ntp/keys

#
# PLEASE DO NOT USE THE DEFAULT VALUES HERE. Pick your own, or remote
# systems might be able to reset your clock at will. Note also that
# ntpd is started with a -A flag, disabling authentication, that
# will have to be removed as well.
#
#65535  M       akey
#1      M       pass

Ce détail de configuration spécifique a été appliqué à tous les serveurs physique et ceux en environnement virtualisé. Il est basé sur la configuration qui a été faîtes sur les serveurs physiques. Ils sont donc tous configurés de la même manière.

Pour vérifier si tout fonctionne correctement taper la commande.

ntptrace mon_serveur_ntp

Cela doit sortir des informations sur le serveur NTP.

Maintenant que tout fonctionne, il faut synchroniser le client avec le serveur. Cela se fait avec la commande.

ntpdate mon_serveur_ntp
ntpdate -d mon_serveur_ntp
ntp_date.txt · Last modified: 2021/01/21 21:42 (external edit)