NTP(Network Time Protocol)は、コンピュータに内蔵されているシステムクロックをネットワークを 介して正しく同期させるためのプロトコルです。活性・非活性、同期先サーバの変更を案内します。
時刻同期の状況を確認
インストール直後は、時刻同期はActiveになっています。
$ timedatectl status
Local time: Thu 2022-09-29 23:06:58 JST
Universal time: Thu 2022-09-29 14:06:58 UTC
RTC time: n/a
Time zone: Asia/Tokyo (JST, +0900)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
もし下記の赤文字のようにinactiveの時は、
$ timedatectl status
Local time: Mon 2023-11-06 00:28:27 JST
Universal time: Sun 2023-11-05 15:28:27 UTC
RTC time: n/a
Time zone: Asia/Tokyo (JST, +0900)
System clock synchronized: yes
NTP service: inactive
RTC in local TZ: no
下記コマンド有効化できます。
$ sudo timedatectl set-ntp true
$ timedatectl status
Local time: Mon 2023-11-06 00:31:41 JST
Universal time: Sun 2023-11-05 15:31:41 UTC
RTC time: n/a
Time zone: Asia/Tokyo (JST, +0900)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
時刻同期先サーバの変更
時刻同期先は、
$ sudo systemctl status systemd-timesyncd.service
● systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; preset: enabled)
Active: active (running) since Mon 2023-11-06 00:31:30 JST; 1min 53s ago
Docs: man:systemd-timesyncd.service(8)
Main PID: 776 (systemd-timesyn)
Status: "Contacted time server 162.159.200.1:123 (0.debian.pool.ntp.org)."
Tasks: 2 (limit: 765)
CPU: 215ms
CGroup: /system.slice/systemd-timesyncd.service
mq776 /lib/systemd/systemd-timesyncd
Nov 06 00:31:30 raspberrypi systemd[1]: Starting systemd-timesyncd.service - Network Time Synchronization...
Nov 06 00:31:30 raspberrypi systemd[1]: Started systemd-timesyncd.service - Network Time Synchronization.
Nov 06 00:31:30 raspberrypi systemd-timesyncd[776]: Contacted time server 162.159.200.1:123 (0.debian.pool.ntp.org).
Nov 06 00:31:30 raspberrypi systemd-timesyncd[776]: Initial clock synchronization to Mon 2023-11-06 00:31:30.456337 JST.
赤字の通りdebian.pool.ntp.org と同期をとっています。
この状態で特に問題はありませんが、同期先のサーバを変更する時は、下記を参考にしてください。
同期先のサーバの変更
私は、NICTおよびgoogleのサーバに同期させます。
$ sudo vi /etc/systemd/timesyncd.conf
ももぶろ
viの超簡単な使い方は、ここを見てね
ももぶろ
viの超簡単な使い方は、ここを見てね
[Time]
NTP=ntp.nict.jp time.google.com
FallbackNTP=0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org
#RootDistanceMaxSec=5
#PollIntervalMinSec=32
#PollIntervalMaxSec=2048
上記赤字の通りの設定をしています。
変更内容を反映して状態を確認
$ sudo systemctl restart systemd-timesyncd.service
$ sudo systemctl status systemd-timesyncd.service
● systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; preset: enabled)
Active: active (running) since Mon 2023-11-06 01:04:10 JST; 16s ago
Docs: man:systemd-timesyncd.service(8)
Main PID: 830 (systemd-timesyn)
Status: "Contacted time server 133.243.238.163:123 (ntp.nict.jp)."
Tasks: 2 (limit: 765)
CPU: 215ms
CGroup: /system.slice/systemd-timesyncd.service
mq830 /lib/systemd/systemd-timesyncd
Nov 06 01:04:10 raspberrypi systemd[1]: Starting systemd-timesyncd.service - Network Time Synchronization...
Nov 06 01:04:10 raspberrypi systemd[1]: Started systemd-timesyncd.service - Network Time Synchronization.
Nov 06 01:04:10 raspberrypi systemd-timesyncd[830]: Contacted time server 133.243.238.163:123 (ntp.nict.jp).
Nov 06 01:04:10 raspberrypi systemd-timesyncd[830]: Initial clock synchronization to Mon 2023-11-06 01:04:10.972210 JST.
赤字の通り ntp.nict.jp と同期しました。