Photon Linux での NTP サーバとの時刻同期。(systemd-timesyncd / ntpd)

Photon Linux での NTP サーバとの時刻同期。(systemd-timesyncd / ntpd)

今回は、VMware Photon Linux の時刻同期の設定をしてみます。

またまた「Photon Full OS (All) 」でインストールした Photon を使用しています。


Photon Linux は systemd 管理なので、

systemd-timesyncd で時刻同期の設定をしてみます。

そして、ntpd での時刻同期も設定してみます。


Photon Linux 1.0 TP1 の初期状態はこんな感じです。

「NTP enabled」 は yes ですが、

「NTP synchronized」 は no になっています。

root [ ~ ]# cat /etc/photon-release

VMware Photon Linux 1.0 TP1

root [ ~ ]# timedatectl

      Local time: Mon 2015-06-01 14:19:57 UTC

  Universal time: Mon 2015-06-01 14:19:57 UTC

        RTC time: Mon 2015-06-01 14:19:57

       Time zone: UTC (UTC, +0000)

     NTP enabled: yes

NTP synchronized: no

RTC in local TZ: no

      DST active: n/a

systemd-timesyncd の設定。

まず、systemd-timesyncd の設定をしてみます。

もともと、systemd では、systemd-timesyncd の Unit は有効(enabled) になっています。

しかし、ConditionVirtualization=no という設定のせいか

デフォルトでは、仮想化環境上だと時刻同期していません。

※今回の Photon は、ESXi の VM です。

root [ ~ ]# systemctl status systemd-timesyncd.service

● systemd-timesyncd.service - Network Time Synchronization

   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled)

   Active: inactive (dead)

           start condition failed at Mon 2015-06-01 14:12:38 UTC; 11min ago

           ConditionVirtualization=no was not met

     Docs: man:systemd-timesyncd.service(8)

Jun 01 14:12:38 photon03 systemd[1]: Started Network Time Synchronizationsystemd-timesyncd.service


そこで、systemd-timesyncd のデフォルトの設定ファイルである

systemd-timesyncd.service を、

/lib/systemd/system/ から /etc/systemd/system/ 配下にコピーして設定を変更してみます。


デフォルトから変更したのは、下記のみ(12行目)です。

ConditionVirtualization=no

ConditionVirtualization=yes

root [ ~ ]# cp -p /lib/systemd/system/systemd-timesyncd.service /etc/systemd/system/

root [ ~ ]# vi /etc/systemd/system/systemd-timesyncd.service

root [ ~ ]# diff /lib/systemd/system/systemd-timesyncd.service /etc/systemd/system/systemd-timesyncd.service

12c12

< ConditionVirtualization=no

---

> ConditionVirtualization=yes

参照する NTP サーバのアドレスを指定するため、

timesyncd.conf も編集します。

root [ ~ ]# cp -p /etc/systemd/timesyncd.conf timesyncd.conf_bk

root [ ~ ]# vi /etc/systemd/timesyncd.conf

root [ ~ ]# cat /etc/systemd/timesyncd.conf

#  This file is part of systemd.

#

#  systemd is free software; you can redistribute it and/or modify it

#  under the terms of the GNU Lesser General Public License as published by

#  the Free Software Foundation; either version 2.1 of the License, or

#  (at your option) any later version.

#

# See timesyncd.conf(5) for details

[Time]

NTP=0.vmware.pool.ntp.org 1.vmware.pool.ntp.org 2.vmware.pool.ntp.org

#FallbackNTP=time1.google.com time2.google.com time3.google.com time4.google.com

編集したのは、11行目だけです。

「NTP=」のコメントアウトを外して、NTP サーバアドレスを追記しました。

root [ ~ ]# diff timesyncd.conf_bk /etc/systemd/timesyncd.conf

11c11

< #NTP=

---

> NTP=0.vmware.pool.ntp.org 1.vmware.pool.ntp.org 2.vmware.pool.ntp.org

root [ ~ ]#

新規作成した(設定変更した)設定ファイルにリンクを張りなおすため、

systemd-timesyncd.service を disable → enable します。

root [ ~ ]# systemctl disable systemd-timesyncd.service

Removed symlink /etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service.

root [ ~ ]# systemctl enable systemd-timesyncd.service

Created symlink from /etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service to /etc/systemd/system/systemd-timesyncd.service.

systemd-timesyncd.service を再起動します。

Active が「active (running)」となり、サービスが起動していることがわかります。

root [ ~ ]# systemctl restart systemd-timesyncd.service

root [ ~ ]# systemctl status systemd-timesyncd.service

● systemd-timesyncd.service - Network Time Synchronization

   Loaded: loaded (/etc/systemd/system/systemd-timesyncd.service; enabled)

   Active: active (running) since Mon 2015-06-01 14:40:44 UTC; 3s ago

     Docs: man:systemd-timesyncd.service(8)

Main PID: 334 (systemd-timesyn)

   Status: "Using Time Server 106.186.114.89:123 (0.vmware.pool.ntp.org)."

   CGroup: /system.slice/systemd-timesyncd.service

           mq334 /lib/systemd/systemd-timesyncd

Jun 01 14:40:44 photon03 systemd[1]: Started Network Time Synchronization.

Jun 01 14:40:44 photon03 systemd-timesyncd[334]: Using NTP server 106.186.114.89:123 (...).

Jun 01 14:40:44 photon03 systemd-timesyncd[334]: interval/delta/delay/jitter/drift 64s...pm

Hint: Some lines were ellipsized, use -l to show in full.

上記の status 確認でも表示されていますが、

journalctl でログ確認をしてみると、時刻同期をしている様子が見られます。

