tech:ntp_temps_horloge_heure
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| tech:ntp_temps_horloge_heure [2025/03/31 09:47] – Jean-Baptiste | tech:ntp_temps_horloge_heure [2026/07/17 14:05] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # NTP temps horloge heure | ||
| + | |||
| + | |||
| + | |||
| + | Voir : | ||
| + | * Film [Quels temps font-ils ? | ||
| + | * https:// | ||
| + | * NTP vs PTP | ||
| + | * http:// | ||
| + | * NTP NTS (Network Time Security) | ||
| + | * openntp | ||
| + | * ntpd-rs | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * Si pb de flux réseau voir [[tunnel_ssh_udp_forward]] | ||
| + | * / | ||
| + | * '' | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | Voir aussi : | ||
| + | * Meinberg Stratum 1 https:// | ||
| + | |||
| + | |||
| + | ## Lexiques | ||
| + | |||
| + | Strate : Strate de la source. La strate 1 indique une source avec une horloge de référence attachée localement. Une source synchronisée avec une source Stratum 1 est définie sur Stratum 2. Une source synchronisée avec une source de strate 2 est définie sur Stratum 3, et ainsi de suite. | ||
| + | Source : https:// | ||
| + | |||
| + | Type : Les sources NTP (Network Time Protocol) peuvent être un serveur (server) ou un pair (peer), c'est à dire client. | ||
| + | |||
| + | |||
| + | |||
| + | ## Configurer | ||
| + | |||
| + | ### Configurer via Systemd | ||
| + | |||
| + | ''/ | ||
| + | ~~~ini | ||
| + | [Time] | ||
| + | Servers=0.debian.pool.ntp.org 1.debian.pool.ntp.org | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | timedatectl set-ntp true | ||
| + | ~~~ | ||
| + | |||
| + | Diag | ||
| + | ~~~bash | ||
| + | systemctl restart systemd-timesyncd | ||
| + | systemctl status systemd-timesyncd | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### Configurer via Chrony | ||
| + | |||
| + | TODO | ||
| + | |||
| + | |||
| + | ### Configurer via NTP | ||
| + | |||
| + | ~~~bash | ||
| + | aptitude install ntp | ||
| + | ~~~ | ||
| + | |||
| + | On configure le serveur de temps via le fichier | ||
| + | |||
| + | Notamment les lignes suivantes: | ||
| + | |||
| + | ''/ | ||
| + | ~~~ | ||
| + | # 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 | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | #### The systems were using only two NTP servers | ||
| + | Four NTP servers are recommended. See http:// | ||
| + | |||
| + | "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:// | ||
| + | |||
| + | Voir : | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | 1 - Add the following line to the beginning of the ''/ | ||
| + | ~~~bash | ||
| + | tinker panic 0 | ||
| + | ~~~ | ||
| + | |||
| + | 2 - Remove or comment the " | ||
| + | ~~~bash | ||
| + | #driftfile / | ||
| + | ~~~ | ||
| + | |||
| + | 3 - Restart the ntpd.service | ||
| + | ~~~bash | ||
| + | / | ||
| + | ~~~ | ||
| + | |||
| + | Voir https:// | ||
| + | |||
| + | |||
| + | ### Configurer via ntpdate | ||
| + | |||
| + | |||
| + | '' | ||
| + | |||
| + | '' | ||
| + | |||
| + | ~~~bash | ||
| + | aptitude install ntpdate | ||
| + | ~~~ | ||
| + | |||
| + | Utilisation manuel | ||
| + | ~~~bash | ||
| + | / | ||
| + | ~~~ | ||
| + | |||
| + | Automatisation | ||
| + | ~~~bash | ||
| + | crontab -e | ||
| + | ~~~ | ||
| + | |||
| + | Ajouter la ligne suivante: | ||
| + | ~~~ | ||
| + | 0 3 * * * root / | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Tester / simuler / lecture seul / dry-run | ||
| + | ~~~bash | ||
| + | ntpdate -q pool.ntp.org | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | #### Autres | ||
| + | |||
| + | ''/ | ||
| + | |||
| + | ~~~bash | ||
| + | SYNC_HWCLOCK=yes | ||
| + | ~~~ | ||
| + | |||
| + | This is an option to ntpdate | ||
| + | |||
| + | |||
| + | ### Horloge matérielle / BIOS / hwclock | ||
| + | |||
| + | |||
| + | |||
| + | Afficher la date et l’heure | ||
| + | ~~~bash | ||
| + | date | ||
| + | ~~~ | ||
| + | |||
| + | Si la date est incorrecte, utiliser date MMDDmm | ||
| + | |||
| + | Afficher l’heure du BIOS | ||
| + | ~~~bash | ||
| + | hwclock | ||
| + | ~~~ | ||
| + | |||
| + | Commande pour que le BIOS puisse utiliser l’heure du système | ||
| + | ~~~bash | ||
| + | hwclock --systohc --utc | ||
| + | ~~~ | ||
| + | |||
| + | Comparaison du temps système et le BIOS | ||
| + | ~~~bash | ||
| + | date | ||
| + | hwclock | ||
| + | ~~~ | ||
| + | |||
| + | Vérification dans le fichier | ||
| + | ''/ | ||
| + | ~~~bash | ||
| + | UTC=true | ||
| + | ~~~ | ||
| + | |||
| + | ## Vérifier | ||
| + | |||
| + | Source: https:// | ||
| + | |||
| + | 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 | ||
| + | |||
| + | ~~~bash | ||
| + | ntpstat | ||
| + | ~~~ | ||
| + | |||
| + | | **Exit status** | **Error** | ||
| + | | --------------- | ----------------------------------------------------------------------- | | ||
| + | | 0 | Clock is synchronised. | ||
| + | | 1 | Clock is not synchronised. | ||
| + | | 2 | If clock state is indeterminant, | ||
| + | |||
| + | |||
| + | ### ntpq | ||
| + | |||
| + | |||
| + | ~~~bash | ||
| + | ntpq -pn | ||
| + | ~~~ | ||
| + | |||
| + | Source : https:// | ||
| + | |||
| + | ~~~ | ||
| + | # ntpq -p | ||
| + | |||
| + | remote | ||
| + | =========================================== | ||
| + | europium.canoni 193.79.237.14 | ||
| + | horlogegps.rese 10.3.128.189 | ||
| + | kontir.mkc.fr | ||
| + | dnscache-london 140.203.16.5 | ||
| + | ~~~ | ||
| + | |||
| + | 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, | ||
| + | |||
| + | Une synchronisation correcte implique une valeur de « delay » et de « offset » non nulle, et de « jitter » inférieure à 100 | ||
| + | |||
| + | Resynchroniser | ||
| + | ~~~bash | ||
| + | sudo service ntp stop | ||
| + | sudo ntpd -gq | ||
| + | sudo service ntp start | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### SystemD - timedatectl | ||
| + | |||
| + | ~~~bash | ||
| + | | ||
| + | ~~~ | ||
| + | ~~~ | ||
| + | NTP enabled: yes | ||
| + | NTP synchronized: | ||
| + | ~~~ | ||
| + | |||
| + | ### Chrony - chronyc | ||
| + | |||
| + | ~~~bash | ||
| + | chronyc tracking | ||
| + | chronyc sources | ||
| + | chronyc sourcestats | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ## Autres | ||
| + | |||
| + | ### Timesyncd | ||
| + | |||
| + | ''/ | ||
| + | ~~~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 | ||
| + | ~~~ | ||
| + | |||
| + | Avant de faire une manip | ||
| + | ~~~bash | ||
| + | adjtimex -u -l=/ | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Voir http:// | ||
| + | |||
| + | ### clocksource | ||
| + | |||
| + | Oracle recommande de changer le "clock source" | ||
| + | |||
| + | ~~~ | ||
| + | # cat / | ||
| + | xen tsc acpi_pm | ||
| + | ~~~ | ||
| + | |||
| + | If the tsc clock source is available, then set tsc as the current clock source. | ||
| + | ~~~bash | ||
| + | echo " | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Using any text editor, append the clocksource directive to the GRUB_CMDLINE_LINUX line in the / | ||
| + | |||
| + | ''/ | ||
| + | ~~~bash | ||
| + | GRUB_CMDLINE_LINUX=" | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | ## Falsifier la date et l' | ||
| + | |||
| + | ~~~bash | ||
| + | faketime 2016-01-01 gpg --list-keys | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Pb | ||
| + | |||
| + | ### Pb fichier de conf ignoré à cause d'une conf via DHCP | ||
| + | |||
| + | Voir aussi : https:// | ||
| + | |||
| + | `/ | ||
| + | ~~~bash | ||
| + | ps -ef | grep ntp | ||
| + | ~~~ | ||
| + | |||
| + | ~~~ | ||
| + | ntp | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | rm / | ||
| + | systemctl restart ntp | ||
| + | ~~~ | ||
| + | |||
| + | ou sur Redhat | ||
| + | ~~~bash | ||
| + | rm / | ||
| + | systemctl restart chronyd.service | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### Pb - the NTP socket is in use, exiting | ||
| + | |||
| + | |||
| + | #### Solution 1 | ||
| + | ~~~bash | ||
| + | ntpdate -u pool.ntp.org | ||
| + | ~~~ | ||
| + | |||
| + | #### Solution 2 | ||
| + | |||
| + | Arrêt du service (pour libérer le socket réseau UDP) puis | ||
| + | ~~~bash | ||
| + | ntpdate -u pool.ntp.org | ||
| + | ~~~ | ||
| + | |||
| + | http:// | ||
| + | ntptrace | ||
| + | |||
| + | |||
| + | ### Pb avec VirtualBox | ||
| + | |||
| + | '' | ||
| + | |||
| + | ~~~ | ||
| + | # systemctl status systemd-timesyncd | ||
| + | ● systemd-timesyncd.service - Network Time Synchronization | ||
| + | | ||
| + | Drop-In: / | ||
| + | | ||
| + | | ||
| + | Condition: start condition failed at Fri 2019-10-11 11:37:16 CEST; 5min ago | ||
| + | | ||
| + | Docs: man: | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | #### Solution | ||
| + | |||
| + | ''/ | ||
| + | |||
| + | ~~~ini | ||
| + | [Unit] | ||
| + | # do not run timesyncd if we have another NTP daemon installed | ||
| + | # | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | systemctl daemon-reload | ||
| + | systemctl restart systemd-timesyncd | ||
| + | ~~~ | ||
| + | |||
| + | |||
