Outils pour utilisateurs

Outils du site


tech:ntp_temps_horloge_heure

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
tech:ntp_temps_horloge_heure [2025/03/24 15:06] – créée - modification externe 127.0.0.1tech:ntp_temps_horloge_heure [2025/10/24 09:49] (Version actuelle) Jean-Baptiste
Ligne 1: Ligne 1:
 +<!DOCTYPE markdown>
 {{tag>SystemD Réseau Temps NTP UDP}} {{tag>SystemD Réseau Temps NTP UDP}}
  
-NTP temps horloge heure+NTP temps horloge heure
  
-== Temps horloge Comment vérifier que NTP fonctionne+## Temps horloge Comment vérifier que NTP fonctionne
  
  
 Voir : Voir :
-* Film [[http://www.canal-u.tv/video/cerimes/quels_temps_font_ils_une_introduction_au_temps_des_physiciens.7605|Quels temps font-ils ?]] +* Film [Quels temps font-ils ?](http://www.canal-u.tv/video/cerimes/quels_temps_font_ils_une_introduction_au_temps_des_physiciens.7605) 
-[[https://wiki.debian.org/fr/NTP]]+* https://wiki.debian.org/fr/NTP
 * http://www.ntp.org/ntpfaq/NTP-s-trbl-general.htm * http://www.ntp.org/ntpfaq/NTP-s-trbl-general.htm
 * Si pb de flux réseau voir [[tunnel_ssh_udp_forward]] * Si pb de flux réseau voir [[tunnel_ssh_udp_forward]]
 +* https://www.vmware.com/docs/vmware_timekeeping
 +* /etc/adjtime ''man 5 adjtime_config''
 +* ''man 4 rtc'' (Real-Time Clock)
 +* https://kb.meinbergglobal.com/kb/time_sync/ntp/ntp_basics
  
  
-== Configurer+## Configurer
  
-=== Configurer via Systemd+### Configurer via Systemd
  
-<code ini /etc/systemd/timesyncd.conf>+''/etc/systemd/timesyncd.conf'' 
 +~~~ini
 [Time] [Time]
 Servers=0.debian.pool.ntp.org 1.debian.pool.ntp.org Servers=0.debian.pool.ntp.org 1.debian.pool.ntp.org
-</code>+~~~
  
-<code bash>+~~~bash
 timedatectl set-ntp true timedatectl set-ntp true
-</code>+~~~
  
 Diag Diag
-<code bash>+~~~bash
 systemctl restart systemd-timesyncd systemctl restart systemd-timesyncd
 systemctl status systemd-timesyncd systemctl status systemd-timesyncd
-</code>+~~~
  
-=== Configurer via Chrony+ 
 +### Configurer via Chrony
  
 TODO TODO
  
-=== Configurer via NTP 
  
-<code bash>+### Configurer via NTP 
 + 
 +~~~bash
 aptitude install ntp aptitude install ntp
-</code>+~~~
  
 On configure le serveur de temps via le fichier  On configure le serveur de temps via le fichier 
  
 Notamment les lignes suivantes: Notamment les lignes suivantes:
-<code - /etc/ntp.conf>+ 
 +''/etc/ntp.conf'' 
 +~~~
 # le serveur doit lui aussi se synchroniser # le serveur doit lui aussi se synchroniser
  
Ligne 60: Ligne 70:
  
 broadcast 192.168.0.255 broadcast 192.168.0.255
-</code>+~~~
  
  
  
-=== Configurer via ntpdate+#### The systems were using only two NTP servers 
 +Four NTP servers are recommended. See http://support.ntp.org/bin/view/Support/SelectingOffsiteNTPServers
  
 +"With two, it is impossible to tell which one is better, because you don't have any other references to compare them with. This is actually the worst possible configuration -- you'd be better off using just one upstream time server and letting the clocks run free if that upstream were to die or become unreachable."
 +
 +"Use at least 4 NTP servers"
 +
 +
 +
 +
 +#### Pour éviter la dérive sur les VM
 +
 +** Ou passer à Chrony **
 +
 +~~~
 +tinker panic 0
 +~~~
 +
 +"The tinker panic value of 0 tells NTP that no matter what the time offset is, not to panic and exit. This is recommended for virtual machines because virtual machines have no physical clock and can be paused at anytime and started back up hours later."
 +
 +Source : https://www.redhat.com/en/blog/avoiding-clock-drift-vms
 +
 +Voir : 
 +* https://documentation.avaya.com/fr-CA/bundle/DeployingSystemManagerinVE_r10.1/page/Timekeeping__NTP_.html
 +
 +
 +1 - Add the following line to the beginning of the ''/etc/ntp.conf'' file 
 +~~~bash
 +tinker panic 0
 +~~~
 +
 +2 - Remove or comment the "driftfile"
 +~~~bash
 +#driftfile /var/lib/ntp/drift/ntp.drift # path for drift file
 +~~~
 +
 +3 - Restart the ntpd.service
 +~~~bash
 +/bin/systemctl restart ntpd.service
 +~~~
 +
 +Voir https://www.suse.com/fr-fr/support/kb/doc/?id=000021102
 +
 +
 +### Configurer via ntpdate
 +
 +
 +''ntpdate -B'' ajustement progressif
  
-''ntpdate -B'' ajustement progressif \\ 
 ''ntpdate -b'' ajustement brutal ''ntpdate -b'' ajustement brutal
  
-<code bash>+~~~bash
 aptitude install ntpdate aptitude install ntpdate
-</code> +~~~
-Utilisation manuel+
  
-<code bash>+Utilisation manuel 
 +~~~bash
 /usr/sbin/ntpdate -dvu 192.168.2.11 /usr/sbin/ntpdate -dvu 192.168.2.11
-</code>+~~~
  
 Automatisation Automatisation
-<code bash>+~~~bash
 crontab -e crontab -e
-</code>+~~~
  
 Ajouter la ligne suivante: Ajouter la ligne suivante:
-<code ->+~~~
 0 3 * * * root /usr/sbin/ntpdate -dv ntp.serveur.org > /dev/null 0 3 * * * root /usr/sbin/ntpdate -dv ntp.serveur.org > /dev/null
-</code>+~~~
  
  
 Tester / simuler / lecture seul / dry-run Tester / simuler / lecture seul / dry-run
-<code bash>+~~~bash
 ntpdate -q pool.ntp.org ntpdate -q pool.ntp.org
-</code>+~~~
  
-===  Horloge matérielle / BIOS / hwclock+ 
 +#### Autres 
 + 
 +''/etc/sysconfig/ntp'' 
 + 
 +~~~bash 
 +SYNC_HWCLOCK=yes 
 +~~~ 
 + 
 +This is an option to ntpdate 
 + 
 + 
 +###  Horloge matérielle / BIOS / hwclock
  
  
  
 Afficher la date et l’heure Afficher la date et l’heure
-<code bash>+~~~bash
 date date
-</code>+~~~
  
 Si la date est incorrecte, utiliser date MMDDmm Si la date est incorrecte, utiliser date MMDDmm
  
 Afficher l’heure du BIOS Afficher l’heure du BIOS
-<code bash>+~~~bash
 hwclock hwclock
-</code>+~~~
  
 Commande pour que le BIOS puisse utiliser l’heure du système Commande pour que le BIOS puisse utiliser l’heure du système
-<code bash>+~~~bash
 hwclock --systohc --utc hwclock --systohc --utc
-</code>+~~~
  
 Comparaison du temps système et le BIOS Comparaison du temps système et le BIOS
-<code bash>+~~~bash
 date date
 hwclock hwclock
-</code>+~~~
  
 Vérification dans le fichier  Vérification dans le fichier 
-<code ini /etc/sysconfig/clock>+''/etc/sysconfig/clock'' 
 +~~~bash
 UTC=true UTC=true
-</code>+~~~
  
-== Vérifier+## Vérifier
  
 Source: https://www.cyberciti.biz/faq/linux-unix-bsd-is-ntp-client-working/ Source: https://www.cyberciti.biz/faq/linux-unix-bsd-is-ntp-client-working/
Ligne 138: Ligne 206:
  
  
-=== ntpstat+### ntpstat
  
-<code bash>+~~~bash
 ntpstat ntpstat
-</code>+~~~
  
-| **Exit status** | **Error**                                                            |+| **Exit status** | **Error**                                                               | 
 +| --------------- | ----------------------------------------------------------------------- |
 | 0               | Clock is synchronised.                                                  |  | 0               | Clock is synchronised.                                                  | 
 | 1               | Clock is not synchronised.                                              | | 1               | Clock is not synchronised.                                              |
 | 2               | If clock state is indeterminant, for example if ntpd is not contactable | | 2               | If clock state is indeterminant, for example if ntpd is not contactable |
  
-=== ntpq 
  
 +### ntpq
  
-<code bash>+ 
 +~~~bash
 ntpq -pn ntpq -pn
-</code>+~~~
  
 Source : https://www.system-linux.eu/index.php?post/2010/01/05/Mettre-vos-serveurs-%C3%A0-la-bonne-heure-avec-NTP Source : https://www.system-linux.eu/index.php?post/2010/01/05/Mettre-vos-serveurs-%C3%A0-la-bonne-heure-avec-NTP
  
-<code ->+~~~
 # ntpq -p # ntpq -p
  
Ligne 167: Ligne 237:
 kontir.mkc.fr   213.251.128.249  2 u  13  64  1  76.501 18.866 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 dnscache-london 140.203.16.5   2 u  12  64  1  58.209  4.266 0.015
-</code>+~~~
  
 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 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.
Ligne 174: Ligne 244:
  
 Resynchroniser Resynchroniser
-<code bash>+~~~bash
 sudo service ntp stop sudo service ntp stop
 sudo ntpd -gq sudo ntpd -gq
 sudo service ntp start sudo service ntp start
-</code> +~~~
-=== SystemD - timedatectl+
  
-<code bash>+ 
 +### SystemD - timedatectl 
 + 
 +~~~bash
  timedatectl status |grep NTP  timedatectl status |grep NTP
-</code> +~~~ 
-<code ->+~~~
      NTP enabled: yes      NTP enabled: yes
 NTP synchronized: yes NTP synchronized: yes
-</code>+~~~
  
-=== Chrony - chronyc +### Chrony - chronyc 
  
-<code bash>+~~~bash
 chronyc tracking chronyc tracking
 chronyc sources chronyc sources
 chronyc sourcestats chronyc sourcestats
-</code>+~~~
  
  
Ligne 201: Ligne 273:
  
  
-== Autres +## Autres
  
-<code bash>+### Timesyncd 
 + 
 +''/lib/systemd/system/systemd-timesyncd.service.d/wsl.conf'' 
 +~~~ini 
 +# Enable timesyncd on WSL machines 
 +# so WSL clock is synced on resume from suspend of the host. 
 + 
 +[Unit] 
 +ConditionVirtualization= 
 +ConditionVirtualization=|!container 
 +ConditionVirtualization=|wsl 
 +~~~ 
 + 
 + 
 +### Adjtimex 
 + 
 + 
 +~~~bash
 apt-get install adjtimex apt-get install adjtimex
-</code>+~~~
  
 Avant de faire une manip Avant de faire une manip
-<code bash>+~~~bash
 adjtimex -u -l=/var/log/clocks.log adjtimex -u -l=/var/log/clocks.log
-</code>+~~~
  
  
 Voir http://www.linux-france.org/article/sys/heure/ch3.html Voir http://www.linux-france.org/article/sys/heure/ch3.html
  
-=== clocksource+### clocksource
  
 Oracle recommande de changer le "clock source" à ''tsc'' pour les VM Linux x86-64. Oracle recommande de changer le "clock source" à ''tsc'' pour les VM Linux x86-64.
  
-<code ->+~~~
 # cat /sys/devices/system/clocksource/clocksource0/available_clocksource # cat /sys/devices/system/clocksource/clocksource0/available_clocksource
 xen tsc acpi_pm  xen tsc acpi_pm 
-</code>+~~~
  
 If the tsc clock source is available, then set tsc as the current clock source. If the tsc clock source is available, then set tsc as the current clock source.
-<code bash>+~~~bash
 echo "tsc" > /sys/devices/system/clocksource/clocksource0/current_clocksource echo "tsc" > /sys/devices/system/clocksource/clocksource0/current_clocksource
-</code>+~~~
  
  
 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. 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.
-<code bash /etc/default/grub>+ 
 +''/etc/default/grub'' 
 +~~~bash
 GRUB_CMDLINE_LINUX="rd.lvm.lv=ol/root rd.lvm.lv=ol/swap rhgb quiet numa=off transparent_hugepage=never clocksource=tsc"  GRUB_CMDLINE_LINUX="rd.lvm.lv=ol/root rd.lvm.lv=ol/swap rhgb quiet numa=off transparent_hugepage=never clocksource=tsc" 
-</code>+~~~
  
  
  
-== Falsifier la date et l'heure avec faketime+## Falsifier la date et l'heure avec faketime
  
-<code bash>+~~~bash
 faketime 2016-01-01 gpg --list-keys faketime 2016-01-01 gpg --list-keys
-</code>+~~~
  
  
-== Pb+## Pb
  
-=== Pb fichier de conf ignoré à cause d'une conf via DHCP+### Pb fichier de conf ignoré à cause d'une conf via DHCP
  
 Voir aussi : https://coreos.com/os/docs/latest/configuring-date-and-timezone.html Voir aussi : https://coreos.com/os/docs/latest/configuring-date-and-timezone.html
Ligne 252: Ligne 343:
 ''/var/lib/ntp/ntp.conf.dhcp'' ''/var/lib/ntp/ntp.conf.dhcp''
  
-<code bash>+~~~bash
 ps -ef |grep ntp ps -ef |grep ntp
-</code>+~~~
  
-<code ->+~~~
 ntp       9777      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 ntp       9777      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
-</code>+~~~
  
-<code bash>+~~~bash
 rm /var/lib/ntp/ntp.conf.dhcp rm /var/lib/ntp/ntp.conf.dhcp
 systemctl restart ntp systemctl restart ntp
-</code>+~~~
  
 ou sur Redhat ou sur Redhat
-<code bash>+~~~bash
 rm /var/lib/dhclient/chrony.servers.eth0 rm /var/lib/dhclient/chrony.servers.eth0
 systemctl restart chronyd.service systemctl restart chronyd.service
-</code>+~~~
  
-=== Pb - the NTP socket is in use, exiting 
  
 +### Pb - the NTP socket is in use, exiting
  
-==== Solution 1 + 
-<code bash>+#### Solution 1 
 +~~~bash
 ntpdate -u pool.ntp.org ntpdate -u pool.ntp.org
-</code>+~~~
  
-==== Solution 2+#### Solution 2
  
 Arrêt du service (pour libérer le socket réseau UDP) puis Arrêt du service (pour libérer le socket réseau UDP) puis
-<code bash>+~~~bash
 ntpdate -u pool.ntp.org ntpdate -u pool.ntp.org
-</code>+~~~
  
-[[http://superuser.com/questions/639202/updating-time-ntpdate3108-the-ntp-socket-is-in-use-exiting +http://superuser.com/questions/639202/updating-time-ntpdate3108-the-ntp-socket-is-in-use-exiting 
-ntptrace]]+ntptrace
  
  
-=== Pb avec VirtualBox+### Pb avec VirtualBox
  
 ''ConditionFileIsExecutable=!/usr/sbin/VBoxService was not met'' ''ConditionFileIsExecutable=!/usr/sbin/VBoxService was not met''
  
-<code ->+~~~
 # systemctl status systemd-timesyncd # systemctl status systemd-timesyncd
 ● systemd-timesyncd.service - Network Time Synchronization ● systemd-timesyncd.service - Network Time Synchronization
Ligne 304: Ligne 396:
            └─ ConditionFileIsExecutable=!/usr/sbin/VBoxService was not met            └─ ConditionFileIsExecutable=!/usr/sbin/VBoxService was not met
      Docs: man:systemd-timesyncd.service(8)      Docs: man:systemd-timesyncd.service(8)
-</code>+~~~
  
-==== Solution+ 
 +#### Solution
      
-<code ini /lib/systemd/system/systemd-timesyncd.service.d/disable-with-time-daemon.conf>+''/lib/systemd/system/systemd-timesyncd.service.d/disable-with-time-daemon.conf'' 
 + 
 +~~~ini
 [Unit] [Unit]
 # do not run timesyncd if we have another NTP daemon installed # do not run timesyncd if we have another NTP daemon installed
 #ConditionFileIsExecutable=!/usr/sbin/VBoxService #ConditionFileIsExecutable=!/usr/sbin/VBoxService
-</code>+~~~
  
-<code bash>+~~~bash
 systemctl daemon-reload systemctl daemon-reload
 systemctl restart systemd-timesyncd systemctl restart systemd-timesyncd
-</code>+~~~
  
  
  
tech/ntp_temps_horloge_heure.1742825205.txt.gz · Dernière modification : de 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki