LoginSignup
29
30

More than 5 years have passed since last update.

CoreOS の時刻とタイムゾーンの設定

Last updated at Posted at 2014-09-02

CoreOS では NTP が利用され、クラスタ内のマシン全体で時刻が同期される。

NTP の設定

ntpd の状態確認

$ systemctl status ntpd

NTP サーバの変更

直接変更する

NTP サーバの変更は /etc/ntp.conf を編集する。しかしデフォルトだと /etc/ntp.conf/usr/share/ntp/ntp.conf のシンボリックリンクとなっているので、編集ができない。

core@core-01 ~ $ ls -l /etc/ntp.conf
lrwxrwxrwx 1 root root 23 Aug 29 08:20 /etc/ntp.conf -> /usr/share/ntp/ntp.conf

一旦 /etc/ntp.conf を消してしまって再度作成する

core@core-01 ~ $ sudo rm /etc/ntp.conf
core@core-01 ~ $ sudo vi /etc/ntp.conf

/etc/ntp.conf

# Common pool
ntp.nict.jp
ntp.jst.mfeed.ad.jp

# Warning: Using default NTP settings will leave your NTP
# server accessible to all hosts on the Internet.

# If you want to deny all machines (including your own)
# from accessing the NTP server, uncomment:
#restrict default ignore

# Default configuration:
# - Allow only time queries, at a limited rate, sending KoD when in excess.
# - Allow all local queries (IPv4, IPv6)
restrict default nomodify nopeer noquery limited kod
restrict 127.0.0.1
restrict [::1]
core@core-01 ~ $ sudo systemctl restart ntpd

NTP を有効にする

core@core-01 ~ $ sudo timedatectl set-ntp true
core@core-01 ~ $ timedatectl
      Local time: Tue 2014-09-02 22:25:55 JST
  Universal time: Tue 2014-09-02 13:25:55 UTC
        RTC time: Tue 2014-09-02 13:25:51
       Time zone: Asia/Tokyo (JST, +0900)
     NTP enabled: yes # -> yes になる
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

cloud-config 経由で設定する

#cloud-config

coreos:
  ...
write_files:
  - path: /etc/ntp.conf
    content: |
      # Common pool
      server 0.pool.ntp.org
      server 1.pool.ntp.org

      # - Allow only time queries, at a limited rate.
      # - Allow all local queries (IPv4, IPv6)
      restrict default nomodify nopeer noquery limited kod
      restrict 127.0.0.1
      restrict [::1]

CoreOS の推奨設定

よほど高い可用性を求められているのでなければ CoreOS はデフォルトの ntp.org のサーバ群を使うことを推奨している

server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server 3.pool.ntp.org

タイムゾーンの設定

現在のタイムゾーンを確認する

core@core-01 ~ $ timedatectl status
      Local time: Tue 2014-09-02 13:18:39 UTC
  Universal time: Tue 2014-09-02 13:18:39 UTC
        RTC time: Tue 2014-09-02 13:18:32
       Time zone: n/a (UTC, +0000)
     NTP enabled: no
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

コマンドからタイムゾーンを変更する

core@core-01 ~ $ timedatectl list-timezones | grep Tokyo
Asia/Tokyo
core@core-01 ~ $ sudo timedatectl set-timezone Asia/Tokyo
core@core-01 ~ $ timedatectl status
      Local time: Tue 2014-09-02 22:22:50 JST
  Universal time: Tue 2014-09-02 13:22:50 UTC
        RTC time: Tue 2014-09-02 13:22:48
       Time zone: Asia/Tokyo (JST, +0900)
     NTP enabled: no
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a
core@core-01 ~ $ date
Tue Sep  2 22:23:56 JST 2014

cloud-config から設定する

#cloud-config

coreos:
  units:
    - name: settimezone.service
      command: start
      content: |
        [Unit]
        Description=Set the timezone

        [Service]
        ExecStart=/usr/bin/timedatectl set-timezone UTC
        RemainAfterExit=yes
        Type=oneshot

CoreOS の推奨設定

UTC を使うのが推奨

$ sudo timedatectl set-timezone UTC

メモと感想

  • UTC 推奨とあるけどいまいち理由がちゃんとわかってない

  • cloud-config の yml ミスると設定まるっと全部効いてないことになる

write_files/etc/ntp.conf のインデントミスったら、etcd discovery も、 timezone の設定も何も反映されてなかった。

REF

29
30
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
29
30