Ceci est une ancienne révision du document !
Table des matières
NTP temps horloge heure
Temps horloge Comment vérifier que NTP fonctionne
Voir :
- Si pb de flux réseau voir tunnel_ssh_udp_forward
Configurer
Configurer via Systemd
- /etc/systemd/timesyncd.conf
[Time] Servers=0.debian.pool.ntp.org 1.debian.pool.ntp.org
timedatectl set-ntp true
Diag
systemctl restart systemd-timesyncd systemctl status systemd-timesyncd
Configurer via Chrony
TODO
Configurer via NTP
aptitude install ntp
On configure le serveur de temps via le fichier
Notamment les lignes suivantes:
- /etc/ntp.conf
# le serveur doit lui aussi se synchroniser server 0.fr.pool.ntp.org # ou debian.pool.ntp.org server 1.fr.pool.ntp.org # ou debian.pool.ntp.org server 2.fr.pool.ntp.org # ou debian.pool.ntp.org server 3.fr.pool.ntp.org # ou debian.pool.ntp.org # Autoriser les autres ordinateurs à ce connecter: restrict 0.0.0.0 mask 0.0.0.0 # Limiter les ordinateurs pouvant se connecter à notre réseau personnel: broadcast 192.168.0.255
Configurer via ntpdate
ntpdate -B ajustement progressif
ntpdate -b ajustement brutal
aptitude install ntpdate
Utilisation manuel
/usr/sbin/ntpdate -dvu 192.168.2.11
Automatisation
crontab -e
Ajouter la ligne suivante:
0 3 * * * root /usr/sbin/ntpdate -dv ntp.serveur.org > /dev/null
Tester / simuler / lecture seul / dry-run
ntpdate -q pool.ntp.org
Horloge matérielle / BIOS / hwclock
Afficher la date et l’heure
date
Si la date est incorrecte, utiliser date MMDDmm
Afficher l’heure du BIOS
hwclock
Commande pour que le BIOS puisse utiliser l’heure du système
hwclock --systohc --utc
Comparaison du temps système et le BIOS
date
hwclock
Vérification dans le fichier
- /etc/sysconfig/clock
UTC=true
Vérifier
Source: https://www.cyberciti.biz/faq/linux-unix-bsd-is-ntp-client-working/
Commandes pour vérifier
- ntpq – standard NTP query program
- ntpstat – show network time synchronisation status
- timedatectl – show or set info about ntp using systemd
- chronyc tracking
ntpstat
ntpstat
| Exit status | Error |
| 0 | Clock is synchronised. |
| 1 | Clock is not synchronised. |
| 2 | If clock state is indeterminant, for example if ntpd is not contactable |
ntpq
ntpq -pn
# ntpq -p remote refid st t when poll reach delay offset jitter =========================================== europium.canoni 193.79.237.14 2 u 15 64 1 28.682 -3.649 0.015 horlogegps.rese 10.3.128.189 2 u 14 64 1 29.002 -11.238 0.015 kontir.mkc.fr 213.251.128.249 2 u 13 64 1 76.501 18.866 0.015 dnscache-london 140.203.16.5 2 u 12 64 1 58.209 4.266 0.015
Une fois la synchronisation faite des *, + et - apparaissent devant les noms de serveur. Le serveur précédé d’une astérisque (*) est celui utilisé, ceux précédés d’un moins (-) sont actuellement éliminés par l’algorithme de choix des serveurs, ceux précédés d’un plus (+) sont des candidats potentiels à la synchronisation et ceux précédés d’un espace sont soit inaccessibles, soit trop éloignés.
Une synchronisation correcte implique une valeur de « delay » et de « offset » non nulle, et de « jitter » inférieure à 100
Resynchroniser
sudo service ntp stop sudo ntpd -gq sudo service ntp start
SystemD - timedatectl
timedatectl status |grep NTP
NTP enabled: yes NTP synchronized: yes
Chrony - chronyc
chronyc tracking chronyc sources chronyc sourcestats
Autres
apt-get install adjtimex
Avant de faire une manip
adjtimex -u -l=/var/log/clocks.log
clocksource
Oracle recommande de changer le “clock source” à tsc pour les VM Linux x86-64.
# cat /sys/devices/system/clocksource/clocksource0/available_clocksource xen tsc acpi_pm
If the tsc clock source is available, then set tsc as the current clock source.
echo "tsc" > /sys/devices/system/clocksource/clocksource0/current_clocksource
Using any text editor, append the clocksource directive to the GRUB_CMDLINE_LINUX line in the /etc/default/grub file to retain this clock source setting even after a reboot.
- /etc/default/grub
GRUB_CMDLINE_LINUX="rd.lvm.lv=ol/root rd.lvm.lv=ol/swap rhgb quiet numa=off transparent_hugepage=never clocksource=tsc"
Falsifier la date et l'heure avec faketime
faketime 2016-01-01 gpg --list-keys
Pb
Pb fichier de conf ignoré à cause d'une conf via DHCP
Voir aussi : https://coreos.com/os/docs/latest/configuring-date-and-timezone.html
/var/lib/ntp/ntp.conf.dhcp
ps -ef |grep ntp
ntp 9777 1 0 08:04 ? 00:00:00 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -c /var/lib/ntp/ntp.conf.dhcp -u 108:113
rm /var/lib/ntp/ntp.conf.dhcp systemctl restart ntp
ou sur Redhat
rm /var/lib/dhclient/chrony.servers.eth0 systemctl restart chronyd.service
Pb - the NTP socket is in use, exiting
Solution 1
ntpdate -u pool.ntp.org
Solution 2
Arrêt du service (pour libérer le socket réseau UDP) puis
ntpdate -u pool.ntp.org
Pb avec VirtualBox
ConditionFileIsExecutable=!/usr/sbin/VBoxService was not met
# systemctl status systemd-timesyncd
● systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/systemd-timesyncd.service.d
└─disable-with-time-daemon.conf
Active: inactive (dead)
Condition: start condition failed at Fri 2019-10-11 11:37:16 CEST; 5min ago
└─ ConditionFileIsExecutable=!/usr/sbin/VBoxService was not met
Docs: man:systemd-timesyncd.service(8)
Solution
- /lib/systemd/system/systemd-timesyncd.service.d/disable-with-time-daemon.conf
[Unit] # do not run timesyncd if we have another NTP daemon installed #ConditionFileIsExecutable=!/usr/sbin/VBoxService
systemctl daemon-reload systemctl restart systemd-timesyncd
