0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ローカル内に設置しているZabbix アプライアンスのNTP設定

Posted at

概要

インターネットに繋がっていない環境下(正確にはVPN網で各拠点に接続)に設置している Zabbix アプライアンスにて、NTPサーバの指定がインターネット上のサーバを参照するように設定されているようで、気が付いたら時刻がずれていた。

各拠点にはローカル NTP サーバが存在するので、Zabbix もローカルの NTP を参照するように設定し、時刻ずれを修正したメモ。

確認

現在の状況をtimedatectlコマンドを実行して確認する。

root@Zabbix:/etc# timedatectl
      Local time: Thu 2020-07-16 10:55:18 JST
  Universal time: Thu 2020-07-16 01:55:18 UTC
        RTC time: Thu 2020-07-16 02:04:47
       Time zone: Asia/Tokyo (JST, +0900)
 Network time on: yes
NTP synchronized: no
 RTC in local TZ: no

時間がずれていることと、Network time onyesと設定されているにも関わらずNTP synchronizednoとなっており、NTPサーバと同期が取れていないことが分かる。

対応

現在のNTPクライアント設定を確認、修正する。
NTPクライアントはsystemd-timesyncdを利用している。
(NTPサーバの機能を利用しないのであれば、NTPdChronyは利用せずにsystemd-timesyncdでクライアント機能だけを利用するのが好ましい)

/etc/systemdに設定ファイルがあるので、移動した後まずバックアップを作成。

root@Zabbix:/etc# cd systemd/
root@Zabbix:/etc/systemd# ls
bootchart.conf  logind.conf  resolved.conf  system.conf     user
journald.conf   network      system         timesyncd.conf  user.conf
root@Zabbix:/etc/systemd# cp -p timesyncd.conf 20200716-timesyncd.conf.bk
root@Zabbix:/etc/systemd# ls
20200716-timesyncd.conf.bk  journald.conf  network        system       timesyncd.conf  user.conf
bootchart.conf              logind.conf    resolved.conf  system.conf  user

バックアップ後、設定ファイルを確認して正しい内容に変更する。

root@Zabbix:/etc/systemd# vi 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.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See timesyncd.conf(5) for details.

[Time]
NTP=XXX.XXX.XXX.XXX ←ここにローカルNTPのIPを指定する(本例では 192.168.1.2)
FallbackNTP=0.jp.pool.ntp.org 1.jp.pool.ntp.org 2.jp.pool.ntp.org 3.jp.pool.ntp.org

修正した後に一応sysetmd-timesyncdのNTP機能を有効化。

root@Zabbix:/etc/systemd# timedatectl set-ntp true

この時点ではまだ変更が適用されていないため、NTP同期が失敗したまま。
サービスの再起動を行って変更を適用する。

# 再起動してないので、まだだめ。
# `Status`が`"Idle."`になっており、動いていない。
root@Zabbix:/etc/systemd#  systemctl status systemd-timesyncd.service
● systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-11-28 12:12:58 JST; 7 months 17 days ago
     Docs: man:systemd-timesyncd.service(8)
 Main PID: 330 (systemd-timesyn)
   Status: "Idle."
   CGroup: /system.slice/systemd-timesyncd.service
           └─330 /lib/systemd/systemd-timesyncd

Jul 16 05:35:28 Zabbix systemd-timesyncd[330]: Timed out waiting for reply from 192.168.1.1:123 (192.168.1.1).
Jul 16 06:09:46 Zabbix systemd-timesyncd[330]: Timed out waiting for reply from 192.168.1.1:123 (192.168.1.1).
Jul 16 06:44:05 Zabbix systemd-timesyncd[330]: Timed out waiting for reply from 192.168.1.1:123 (192.168.1.1).
Jul 16 07:18:23 Zabbix systemd-timesyncd[330]: Timed out waiting for reply from 192.168.1.1:123 (192.168.1.1).
Jul 16 07:52:42 Zabbix systemd-timesyncd[330]: Timed out waiting for reply from 192.168.1.1:123 (192.168.1.1).
Jul 16 08:27:00 Zabbix systemd-timesyncd[330]: Timed out waiting for reply from 192.168.1.1:123 (192.168.1.1).
Jul 16 09:01:19 Zabbix systemd-timesyncd[330]: Timed out waiting for reply from 192.168.1.1:123 (192.168.1.1).
Jul 16 09:35:37 Zabbix systemd-timesyncd[330]: Timed out waiting for reply from 192.168.1.1:123 (192.168.1.1).
Jul 16 10:09:56 Zabbix systemd-timesyncd[330]: Timed out waiting for reply from 192.168.1.1:123 (192.168.1.1).
Jul 16 10:44:14 Zabbix systemd-timesyncd[330]: Timed out waiting for reply from 192.168.1.1:123 (192.168.1.1).

# サービス再起動
root@Zabbix:/etc/systemd# systemctl restart systemd-timesyncd.service

# 修正が反映された。`Status`が`"Synchronized ~"`となっており、同期が開始された。
root@Zabbix:/etc/systemd# systemctl status systemd-timesyncd.service
● systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2020-07-16 11:00:19 JST; 12s ago
     Docs: man:systemd-timesyncd.service(8)
 Main PID: 7616 (systemd-timesyn)
   Status: "Synchronized to time server 192.168.1.2:123 (192.168.1.2)."
   CGroup: /system.slice/systemd-timesyncd.service
           └─7616 /lib/systemd/systemd-timesyncd

Jul 16 11:00:19 Zabbix systemd[1]: Starting Network Time Synchronization...
Jul 16 11:00:19 Zabbix systemd-timesyncd[7616]: Synchronized to time server 192.168.1.2:123 (192.168.1.2).
Jul 16 11:00:19 Zabbix systemd[1]: Started Network Time Synchronization.

最後に改めて現在の状況をtimedatectlコマンドを実行して確認。

root@Zabbix:/etc/systemd# timedatectl
      Local time: Thu 2020-07-16 11:00:52 JST
  Universal time: Thu 2020-07-16 02:00:52 UTC
        RTC time: Thu 2020-07-16 02:00:52
       Time zone: Asia/Tokyo (JST, +0900)
 Network time on: yes
NTP synchronized: yes
 RTC in local TZ: no
root@Zabbix:/etc/systemd#  

NTP synchronizedyesとなっており、NTPサーバと同期が取れていることが分かる。
もしも本設定を行っても時刻が同期されない場合は、大きく時刻がずれている可能性があるため、timedatectl set-time "時刻"コマンドにて手動で時刻合わせしてからサービスを再起動してみること。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?