Ubuntu

Ubuntu18.04 NTPサーバーを動かす

昔の記事を見ながら宅内のNTPサーバーを立ててみたが、うまく動かない。
NTPでは123/udpを利用するので開けてある。だが、それ以前の問題としてサービスがうまく起動しない。

やることは Chrony というアプリケーションを設定すること。
そこに至る過程は、その後に記載。



広告


よくわからないけど、NTPはChronyに置き換わったのかな?
Server World / NTP サーバー : Chrony の設定
を参考にインストールしてみる。

$ sudo apt install chrony

設定はntpdとよく似ている。

/etc/chrony/chrony.conf

pool ntp.nict.jp          iburst
pool ntp1.jst.mfeed.ad.jp iburst
pool ntp2.jst.mfeed.ad.jp iburst
pool ntp3.jst.mfeed.ad.jp iburst

keyfile /etc/chrony/chrony.keys

driftfile /var/lib/chrony/chrony.drift

logdir /var/log/chrony

maxupdateskew 100.0

rtcsync

makestep 1 3

# 接続元設定
allow 172.16.0.0/16
allow 24nn:nnnn:nnnn:nnnn::/64
allow fdnn:nnnn:nnnn:nnnn::/64

※コメントは割愛

NTPサーバーは以下を使わせていただくこととした。
日本標準時グループ / 公開NTP
INTERNET MULTIFEED社 / 時刻情報提供サービス for Publicとは

サービスを再起動して、状況確認。

$ sudo systemctl restart chrony
$ chronyc sources
210 Number of sources = 7
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^* ntp-a2.nict.go.jp             1   6   377    32    +31us[ +103us] +/- 4256us
^+ ntp-a3.nict.go.jp             1   6   377    30   -474us[ -474us] +/- 4544us
^+ ntp-b2.nict.go.jp             1   6   377    29   +387us[ +387us] +/- 3895us
^+ ntp-a3.nict.go.jp             1   6   377    29   -648us[ -648us] +/- 4856us
^- ntp1.jst.mfeed.ad.jp          2   6   377    28   -291us[ -291us] +/-   79ms
^- ntp2.jst.mfeed.ad.jp          2   6   377    30   +592us[ +592us] +/-   74ms
^- ntp3.jst.mfeed.ad.jp          2   6   377    29   +799us[ +799us] +/-  109ms

さっくり動作、Windowsからも時刻の同期がとれた。


なんで Chrony をインストールしたかというと、ntpがうまく動かないから調べていたら CentOSではChronyへの流れになっているようだったから。Ubuntuがどうなのかはわからない。

当然動くんでしょ?ということでntpをインストールして設定してみる。

$ sudo apt install ntp

/etc/ntp.conf

driftfile /var/lib/ntp/ntp.drift
leapfile /usr/share/zoneinfo/leap-seconds.list
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

server ntp.nict.jp
server ntp.nict.jp
server ntp.nict.jp
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited

restrict 127.0.0.1
restrict ::1

restrict 172.16.0.0 mask 255.255.0.0
restrict fdnn:nnnn:nnnn:nnnn:: mask ffff:ffff:ffff:ffff::
restrict 24nn:nnnn:nnnn:nnnn:: mask ffff:ffff:ffff:ffff::

設定をこうして、サービスを再起動してみた。

$ sudo systemctl restart ntp

いつまでたっても同期しない。先頭に*が付かない。

$ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 ntp-a2.nict.go. .INIT.          16 u    -  256    0    0.000    0.000   0.000

サーバープールってのが気になったので…でも、これはサーバーを列挙してるだけだなぁ。

driftfile /var/lib/ntp/ntp.drift
leapfile /usr/share/zoneinfo/leap-seconds.list
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

server 0.jp.pool.ntp.org iburst
server 1.jp.pool.ntp.org iburst
server 2.jp.pool.ntp.org iburst
server 3.jp.pool.ntp.org iburst
server ntp.nict.jp
server ntp.nict.jp
server ntp.nict.jp
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited

restrict 127.0.0.1
restrict ::1

restrict 172.16.0.0 mask 255.255.0.0
restrict fdnn:nnnn:nnnn:nnnn:: mask ffff:ffff:ffff:ffff::
restrict 24nn:nnnn:nnnn:nnnn:: mask ffff:ffff:ffff:ffff::

これでどうにか同期が始まったのだが…再起動して試そうと思ったら、サービス起動しない。サービスを有効にしてみたものの、再起動するといったんロードされて誰かにプロセスを落とされるみたい。

Quiita / Ubuntu 16.04にntpとntpdateを両方インストールするとOS起動時にntp.serviceが停止している

なんで、こんなに不親切な感じにしてあるんだろう?
やめよう。

$ sudo apt remove ntp --purge
$ sudo apt autoremove


今後は ntp じゃなくて Chronyってことなのかな。
今は他にやることもあるから、気にしないで進めることとする。

広告
ろっひー

コメントはこちらから お気軽にどうぞ ~ 投稿に関するご意見・感想・他