【CenotOS8.2】timezoneとlocaleを変更して日本時間(JST)と日本語表示されるようにする

CentOS6とかのときと違う方法で設定できるようだったのでやってみました。

環境

$ cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)

参考

CentOS 8 : 日本語環境にする : Server World
CentOS 8 日本語環境にする

タイムゾーン変更

dateコマンドを使った際にJSTで表示されるようにします。

タイムゾーン確認(LocalがUTCになっている)

$ timedatectl
               Local time: Thu 2020-09-24 01:15:20 UTC
           Universal time: Thu 2020-09-24 01:15:20 UTC
                 RTC time: Thu 2020-09-24 01:11:51
                Time zone: UTC (UTC, +0000)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: yes

Warning: The system is configured to read the RTC time in the local time zone.
         This mode cannot be fully supported. It will create various problems
         with time zone changes and daylight saving time adjustments. The RTC
         time is never updated, it relies on external facilities to maintain it.
         If at all possible, use RTC in UTC by calling
         'timedatectl set-local-rtc 0'.

使えるタイムゾーンにAsia/Tokyoがあるか確認

$ timedatectl list-timezones | grep Tokyo
Asia/Tokyo

Asia/Tokyoに設定

$ sudo timedatectl set-timezone Asia/Tokyo
$ date
Thu Sep 24 10:16:45 JST 2020
$ timedatectl
               Local time: Thu 2020-09-24 10:16:57 JST
           Universal time: Thu 2020-09-24 01:16:57 UTC
                 RTC time: Thu 2020-09-24 10:16:57
                Time zone: Asia/Tokyo (JST, +0900)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: yes

日本語化する

locale(地域)を日本にするとコマンドの実行結果とかが日本語で表示されるのでやってみます。

現在のlocaleを確認

$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
$ localectl
   System Locale: LANG=en_US.UTF-8
       VC Keymap: us
      X11 Layout: n/a
[bash]

使えるlocleを確認
[bash]
$ localectl list-locales | grep -i ja
[bash]

日本のlocaleが入っていないようなので言語パックをインストール
[bash]
$ sudo dnf -y install langpacks-ja
$ localectl list-locales | grep -i ja
ja_JP.eucjp
ja_JP.utf8

日本語localeのインストールが確認できたので設定

$ sudo localectl set-locale LANG=ja_JP.utf8

date関数を実行、設定しただけでは反映されないらしい。

$ date
Thu Sep 24 10:30:37 JST 2020
[bash]

設定を反映してもう一度dateコマンドを実行すると、日本的な表現で日本時間(JST)が表示される
[bash]
$ source /etc/locale.conf
$ date
2020年  9月 24日 木曜日 10:30:49 JST

おわり。