Ubuntu20.04.2のシステムタイムゾーンとNTPクライアントを設定する
はじめに
ubuntu初期イントール時、UTCになっているため、日本時刻と9時間ずれている。
タイムゾーンの変更と、NTPの設定を行い、システム時刻を変更する。
システムタイムゾーンの確認
以下のコマンドを実行し、現在のTimezoneを確認する。
1 2 3 4 5 6 7 8 9 |
ubuntu@ubuntu:/etc/netplan# timedatectl Local time: Mon 2021-04-19 08:43:48 UTC Universal time: Mon 2021-04-19 08:43:48 UTC RTC time: n/a Time zone: Etc/UTC (UTC, +0000) System clock synchronized: yes NTP service: active RTC in local TZ: no ubuntu@ubuntu:/etc/netplan# |
タイムゾーンがUTCになっていることが確認出来た。
システムタイムゾーンの変更
タイムゾーンのリストから、設定値を抽出し、日本時間に変更する。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#タイムゾーンの一覧から設定を調べる root@ubuntu:~# timedatectl list-timezones | grep Tokyo Asia/Tokyo #タイムゾーンを設定 root@ubuntu:~# timedatectl set-timezone Asia/Tokyo #タイムゾーンの確認 root@ubuntu:~# timedatectl Local time: Mon 2021-04-19 18:36:09 JST Universal time: Mon 2021-04-19 09:36:09 UTC RTC time: Mon 2021-04-19 09:36:10 Time zone: Asia/Tokyo (JST, +0900) System clock synchronized: yes NTP service: active RTC in local TZ: no root@ubuntu:~# |
以上で、タイムゾーンの変更が完了
NTPクライアントの設定
NTPサービスの確認
サービスが無効な場合は、有効にする。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
root@ubuntu:~# systemctl status systemd-timesyncd.service ● systemd-timesyncd.service - Network Time Synchronization Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2021-04-19 03:02:55 UTC; 8h ago Docs: man:systemd-timesyncd.service(8) Main PID: 1572 (systemd-timesyn) Status: "Initial synchronization to time server 91.189.94.4:123 (ntp.ubuntu.com)." Tasks: 2 (limit: 9257) CGroup: /system.slice/systemd-timesyncd.service mq1572 /lib/systemd/systemd-timesyncd Mar 17 21:36:12 ubuntu systemd[1]: Starting Network Time Synchronization... Mar 17 21:36:12 ubuntu systemd-timesyncd[1572]: System clock time unset or jumped backwards, restoring from recorded timestamp: Mon 2021-04-19 03:02:55 UTC Apr 19 03:02:55 ubuntu systemd[1]: Started Network Time Synchronization. Apr 19 03:03:04 ubuntu systemd-timesyncd[1572]: Network configuration changed, trying to establish connection. Apr 19 03:03:05 ubuntu systemd-timesyncd[1572]: Network configuration changed, trying to establish connection. Apr 19 03:03:08 ubuntu systemd-timesyncd[1572]: Network configuration changed, trying to establish connection. Apr 19 06:54:35 ubuntu systemd-timesyncd[1572]: Initial synchronization to time server 91.189.94.4:123 (ntp.ubuntu.com). root@ubuntu:~# |
上記は既に有効化されているが、サービスが停止していた場合、有効にし、自動起動も設定する。
1 2 3 4 5 |
# サービスの開始 systemctl start systemd-timesyncd.service # 自動起動 systemctl enable systemd-timesyncd.service |
NTPサーバの設定
同期するNTPサーバを設定する。今回は、日本標準時グループを設定する
1 2 3 |
root@ubuntu:~# vi /etc/systemd/timesyncd.conf # 最終行にNTPサーバーを追記 NTP=ntp.nict.jp |
NTP同期の確認
NTP同期の確認をする。まだサービスを再起動していないので、旧設定での確認が出来る。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
root@ubuntu:~# timedatectl timesync-status Server: 2001:67c:1560:8003::c8 (ntp.ubuntu.com) Poll interval: 8min 32s (min: 32s; max 34min 8s) Leap: normal Version: 4 Stratum: 2 Reference: 11FD22FD Precision: 1us (-23) Root distance: 20.545ms (max: 5s) Offset: -20.327ms Delay: 238.559ms Jitter: 8.322ms Packet count: 4 root@ubuntu:~# |
NTPサービスを再起動して、同期を確認する。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
root@ubuntu:~# systemctl restart systemd-timesyncd.service root@ubuntu:~# timedatectl timesync-status Server: 2001:df0:232:eea0::fff4 (ntp.nict.jp) Poll interval: 4min 16s (min: 32s; max 34min 8s) Leap: normal Version: 4 Stratum: 1 Reference: NICT Precision: 1us (-20) Root distance: 0 (max: 5s) Offset: +21.339ms Delay: 5.683ms Jitter: 19.933ms Packet count: 3 Frequency: -141.224ppm root@ubuntu:~# |