NTPD
ネットワーク内の時刻合わせを行うためのNTPサーバを導入する。
上位NTPサーバは自分が加入しているISPが提供しているNTPサーバを利用する。
Strutmが上位のNTPサーバほど誤差が少ないはずだが、経路上遠いのではあまり意味がなくなる。
NTPの公式サイトより最新のソースファイルを入手しインストールする。
$ wget http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2.0.tar.gz
$ tar xvzf ntp-4.2.0.tar.gz
$ cd ntp-4.2.0
$ ./configure
$ make
$ make check
# make install
NTPサーバの設定を行う。
/etc/ntp.conf
restrict default ignore
restrict 127.0.0.1
restrict 192.168.1.0 mask 255.255.255.0 notrust nomodify notraprestrict 211.9.226.25 nomodify notrap noquery
server 211.9.226.25 #ntp1.wakwak.comdriftfile /etc/ntp.drift
broadcastdelay 0.008logfile /var/log/ntpd.log
既に時間が大きくずれている場合は事前にNTPサーバと手動で時刻同期をしておく。
# ntpdate ntp1.wakwak.com
Looking for host ntp1.wakwak.com and service ntp
host found : ntp1.wakwak.com
1 Mar 15:41:44 ntpdate[28000]: step time server 211.9.226.25 offset -78.946182sec
NTPサーバを起動し時刻が同期されるか確認する。
# /usr/local/bin/ntpd -c /etc/ntp.conf
# ps -ef | grep ntpd
root 6934 1 0 13:30:16 ? 0:00 ntpd -c /etc/ntp.conf# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*ntp1.wakwak.com 211.9.226.9 3 u 32 64 37 15.886 -195.00 43.005
サーバ起動時に自動的にNTPサーバも起動するように起動スクリプトを作成する。
/etc/init.d/ntpd
#!/sbin/sh
# ntpd scriptcase "$1" in
'start')
if [ -f /etc/ntp.conf ]; then
echo "Startup ntpd now..............."
/usr/local/bin/ntpd -c /etc/ntp.conf &
fi
;;'stop')
echo "Shutdown ntpd now..............."
/usr/bin/pkill -x -u 0 'ntpd'
;;'restart')
$0 stop
$0 start
;;*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;esac
exit 0
ランレベル2のときにntpdが起動するようにシンボリックリンクを張る。
# chmod 744 /etc/init.d/ntpd
# ln -s /etc/init.d/ntpd /etc/rc2.d/S74ntpd
サーバ稼働時のログ。
# tail /var/log/daemon.log
Dec 12 16:03:47 bolis last message repeated 1 time
Dec 12 16:19:09 bolis ntpd[18193]: [ID 702911 daemon.notice] ntpd 4.2.0@1.1161-r Fri Dec 12 16:07:14 JST 2003 (1)
Dec 12 16:19:09 bolis ntpd[18193]: [ID 702911 daemon.info] precision = 4.631 usec
Dec 12 16:19:09 bolis ntpd[18193]: [ID 702911 daemon.info] kernel time sync status 0040
Dec 12 16:19:09 bolis ntpd[18193]: [ID 702911 daemon.info] frequency initialized 500.000 PPM from /etc/ntp.drift# tail /var/log/ntpd.log
12 Dec 16:46:23 ntpd[18193]: synchronized to 211.9.226.25, stratum=3
