時刻同期化設定の点検
    • PDF

    時刻同期化設定の点検

    • PDF

    Article Summary

    VPC環境で利用できます。

    NAVERクラウドプラットフォームでは時刻同期化のための NTPサーバを提供します。時刻同期化設定はシステムの運用と管理に重要な影響を及ぼし、セキュリティ、ネットワーク通信、データの正確性などと密接な関係があります。なるべく周期的な1回限りの時刻同期化よりは、持続的に時刻を同期するデーモンの使用をお勧めします。

    CentOS, Rocky Linux

    NAVERクラウドプラットフォームで提供している RedHat系の OSで NTP設定値とファイルを点検してください。

    参考

    CentOS 7と Rocky Linux 8を対象に説明します。

    1. chronyインストールおよび動作を確認します。

      • CentOS 7
        [root@centos7 ~]# rpm -qa | grep chrony
        chrony-3.4-1.el7.x86_64
        
        [root@centos7 ~]# ps -ef|grep chronyd | grep -v grep 
        chrony     497     1  0 Mar27 ?        00:00:05 /usr/sbin/chronyd
        
      • Rocky Linux 8
        [root@rockylinux8 ~]# rpm -qa | grep chrony
        chrony-4.1-1.el8.rocky.0.1.x86_64
        
        [root@rockylinux8 ~]# ps -ef | grep chronyd | grep -v grep
        chrony       725       1  0 Jul25 ?        00:00:05 /usr/sbin/chronyd
        
    2. DHCPから取得した NAVERクラウドプラットフォームの NTP設定値を確認します。VPC環境で提供される NTPサーバの IPアドレスは169.254.169.123169.254.169.124です。

      [root@centos7 ~]# cat /var/lib/dhclient/chrony.servers.eth0
      169.254.169.123 iburst
      169.254.169.124 iburst
      
      • 上記のパスに169.254.169.123169.254.169.124が存在しない場合は、以下のように直接 NTP設定値を追加して対応します。
        [root@centos7 ~]# cat /etc/chrony.conf
        # Use public servers from the pool.ntp.org project.
        # Please consider joining the pool (http://www.pool.ntp.org/join.html).
        #server 0.centos.pool.ntp.org iburst
        #server 1.centos.pool.ntp.org iburst
        #server 2.centos.pool.ntp.org iburst
        #server 3.centos.pool.ntp.org iburst
        server 169.254.169.123
        server 169.254.169.124
        
        ... 省略...
        
        [root@centos7 ~]# systemctl restart chronyd.service
        
        [root@centos7 ~]# chronyc sources
        210 Number of sources = 2
        MS Name/IP address         Stratum Poll Reach LastRx Last sample              
        ===============================================================================
        ^? 169.254.169.123               3   6     3     6  -1689us[-1689us] +/-   48ms
        ^? 169.254.169.124               3   6     3     6  -1437us[-1437us] +/-   38ms
        
    3. timedatectl コマンドで時刻同期化の状態を確認します。

      • NTP synchronized 値、または System clock synchronized 値が yesになると同期化が正常に行われた状態です。
      • CentOS 7
        [root@centos7 ~]# timedatectl
                        Local time: Fri 2023-08-18 13:57:57 KST
                    Universal time: Fri 2023-08-18 04:57:57 UTC
                          RTC time: Fri 2023-08-18 04:57:57
                         Time zone: Asia/Seoul (KST, +0900)
                       NTP enabled: yes
                  NTP synchronized: yes
                   RTC in local TZ: no
        
      • Rocky Linux 8
        [root@rockylinux8 ~]# timedatectl
                         Local time: Fri 2023-08-18 13:57:57 KST
                     Universal time: Fri 2023-08-18 04:57:57 UTC
                           RTC time: Fri 2023-08-18 04:57:57
                          Time zone: Asia/Seoul (KST, +0900)
          System clock synchronized: yes
                        NTP service: active
                    RTC in local TZ: no
        
    4. /etc/chrony.conf ファイルの設定と内容を確認します。追加の時刻同期化を設定するか、既存の設定情報を変更したい場合にこのファイルで設定できます。

      • VPC環境で提供される NTPサーバの IPアドレスは169.254.169.123169.254.169.124です。
      • CentOS 7
        [root@centos7 ~]# cat /etc/chrony.conf
        # Use public servers from the pool.ntp.org project.
        server 0.centos.pool.ntp.org iburst
        server 1.centos.pool.ntp.org iburst
        server 2.centos.pool.ntp.org iburst
        server 3.centos.pool.ntp.org iburst
        
        ... 省略...
        
      • Rocky Linux 8
        • 時刻同期化の設定値で誤って入力した10. X IPアドレス帯域はコメントアウトします。
        • DHCPサーバから時間同期化のためのサーバ情報を取得するため、変更しなくても時間同期化には問題ありません。
        • コメントアウト前
          [root@rockylinux8 ~]#  cat /etc/chrony.conf
          # These servers were defined in the installation:
          server 10.22.64.22 iburst
          server 10.22.64.38 iburst
          # Use public servers from the pool.ntp.org project.
          # Please consider joining the pool (http://www.pool.ntp.org/join.html).
          
          ... 省略...
          
        • コメントアウト後
          [root@rockylinux8 ~]#  cat /etc/chrony.conf
          # These servers were defined in the installation:
          # server 10.22.64.22 iburst
          # server 10.22.64.38 iburst
          # Use public servers from the pool.ntp.org project.
          # Please consider joining the pool (http://www.pool.ntp.org/join.html).
          server 169.254.169.123
          server 169.254.169.124
          
          ... 省略...
          
    5. 時間同期化の内容を確認します。

      [root@centos7 ~]# systemctl restart chronyd.service
      
      [root@centos7 ~]# chronyc sources -v
      
      .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
      / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
      | /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
      ||                                                 .- xxxx [ yyyy ] +/- zzzz
      ||      Reachability register (octal) -.           |  xxxx = adjusted offset,
      ||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
      ||                                \     |          |  zzzz = estimated error.
      ||                                 |    |           \
      MS Name/IP address         Stratum Poll Reach LastRx Last sample              
      ===============================================================================
      ^+ 169.254.169.123               3   6   377    14  +3999us[+3999us] +/-  227ms
      ^+ 169.254.169.124               3   6   377    51   +198us[ +198us] +/-   44ms
      
      

    Ubuntu

    NAVERクラウドプラットフォームで提供している Ubuntu系の OSで NTP設定値とファイルを点検してください。

    参考

    Ubuntu 18.04、Ubuntu 20.04を対象に説明します。

    1. systemd-timesyncdデーモンの状態を確認します。

      • systemd-timesyncdデーモンが有効になっていると起動時に chronydサービスが動作しないため、必ず無効化します。
      • Ubuntu 18.04: 基本的に systemd-timesynd.serviceが「enabled」状態です。chronydサービスを正常に使用するために「disable」に状態を変更します。
      root@ubuntu1804:~# systemctl is-enabled systemd-timesyncd.service
      enabled
      
      root@ubuntu1804:~# systemctl disable systemd-timesyncd
      Removed /etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service.
      
      root@ubuntu1804:~# systemctl stop systemd-timesyncd
      
      root@ubuntu1804:~# systemctl restart chronyd
      
      root@ubuntu1804:~# systemctl is-enabled systemd-timesyncd.service
      disabled
      
      • Ubuntu 20.04
        root@ubuntu2004:~# systemctl is-enabled systemd-timesyncd.service
        masked
        
    2. chronyインストールおよび動作を確認します。

      • Ubuntu 18.04
        root@ubuntu1804:~# dpkg -l | grep chrony
        ii  chrony                                 3.2-4ubuntu4.5                                     amd64        Versatile implementation of the Network Time Protocol  
        
        root@ubuntu1804:~# ps -ef | grep chronyd | grep -v grep
        _chrony   2149     1  0 19:27 ?        00:00:00 /usr/sbin/chronyd
        
      • Ubuntu 20.04
        root@ubuntu2004:~# dpkg -l | grep chrony
        ii  chrony                               3.5-6ubuntu6.2                        amd64        Versatile implementation of the Network Time Protocol  
        
        root@ubuntu2004:~# ps -ef | grep chronyd | grep -v grep
        _chrony      680       1  0 17:48 ?        00:00:00 /usr/sbin/chronyd -F -1
        _chrony      683     680  0 17:48 ?        00:00:00 /usr/sbin/chronyd -F -1
        
    3. DHCPから取得した NAVERクラウドプラットフォームの NTP設定値を確認します。VPC環境で提供される NTPサーバの IPアドレスは169.254.169.123169.254.169.124です。

      root@ubuntu2004:~# cat /var/lib/dhcp/chrony.servers.eth0
      169.254.169.123 iburst
      169.254.169.124 iburst
      
      • 上記のパスに169.254.169.123169.254.169.124が存在しない場合は、以下のように直接 NTP設定値を追加して対応します。
        root@ubuntu2004:~# cat /etc/chrony/chrony.conf
        # See http://www.pool.ntp.org/join.html for more information.
        #pool ntp.ubuntu.com        iburst maxsources 4
        #pool 0.ubuntu.pool.ntp.org iburst maxsources 1
        #pool 1.ubuntu.pool.ntp.org iburst maxsources 1
        #pool 2.ubuntu.pool.ntp.org iburst maxsources 2
        server 169.254.169.123
        server 169.254.169.124
        
        ... 省略...
        
        root@ubuntu2004:~# systemctl restart chronyd.service
        
        root@ubuntu2004:~# chronyc sources
        210 Number of sources = 2
        MS Name/IP address         Stratum Poll Reach LastRx Last sample              
        ===============================================================================
        ^? 169.254.169.123               3   6     1     8   +608us[ +608us] +/-   19ms
        ^? 169.254.169.124               3   6     1     8   +669us[ +669us] +/-   20ms
        
    4. timedatectl コマンドで時刻同期化の状態を確認します。

      • System clock synchronized 値が yesになると、同期化が正常に行われた状態です。
      • Ubuntu 18.04
        root@ubuntu1804:~# timedatectl
                              Local time: Wed 2023-08-18 19:33:52 KST
                          Universal time: Wed 2023-08-18 10:33:52 UTC
                                RTC time: Wed 2023-08-18 10:33:53
                               Time zone: Asia/Seoul (KST, +0900)
               System clock synchronized: yes
        systemd-timesyncd.service active: no
                         RTC in local TZ: no
        
      • Ubuntu 20.04
        root@ubuntu2004:~# timedatectl
                       Local time: Wed 2023-08-18 17:40:33 KST
                   Universal time: Wed 2023-08-18 08:40:33 UTC
                         RTC time: Wed 2023-08-18 08:40:34   
                        Time zone: Asia/Seoul (KST, +0900)   
        System clock synchronized: yes                       
                      NTP service: active                    
                  RTC in local TZ: no
        
    5. /etc/chrony/chrony.conf ファイルの設定と内容を確認します。追加の時刻同期化を設定するか、既存の設定情報を変更したい場合にこのファイルで設定できます。

      • VPC環境で提供される NTPサーバの IPアドレスは169.254.169.123169.254.169.124です。
        root@ubuntu2004:~# cat /etc/chrony/chrony.conf
        # Use public servers from the pool.ntp.org project.
        server 0.centos.pool.ntp.org iburst
        server 1.centos.pool.ntp.org iburst
        server 2.centos.pool.ntp.org iburst
        server 3.centos.pool.ntp.org iburst
        
        ... 省略...
        
    6. 時間同期化の内容を確認します。

      root@ubuntu2004:~# chronyc sources -v
      
       .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
      / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
      | /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
      ||                                                 .- xxxx [ yyyy ] +/- zzzz
      ||      Reachability register (octal) -.           |  xxxx = adjusted offset,
      ||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
      ||                                \     |          |  zzzz = estimated error.
      ||                                 |    |           \
      MS Name/IP address         Stratum Poll Reach LastRx Last sample              
      ===============================================================================
      ^+ 169.254.169.123               3   6   377    14  +3999us[+3999us] +/-  227ms
      ^+ 169.254.169.124               3   6   377    51   +198us[ +198us] +/-   44ms
      

    NTPに関するよくある質問

    Q. ネットワークを通じた時刻同期化 NTPサーバの設定は NAVERクラウドが提供する2台のみ設定すればいいですか?

    NAVERクラウドで提供する NTPサーバは顧客の多様な環境を考慮して無料で提供するサービスです。
    ネットワーク環境が外部にアクセスできる NATやグローバル IPアドレスを持つ環境の場合は、NAVERクラウドで提供する NTPサーバ以外にも外部の Public NTPサーバを3台以上設定することをお勧めします。

    NTPサーバを2台のみ設定する場合、2台のうち1台で時刻同期化が正常に行われない状況が発生すると、どのサーバの時刻が正確な時刻を提供しているのか分からなくなる Majority(過半数)問題が発生します。公式 NTP設定ガイドでも最小3台のサーバを推奨しており、一般的に5台のサーバを設定することをお勧めしています。詳細は、公式ホームページをご参照ください。

    Private Subnetで NAT設定ができていないため外部ネットワークにアクセスできない場合、Bastionサーバを外部 Public NTPサーバと同期化できるように設定し、そのサーバを含む最小3台以上の NTPサーバを設定することをお勧めします。


    この記事は役に立ちましたか?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.