Skip to Content
ドキュメントサーバー時刻同期 (クロニー)

時刻同期 (クロニー)

正確なシステム時間は、ログの関連付け、TLS 証明書の検証、データベースの一貫性、分散システムにとって不可欠です。 新しい Ubuntu 26.04 をインストールすると、Chrony がデフォルトのネットワーク時刻同期デーモンになります。

Chrony 対 systemd-timesyncd

Ubuntu には 2 つの時刻同期実装が同梱されています。それらがどのように関係しているかを理解することで間違いを避けることができます。

特徴systemd-timesyncdクロニー
役割軽量のSNTPクライアントフル機能の NTP クライアント/サーバー
26.04 デフォルトアップグレード/最小限のシステムのフォールバック新規インストール時のデフォルト
NTPサーバーとして機能しますいいえはい (他のホストに時間を提供できます)
断続的な接続/VMクロックのドリフト平均より良い
管理コマンドtimedatectlchronyc
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/24
sudo systemctl restart chrony # Open the NTP firewall port (UDP 123) sudo ufw allow 123/udp
Tip

長時間サスペンドした仮想マシンやラップトップは、クロック ドリフトが発生する傾向があります。 Chrony の makestep およびドリフト ファイル メカニズムは、大きなオフセットをより速く修正するため、timesyncd よりもこれらのシナリオに適しています。

Last updated on