2022年8月、ホームページを全面リニューアルしました! 情報を分かりやすくお伝えできるサイト作りを目指してまいります。

xntpタイムサーバ構築改、ntpサーバインスコ!

xntpサーバ改、ntpdサーバモジュールのインスコ!
ntpd時間同期サーバモジュールを入れて、自分のサーバの時間を正確にしよう!
ところで、 ntpサーバの元祖福岡大学のntpサーバがパンクしそうだ!と言う話がある。したがって、出来るだけあなたの契約してるプロバイダのntpサーバや、最近公開された独立行政法人 情報通信研究機構 国立研究開発法人情報通信研究機構 ( 133.243.238.164 )(ntp.nict.jp)のntpサーバなどへ同期を取ったらいかがだろう。

ターゲットOS : RedHatLinux9
rpm版は消してソースからわざわざコンパイルする( ̄ー ̄; ヒヤリ!


1. ソース入手

ダウンロードサイトより ntp-4.1.1a.tar.gz を入手する(執筆時点ではこれが最新だった)。

ダウンロードサイトは、 ここ でゲットしよう。


2. インストール(コンパイル&リンク)

 # cd /usr/local/src

 # tar zxvf ntp-4.1.1a.tar.gz

 # cd ntp-4.1.1a

 # ./configure

 # make

 # make install

 # cd /etc

 # mkdir ntp

 # cd ntp

 # touch drift


3. 設定

/etc/ntp.confを設定する(俺のconfだぜ!!)。以下の赤字のみにする。

# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available. The
# default stratum is usually 3, but in this case we elect to use stratum
# 0. Since the server line does not have the prefer keyword, this driver
# is never used for synchronization, unless no other other
# synchronization source is available. In case the local host is
# controlled by some external source, such as an external oscillator or
# another protocol, the prefer keyword would cause the local host to
# disregard all other synchronization sources, unless the kernel
# modifications are in use and declare an unsynchronized condition.
#
#server 127.127.1.0 # local clock
#fudge 127.127.1.0 stratum 10

server 133.243.238.164        # nict
server 203.139.30.195         # ntp.cyber-fleet.net
server 203.255.112.4          # time.nuri.net

#
# Drift file. Put this in a directory which the daemon can write to.
# No symbolic links allowed, either, since the daemon updates the file
# by creating a temporary in the same directory and then rename()’ing
# it to the file.
#
driftfile /etc/ntp/drift
multicastclient             # listen on default 224.0.1.1
broadcastdelay 0.008

#
# Authentication delay. If you use, or plan to use someday, the
# authentication facility you should make the programs in the auth_stuff
# directory and figure out what this number should be on your machine.
#
authenticate no

#
# Keys file. If you want to diddle your server at run time, make a
# keys file (mode 600 for sure) and define the key number to be
# used for making requests.
#
# PLEASE DO NOT USE THE DEFAULT VALUES HERE. Pick your own, or remote
# systems might be able to reset your clock at will. Note also that
# ntpd is started with a -A flag, disabling authentication, that
# will have to be removed as well.
#
#keys /etc/ntp/keys

serverの項を 福岡大学タイムサーバ にすることが多いらしく、 このような 問題も深刻らしい。出来るだけ、自分の使ってるISPのタイムサーバと同期するか、最近NTPを公開した 独立行政法人 情報通信研究機構( 133.243.238.164 )のサーバなんて使うと良いかも知れない。

server 133.243.238.164
driftfile /etc/ntp/drift

ちなみにここでは使ってないが、以下のように”restrict” を使うことで、NTP server に対する接続を制限することが出来る。自前のサーバは、NTPツリー上では下位に位置し、回線も細いことから制限して LAN 接続のIPアドレス以外は、接続しないように設定する。 ntpd は、最後にマッチした行の制限がかかるので、最初にデフォルトを書く。

restrict default notrust nomodify
restrict 133.100.11.8
restrict 192.168.255.0 mask 255.255.255.0 nomodify
restrict 127.0.0.1


4. 起動ファイルの作成

ゆみどんサイト の ここ のntpネタで起動ファイルは、この項を参照せよ。と紹介していただいたので責任重大とばかりしっかりと説明せねば(笑)。

 # vi /etc/rc.d/init.d/ntpd

#chkconfig: 345 58 74
#description:ntp Server

#!/bin/sh
case “$1” in
  ’start’)
    if [ -f /etc/ntp.conf ]; then
      echo ‘starting ntpd daemon’
      /usr/local/bin/ntpd -c /etc/ntp.conf &
    fi
  ;;

  ’stop’)
    killall ‘ntpd’
  ;;

  *)
   echo “Usage: $0 { start | stop }”
   exit 1
  ;;
esac
exit 0

 # chmod 755 /etc/rc.d/init.d/ntpd

 # chkconfig –add ntpd

 # chkconfig –level 345 ntpd on

 # chkconfig –list ntpd

 ntpd 0:オフ 1:オフ 2:オン 3:オン 4:オン 5:オン 6:オフ


5. ntpdの起動

 # /etc/rc.d/init.d/ntpd start

※ 再起動しても良い。


6. 一発目の時刻合わせ

 # /usr/sbin/ntpdate 203.255.112.4

 # /sbin/clock -w                  ← BIOSへの時刻書込!(Linuxのみ)


7. 確認

 # ntpq -p

remote refid st t when poll reach delay offset jitter
=========================================================
*clock.nc.fukuok .GPS. 1 u 489 1024 377 102.446 15.149 25.288
ns2.cyber-fleet tick.ucla.edu 2 u 447 1024 3 80.485 -2.053 6.361
ns2.higlobe.net 202.30.201.92 16 u 87d 1024 0 0.000 0.000 4000.00

上のように、アスタリスクマークがつかないと同期が取れてないので注意する事。


8. ntp鯖なんぞ立てないで手っ取り早い時刻合わせ!

xntpサーバをわざわざ立てないで、どこぞのタイムサーバから時刻をゲットする!

# /usr/sbin/ntpdate 203.255.112.4 > /dev/null 2>&1

上記のコマンドを、cronに数時間間隔で実行させるようにしておけばOK!


9. その他(エラーの対処)

CentOSとかFedoraCoreなどRHL系のNTPのバイナリパッケージを入れたら、

can’t open /etc/ntp/drift.TEMP: Permission denied
こんなエラーが出てしまった。

これは、/etc/ntpのオーナーとグループの設定の問題なので、以下のようにしてオーナーとグループをちゃんと設定すれば消えるはずだ。
# chown ntp.ntp /etc/ntp

以上

コメント