時刻同期 (クロニー)
正確なシステム時間は、ログの関連付け、TLS 証明書の検証、データベースの一貫性、分散システムにとって不可欠です。 新しい Ubuntu 26.04 をインストールすると、Chrony がデフォルトのネットワーク時刻同期デーモンになります。
Chrony 対 systemd-timesyncd
Ubuntu には 2 つの時刻同期実装が同梱されています。それらがどのように関係しているかを理解することで間違いを避けることができます。
| 特徴 | systemd-timesyncd | クロニー |
|---|---|---|
| 役割 | 軽量のSNTPクライアント | フル機能の NTP クライアント/サーバー |
| 26.04 デフォルト | アップグレード/最小限のシステムのフォールバック | 新規インストール時のデフォルト |
| NTPサーバーとして機能します | いいえ | はい (他のホストに時間を提供できます) |
| 断続的な接続/VMクロックのドリフト | 平均 | より良い |
| 管理コマンド | timedatectl | chronyc |
Note
2 つを同時に実行することはできません。 Chrony をインストールすると、systemd-timesyncd が自動的に無効になります。その時点で、timedatectl set-ntp true/false は実際の同期を制御しなくなりました。代わりに chronyc および systemctl ... chrony を使用してください。
現在の同期ステータスを確認する
# Overall time status
timedatectl
# Confirm which service is handling sync
systemctl status chrony
# If Chrony is not installed and timesyncd is in use
timedatectl show-timesyncインストールして有効にする
# A fresh 26.04 install usually has Chrony pre-installed and enabled
sudo apt update
sudo apt install chrony
# Enable and start immediately
sudo systemctl enable --now chronyアップストリームのタイムソースを構成する
メインの構成ファイルは /etc/chrony/chrony.conf です。
sudo nano /etc/chrony/chrony.conf一般的な構成:
# Use the Ubuntu NTP pool (default)
pool ntp.ubuntu.com iburst maxsources 4
# Record the offset of the system clock vs. the hardware clock to speed up future sync
driftfile /var/lib/chrony/chrony.drift
# Step the clock in one go when the initial offset is large (first 3 updates)
makestep 1.0 3編集後にサービスを再起動します。
sudo systemctl restart chrony一般的な chronyc コマンド
# View time sources and their status
chronyc sources -v
# View sync statistics (offset, jitter)
chronyc tracking
# View per-source measurement statistics
chronyc sourcestats
# Force an immediate step toward the server
sudo chronyc makestep
# Check whether the clock is synchronized
chronyc tracking | grep "Leap status"Chrony を NTP サーバーとして実行する
LAN 上の他のホストに時間を提供するには、chrony.conf のクライアント サブネットを許可します。
# Allow LAN clients to query this host's time
allow 192.168.1.0/24sudo systemctl restart chrony
# Open the NTP firewall port (UDP 123)
sudo ufw allow 123/udpTip
長時間サスペンドした仮想マシンやラップトップは、クロック ドリフトが発生する傾向があります。 Chrony の makestep およびドリフト ファイル メカニズムは、大きなオフセットをより速く修正するため、timesyncd よりもこれらのシナリオに適しています。
Last updated on