RHEL、CentOSのタイムゾーン設定(timedatectl)
Linuxを使っていると、タイムゾーンでよく苦しめられます。
RHEL/CentOS7系ですが、タイムゾーンの設定は、/etc/localtimeがどのタイムゾーンファイルへのシンボリックリンクになっているかで決まります。
ll /etc/localtime
lrwxrwxrwx 1 root root 32 10月 8 15:52 /etc/localtime -> ../usr/share/zoneinfo/Asia/Tokyo
これだと日本標準時ですね。これを変えるのに、いちいちシンボリックリンクを付け替えしなくてもいいコマンドがあることを先日知りました。
まずは、今のタイムゾーンを確認するコマンド。
[root@rhel80 ~]# timedatectl status
Local time: 火 2019-10-08 16:05:15 JST
Universal time: 火 2019-10-08 07:05:15 UTC
RTC time: 火 2019-10-08 07:05:14
Time zone: Asia/Tokyo (JST, +0900)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
[root@rhel80 ~]# ll /etc/localtime
lrwxrwxrwx 1 root root 32 10月 8 15:52 /etc/localtime -> ../usr/share/zoneinfo/Asia/Tokyo
では、これをUTCにしてみましょう。
[root@rhel80 ~]# timedatectl set-timezone UTC
[root@rhel80 ~]# timedatectl status
Local time: 火 2019-10-08 07:11:01 UTC
Universal time: 火 2019-10-08 07:11:01 UTC
RTC time: 火 2019-10-08 07:11:00
Time zone: UTC (UTC, +0000)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
変わりましたー。
内部的にはシンボリックリンクを付け替えてるだけだと思いますが、何気に便利ですね。
ではでは。今日はこの辺で。