LoginSignup
7
6

More than 5 years have passed since last update.

ntpdとntpdateを同時に実行する方法

Posted at

経緯

Qiitaを最近書き始めるようになり、過去の対応内容を見返していました。
改めて記事を書こうと思い、調べてみるともっとよい方法が見つかったので、共有したいと思います。

※ そもそもntpdとntpdateを共存させる必要あるの?という面は、ここでは述べません。

当時の対応

the NTP socket is in use, exiting

上記メッセージがサーバから届き、調べてみると同時には実行できないとのこと。
当時は「2つも時刻合わせはいらないね」ってことで、1つだけにしました。

ntpdとntpdateは同時実行できない!?

この記事を書いていて、検証も兼ねてサーバで実験してみました。
環境:CentOS 5.9 (Final)

#  service ntpd status
ntpd (pid  2471) を実行中...
# ntpdate (NTPサーバ)
 4 Mar 23:49:38 ntpdate[24301]: the NTP socket is in use, exiting

確かに、今でも実行できません。
では、こうすると

# ntpdate -u (NTPサーバ)
 4 Mar 23:56:42 ntpdate[24400]: adjust time server 202.224.32.4 offset -0.000102 sec

実行することができました!

# man ntpdate
-u      Direct ntpdate to use an unprivileged port for  outgoing  packets.  This  is  most  useful when behind a firewall that blocks incoming traffic to privileged ports, and you want to  synchronize  with  hosts  beyond the firewall. Note that the -d option always uses unprivileged ports.

-u オプションを付けることで、ntpdが使用しているポートとは、別のポートを利用して同期を実行してくれるとのこと。

とても勉強になりました!

参考記事(感謝!):
元RX-7乗りの適当な日々
ntpdが動いている環境で、ntpdateを実行する

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