tech:ntp_temps_horloge_heure
Différences
Ci-dessous, les différences entre deux révisions de la page.
| 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.1 | tech:ntp_temps_horloge_heure [2025/10/24 09:49] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| {{tag> | {{tag> | ||
| - | = 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:// | + | * Film [Quels temps font-ils ?](http:// |
| - | * [[https:// | + | * https:// |
| * http:// | * http:// | ||
| * Si pb de flux réseau voir [[tunnel_ssh_udp_forward]] | * Si pb de flux réseau voir [[tunnel_ssh_udp_forward]] | ||
| + | * https:// | ||
| + | * / | ||
| + | * '' | ||
| + | * https:// | ||
| - | == Configurer | + | ## Configurer |
| - | === Configurer via Systemd | + | ### Configurer via Systemd |
| - | <code ini / | + | '' |
| + | ~~~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 | ||
| - | </ | + | ~~~ |
| - | < | + | ~~~bash |
| timedatectl set-ntp true | timedatectl set-ntp true | ||
| - | </ | + | ~~~ |
| Diag | Diag | ||
| - | < | + | ~~~bash |
| systemctl restart systemd-timesyncd | systemctl restart systemd-timesyncd | ||
| systemctl status systemd-timesyncd | systemctl status systemd-timesyncd | ||
| - | </ | + | ~~~ |
| - | === Configurer via Chrony | + | |
| + | ### Configurer via Chrony | ||
| TODO | TODO | ||
| - | === Configurer via NTP | ||
| - | < | + | ### Configurer via NTP |
| + | |||
| + | ~~~bash | ||
| aptitude install ntp | aptitude install ntp | ||
| - | </ | + | ~~~ |
| 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 - / | + | |
| + | '' | ||
| + | ~~~ | ||
| # 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 | ||
| - | </ | + | ~~~ |
| - | === Configurer via ntpdate | + | #### 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 | aptitude install ntpdate | ||
| - | </ | + | ~~~ |
| - | Utilisation manuel | + | |
| - | < | + | Utilisation manuel |
| + | ~~~bash | ||
| / | / | ||
| - | </ | + | ~~~ |
| Automatisation | Automatisation | ||
| - | < | + | ~~~bash |
| crontab -e | crontab -e | ||
| - | </ | + | ~~~ |
| Ajouter la ligne suivante: | Ajouter la ligne suivante: | ||
| - | <code -> | + | ~~~ |
| 0 3 * * * root / | 0 3 * * * root / | ||
| - | </ | + | ~~~ |
| Tester / simuler / lecture seul / dry-run | Tester / simuler / lecture seul / dry-run | ||
| - | < | + | ~~~bash |
| ntpdate -q pool.ntp.org | ntpdate -q pool.ntp.org | ||
| - | </ | + | ~~~ |
| - | === | + | |
| + | #### Autres | ||
| + | |||
| + | ''/ | ||
| + | |||
| + | ~~~bash | ||
| + | SYNC_HWCLOCK=yes | ||
| + | ~~~ | ||
| + | |||
| + | This is an option to ntpdate | ||
| + | |||
| + | |||
| + | ### | ||
| Afficher la date et l’heure | Afficher la date et l’heure | ||
| - | < | + | ~~~bash |
| date | date | ||
| - | </ | + | ~~~ |
| 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 | ||
| - | < | + | ~~~bash |
| hwclock | hwclock | ||
| - | </ | + | ~~~ |
| Commande pour que le BIOS puisse utiliser l’heure du système | Commande pour que le BIOS puisse utiliser l’heure du système | ||
| - | < | + | ~~~bash |
| hwclock --systohc --utc | hwclock --systohc --utc | ||
| - | </ | + | ~~~ |
| Comparaison du temps système et le BIOS | Comparaison du temps système et le BIOS | ||
| - | < | + | ~~~bash |
| date | date | ||
| hwclock | hwclock | ||
| - | </ | + | ~~~ |
| Vérification dans le fichier | Vérification dans le fichier | ||
| - | <code ini / | + | '' |
| + | ~~~bash | ||
| UTC=true | UTC=true | ||
| - | </ | + | ~~~ |
| - | == Vérifier | + | ## Vérifier |
| Source: https:// | Source: https:// | ||
| Ligne 138: | Ligne 206: | ||
| - | === ntpstat | + | ### ntpstat |
| - | < | + | ~~~bash |
| ntpstat | ntpstat | ||
| - | </ | + | ~~~ |
| - | | **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, | | 2 | If clock state is indeterminant, | ||
| - | === ntpq | ||
| + | ### ntpq | ||
| - | < | + | |
| + | ~~~bash | ||
| ntpq -pn | ntpq -pn | ||
| - | </ | + | ~~~ |
| Source : https:// | Source : https:// | ||
| - | <code -> | + | ~~~ |
| # ntpq -p | # ntpq -p | ||
| Ligne 167: | Ligne 237: | ||
| kontir.mkc.fr | kontir.mkc.fr | ||
| dnscache-london 140.203.16.5 | 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 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, | ||
| Ligne 174: | Ligne 244: | ||
| Resynchroniser | Resynchroniser | ||
| - | < | + | ~~~bash |
| sudo service ntp stop | sudo service ntp stop | ||
| sudo ntpd -gq | sudo ntpd -gq | ||
| sudo service ntp start | sudo service ntp start | ||
| - | </ | + | ~~~ |
| - | === SystemD - timedatectl | + | |
| - | < | + | |
| + | ### SystemD - timedatectl | ||
| + | |||
| + | ~~~bash | ||
| | | ||
| - | </ | + | ~~~ |
| - | <code -> | + | ~~~ |
| NTP enabled: yes | NTP enabled: yes | ||
| NTP synchronized: | NTP synchronized: | ||
| - | </ | + | ~~~ |
| - | === Chrony - chronyc | + | ### Chrony - chronyc |
| - | < | + | ~~~bash |
| chronyc tracking | chronyc tracking | ||
| chronyc sources | chronyc sources | ||
| chronyc sourcestats | chronyc sourcestats | ||
| - | </ | + | ~~~ |
| Ligne 201: | Ligne 273: | ||
| - | == Autres | + | ## 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 | apt-get install adjtimex | ||
| - | </ | + | ~~~ |
| Avant de faire une manip | Avant de faire une manip | ||
| - | < | + | ~~~bash |
| adjtimex -u -l=/ | adjtimex -u -l=/ | ||
| - | </ | + | ~~~ |
| Voir http:// | Voir http:// | ||
| - | === clocksource | + | ### clocksource |
| Oracle recommande de changer le "clock source" | Oracle recommande de changer le "clock source" | ||
| - | <code -> | + | ~~~ |
| # cat / | # cat / | ||
| xen tsc acpi_pm | xen tsc acpi_pm | ||
| - | </ | + | ~~~ |
| 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. | ||
| - | < | + | ~~~bash |
| echo " | echo " | ||
| - | </ | + | ~~~ |
| Using any text editor, append the clocksource directive to the GRUB_CMDLINE_LINUX line in the / | Using any text editor, append the clocksource directive to the GRUB_CMDLINE_LINUX line in the / | ||
| - | <code bash / | + | |
| + | '' | ||
| + | ~~~bash | ||
| GRUB_CMDLINE_LINUX=" | GRUB_CMDLINE_LINUX=" | ||
| - | </ | + | ~~~ |
| - | == Falsifier la date et l' | + | ## Falsifier la date et l' |
| - | < | + | ~~~bash |
| faketime 2016-01-01 gpg --list-keys | faketime 2016-01-01 gpg --list-keys | ||
| - | </ | + | ~~~ |
| - | == 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:// | Voir aussi : https:// | ||
| Ligne 252: | Ligne 343: | ||
| ''/ | ''/ | ||
| - | < | + | ~~~bash |
| ps -ef |grep ntp | ps -ef |grep ntp | ||
| - | </ | + | ~~~ |
| - | <code -> | + | ~~~ |
| ntp | ntp | ||
| - | </ | + | ~~~ |
| - | < | + | ~~~bash |
| rm / | rm / | ||
| systemctl restart ntp | systemctl restart ntp | ||
| - | </ | + | ~~~ |
| ou sur Redhat | ou sur Redhat | ||
| - | < | + | ~~~bash |
| rm / | rm / | ||
| systemctl restart chronyd.service | systemctl restart chronyd.service | ||
| - | </ | + | ~~~ |
| - | === Pb - the NTP socket is in use, exiting | ||
| + | ### Pb - the NTP socket is in use, exiting | ||
| - | ==== Solution 1 | + | |
| - | < | + | #### Solution 1 |
| + | ~~~bash | ||
| ntpdate -u pool.ntp.org | ntpdate -u pool.ntp.org | ||
| - | </ | + | ~~~ |
| - | ==== 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 | ||
| - | < | + | ~~~bash |
| ntpdate -u pool.ntp.org | ntpdate -u pool.ntp.org | ||
| - | </ | + | ~~~ |
| - | [[http:// | + | http:// |
| - | ntptrace]] | + | ntptrace |
| - | === Pb avec VirtualBox | + | ### Pb avec VirtualBox |
| '' | '' | ||
| - | <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: | ||
| | | ||
| Docs: man: | Docs: man: | ||
| - | </ | + | ~~~ |
| - | ==== Solution | + | |
| + | #### Solution | ||
| - | <code ini / | + | '' |
| + | |||
| + | ~~~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 | ||
| # | # | ||
| - | </ | + | ~~~ |
| - | < | + | ~~~bash |
| systemctl daemon-reload | systemctl daemon-reload | ||
| systemctl restart systemd-timesyncd | systemctl restart systemd-timesyncd | ||
| - | </ | + | ~~~ |
tech/ntp_temps_horloge_heure.1742825205.txt.gz · Dernière modification : de 127.0.0.1
