LoginSignup
1
2

More than 5 years have passed since last update.

RHEL7の/etc/localtimeのリンク先が変わっちゃう問題

Last updated at Posted at 2017-06-01

結論

タイムゾーンを変更する時は、timedatectlを使いましょう
/etc/localtimeにリンク貼っちゃいかん

対象環境

RHEL7
CentOS7
on ESXi

問題

最初は下記を設定してたのに、

# ll /etc/localtime
lrwxrwxrwx 1 root root 25  6月  1 17:55 /etc/localtime -> /usr/share/zoneinfo/Japan

VMでテンプレートから上げ直すと下記のようになってた

# ll /etc/localtime
lrwxrwxrwx 1 root root 30  5月 30 17:33 /etc/localtime -> /usr/share/zoneinfo/Asia/Tokyo

原因

1. そもそもタイムゾーンにJapanがない

下記のようにタイムゾーンのリストにAsia/Tokyoはあるが、Japanはなかった

# timedatectl list-timezones | grep Tokyo
Asia/Tokyo
# timedatectl list-timezones | grep Japan
# 

2. 設定方法が違う

設定を下記のようにしたが、テンプレートから起動した際に、glibcが更新された時に/etc/localtimeが上書きされた
多分、JapanないからTokyoに上書きされたっぽい
リンクを貼ってゾーンを変更するやり方は推奨されていない

# ln -sf /usr/share/zoneinfo/Japan /etc/localtime

対策

timedatectlでゾーン変更を行う

事前確認

現在のゾーン確認

# timedatectl | grep zone
       Time zone: Japan (JST, +0900)

リンク先確認

# ls -l /etc/localtime
lrwxrwxrwx. 1 root root 25  4月 10 15:53 /etc/localtime -> /usr/share/zoneinfo/Japan

ゾーンリストにあるよね確認

# timedatectl list-timezones | grep Asia/Tokyo
Asia/Tokyo

ゾーン設定

# timedatectl set-timezone Asia/Tokyo

事後確認

現在のゾーン確認

# timedatectl | grep zone
       Time zone: Japan (JST, +0900)

リンク先確認

# ls -l /etc/localtime
lrwxrwxrwx. 1 root root 25  4月 10 15:53 /etc/localtime -> /usr/share/zoneinfo/Japan

参考

  1. glibcを更新しても大丈夫な「正しい」タイムゾーンの設定方法 http://d.hatena.ne.jp/nekoruri/20150130/glibclocaltime
  2. 日付と時刻の設定 https://access.redhat.com/documentation/ja-JP/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/chap-Configuring_the_Date_and_Time.html#sect-Configuring_the_Date_and_Time-timedatectl-Time_Zone
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2