Raspberry Pi の ntp 設定を変更する

小ネタです。調べ物をしてたら、 Raspberry Pi OS には標準で NTP サーバーの機能が埋め込まれており、 Debian の NTP サーバーにアクセスしているということでした。必ずしも変更する必要もないかもしれませんが、気になったので日本のサーバーに変更しました。

状態確認

● systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
  Drop-In: /usr/lib/systemd/system/systemd-timesyncd.service.d
           └─disable-with-time-daemon.conf
   Active: active (running) since Sun 2021-01-10 15:17:18 JST; 1 weeks 2 days ago
     Docs: man:systemd-timesyncd.service(8)
 Main PID: 309 (systemd-timesyn)
   Status: "Synchronized to time server for the first time [2001:19f0:200:144b::2000]:123 (2.debian.pool.ntp.org)."
    Tasks: 2 (limit: 4915)
   CGroup: /system.slice/systemd-timesyncd.service
           └─309 /lib/systemd/systemd-timesyncd

 1月 10 15:17:17 raspberrypi systemd[1]: Starting Network Time Synchronization...
 1月 10 15:17:18 raspberrypi systemd[1]: Started Network Time Synchronization.
 1月 10 15:18:07 raspberrypi systemd-timesyncd[309]: Synchronized to time server for the first time [2600:3c04::f03c:92ff:fe41:5a9c]:123 (2.deb
 1月 16 11:18:17 raspberrypi systemd-timesyncd[309]: Timed out waiting for reply from [2001:1620:2777:b::128]:123 (2.debian.pool.ntp.org).
 1月 16 11:18:18 raspberrypi systemd-timesyncd[309]: Synchronized to time server for the first time [2001:19f0:200:144b::2000]:123 (2.debian.po

これが、設定前の Network Time Synchronization System の設定です。 debian.pool.ntp.org に読みに行ってます。これを ntp.nict.jp に変えます。

設定変更

設定ファイルは /etc/systemd/timesyncd.conf です。任意のエディタで編集します。

#NTP=
 ↓
NTP=ntp.nict.jp

これで OK なんですが、これまで標準だった debian サーバーの設定が残ったままで、 nict.jp にアクセスするか不明なので、 Debian サーバーにアクセスしないようにします。といっても、コメントアウトされた 1 文から#を取り去るだけです。

#FallbackNTP=0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org
 ↓
FallbackNTP=0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org

これで設定はおしまいです。簡単ですなぁ。

再起動と確認

では、設定ファイルをセーブして、 Network Time Synchronization System を再起動します。そして、設定を確認します。

$ sudo systemctl restart systemd-timesyncd.service
$ sudo systemctl status systemd-timesyncd.service

2行目の status コマンドで、設定が上手くいっているか確認します。エラーが出ていなければ次のようなステータスが表示されると思います。

● systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
  Drop-In: /usr/lib/systemd/system/systemd-timesyncd.service.d
           └─disable-with-time-daemon.conf
   Active: active (running) since Tue 2021-01-19 20:42:16 JST; 18s ago
     Docs: man:systemd-timesyncd.service(8)
 Main PID: 30168 (systemd-timesyn)
   Status: "Synchronized to time server for the first time [2001:ce8:78::2]:123 (ntp.nict.jp)."
    Tasks: 2 (limit: 4915)
   CGroup: /system.slice/systemd-timesyncd.service
           └─30168 /lib/systemd/systemd-timesyncd

 1月 19 20:42:16 raspberrypi systemd[1]: Starting Network Time Synchronization...
 1月 19 20:42:16 raspberrypi systemd[1]: Started Network Time Synchronization.
 1月 19 20:42:16 raspberrypi systemd-timesyncd[30168]: Synchronized to time server for the first time [2001:ce8:78::2]:123 (ntp.nict.jp).

ちゃんと ntp.nict.jp から時間を読んでます。完成ですね。

まとめ

簡単な変更ですし、順番にやれば問題なるところはないはずです。 ntp サーバーの詳しいシステムに関してはよく分かってないのですが、遅延がなければより正しい時間を表示されるはずですよね。 Debian のサーバーがどこにあるのかわかりませんが、日本国内ではないと思います。多少の遅延が生じているのかもしれませんね。

絶対に直さなければならないと言うわけではありませんが、気になったので直してみました。

投稿者プロフィール

kaizawa
kaizawaブロガー
新潟県在住。1964年生まれ、東京オリンピックの年ですね。
突然燃え上がったり、鎮火したり興味の波が激しいので注意が必要です。
最新の投稿

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


Linux

前の記事

Wacthdog の設定