root [ ~ ]# journalctl -u systemd-timesyncd.service | tail -n 1

Jun 01 14:41:48 photon03 systemd-timesyncd[334]: interval/delta/delay/jitter/drift 128s/-0.000s/0.008s/0.000s/-1ppm

timedatectl の「NTP synchronized」も yes になりました。

root [ ~ ]# timedatectl

      Local time: Mon 2015-06-01 14:44:45 UTC

  Universal time: Mon 2015-06-01 14:44:45 UTC

        RTC time: Mon 2015-06-01 14:44:45

       Time zone: UTC (UTC, +0000)

     NTP enabled: yes

NTP synchronized: yes

RTC in local TZ: no

      DST active: n/a

ntpd の設定。

Photon には、ntpd もインストールされます。そこで、

systemd-timesyncd を停止して、ntpd でも時刻同期を設定してみます。

root [ ~ ]# rpm -q ntp

ntp-4.2.6p5-1.x86_64

まず、systemd-timesyncd を停止しておきます。

root [ ~ ]# timedatectl set-ntp no

root [ ~ ]# systemctl stop systemd-timesyncd.service

root [ ~ ]# systemctl disable systemd-timesyncd.service

root [ ~ ]# systemctl status systemd-timesyncd.service | head -n 3

● systemd-timesyncd.service - Network Time Synchronization

   Loaded: loaded (/etc/systemd/system/systemd-timesyncd.service; disabled)

   Active: inactive (dead)

ntpd の Unit ファイル /etc/systemd/system/ntpd.service を作成します。

root [ ~ ]# vi /etc/systemd/system/ntpd.service

root [ ~ ]# cat /etc/systemd/system/ntpd.service

[Unit]

Description=Network Time Service

After=network-online.target

[Service]

ExecStart=/usr/sbin/ntpd -u ntp:ntp

KillMode=process

Restart=always

PIDFile=/var/run/ntpd.pid

[Install]

WantedBy=multi-user.target

/etc/ntp.conf ファイルに、NTP サーバのアドレスを設定します。

root [ ~ ]# cp -p /etc/ntp.conf ntp.conf_bk

root [ ~ ]# vi /etc/ntp.conf

root [ ~ ]# cat /etc/ntp.conf

server 0.vmware.pool.ntp.org

server 1.vmware.pool.ntp.org

server 2.vmware.pool.ntp.org

driftfile /var/cache/ntp.drift

pidfile   /var/run/ntpd.pid


今回 編集したのは、NTP サーバのアドレスだけです。

root [ ~ ]# diff ntp.conf_bk /etc/ntp.conf

1,10c1,3

< # Asia

< server 0.asia.pool.ntp.org

< # Australia

< server 0.oceania.pool.ntp.org

< # Europe

< server 0.europe.pool.ntp.org

< # North America

< server 0.north-america.pool.ntp.org

< # South America

< server 2.south-america.pool.ntp.org

---

> server 0.vmware.pool.ntp.org

> server 1.vmware.pool.ntp.org

> server 2.vmware.pool.ntp.org

ntpd を有効化~起動します。

root [ ~ ]# systemctl enable ntpd.service

Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /etc/systemd/system/ntpd.service.

root [ ~ ]# systemctl start ntpd.service

root [ ~ ]# systemctl status ntpd.service

● ntpd.service - Network Time Service

   Loaded: loaded (/etc/systemd/system/ntpd.service; enabled)

   Active: active (running) since Mon 2015-06-01 15:05:33 UTC; 7s ago

Main PID: 469 (ntpd)

   CGroup: /system.slice/ntpd.service

           mq469 /usr/sbin/ntpd -u ntp:ntp

Jun 01 15:05:33 photon03 ntpd[469]: ntp_io: estimated max descriptors: 1024, ini...16

Jun 01 15:05:33 photon03 ntpd[469]: Listen and drop on 0 v4wildcard 0.0.0.0 UDP 123

Jun 01 15:05:33 photon03 ntpd[469]: Listen and drop on 1 v6wildcard :: UDP 123

Jun 01 15:05:33 photon03 ntpd[469]: Listen normally on 2 lo 127.0.0.1 UDP 123

Jun 01 15:05:33 photon03 ntpd[469]: Listen normally on 3 eth0 192.168.1.8 UDP 123

Jun 01 15:05:33 photon03 ntpd[469]: Listen normally on 4 lo ::1 UDP 123

Jun 01 15:05:33 photon03 ntpd[469]: Listen normally on 5 eth0 2408:210:a3c8:7000...23

Jun 01 15:05:33 photon03 ntpd[469]: Listen normally on 6 eth0 fe80::250:56ff:fea...23

Jun 01 15:05:33 photon03 ntpd[469]: peers refreshed

Jun 01 15:05:33 photon03 ntpd[469]: Listening on routing socket on fd #23 for in...es

Hint: Some lines were ellipsized, use -l to show in full.

時刻同期が開始されます。

root [ ~ ]# ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter

==============================================================================

7c2956c8.i-revo 131.112.125.48   2 u    2   64    7   30.411    7.755   8.316

x.ns.gin.ntt.ne 103.1.106.69     2 u    -   64    7   14.764    2.135   2.310

vps.jre655.com  10.84.87.146     2 u    1   64    7   15.498    1.946  12.851

しばらく待つと、ジョジョに同期され、NTP サーバの行頭に、* や + がつきます。

photon-ntpd.png

やっぱり、もっと近そうな NTP サーバを指定したほうがよかったかもしれません。

以上、Photon Linux の時刻同期設定でした。

Version history
Revision #:
1 of 1
Last update:
‎06-01-2015 09:28 AM
Updated by: