Ubuntu Server/CentOSの初期設定 時刻合わせ編

スポンサーリンク

前回の記事でUbuntu Server 20.04.2 LTSをインストールしました。

今回は初期設定をしていきたいと思います。

 

 

スポンサーリンク

時刻設定

 

timedatectlコマンドを実行してみましょう。
現在、9:40なのですが、こんな感じで表示されています。

user01@ubuntuserver01:~$ timedatectl
Local time: Mon 2021-03-29 00:40:25 UTC
Universal time: Mon 2021-03-29 00:40:25 UTC
RTC time: Mon 2021-03-29 00:40:25
Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
user01@ubuntuserver01:~$

初期設定をしてないと協定世界時 (UTC)で表示されちゃうんですよね。

日本時間から9時間引いた時間だったりします。

これをタイムロケールを変更することで日本時間に合わせるようにします。

「/etc/localtime」に「/usr/share/zoneinfo/Etc/UTC」へのシンボリックが設定されているので、
それを変更します。

現時点の設定確認

user01@ubuntuserver01:~$ ls -l /etc/localtime
lrwxrwxrwx 1 root root 27 Feb 1 17:24 /etc/localtime -> /usr/share/zoneinfo/Etc/UTC

 

変更

user01@ubuntuserver01:~$ sudo ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

 

変更の確認

user01@ubuntuserver01:~$ ls -l /etc/localtime
lrwxrwxrwx 1 root root 30 Mar 29 09:46 /etc/localtime -> /usr/share/zoneinfo/Asia/Tokyo
user01@ubuntuserver01:~$ timedatectl
Local time: Mon 2021-03-29 09:48:19 JST
Universal time: Mon 2021-03-29 00:48:19 UTC
RTC time: Mon 2021-03-29 00:48:19
Time zone: Asia/Tokyo (JST, +0900)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no

オプションの意味はこんな感じ
-s シンボリックリンクを設定
-f 同じ名前のファイルがあっても強制的に設定

 

※なお、NTPによる設定でchronyを使う場合は、chronyをインストールします。
sudo apt install chrony

以上、時刻合わせでした。

コマンド実行例は Ubuntu Server 20.04.2 LTSになります。