NTP 4.2.4 Install (rpm)


NTP 4.2.4をインストールした時のメモ。

  • Vine Linux 5.0
  • NTP 4.2.4

rpmパッケージをインストールする。

# apt-get install ntp

時間をISPのNTPサーバに同期させる。

# ntpdate -b -u 202.234.233.106


取り敢えず使っているISPの近い距離のサーバに向ける。

# vi /etc/ntp.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  202.234.233.106 iburst
server  202.234.233.109 iburst
server  210.145.255.76 iburst

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

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

起動スクリプト。

#!/bin/bash
#
# ntpd		This shell script takes care of starting and stopping
#		ntpd (NTPv4 daemon).
#
# chkconfig: - 58 74
# description: ntpd is the NTPv4 daemon. \
# The Network Time Protocol (NTP) is used to synchronize the time of \
# a computer client or server to another server or reference time source, \
# such as a radio or satellite receiver or modem.

# Source function library.
. /etc/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

if [ -f /etc/sysconfig/ntpd ];then
        . /etc/sysconfig/ntpd
fi

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

ntpconf=/etc/ntp.conf
ntpstep=/etc/ntp/step-tickers

[ -x /usr/sbin/ntpd -a -f $ntpconf ] || exit 0

RETVAL=0
prog="ntpd"

start() {
	# check for -x
	OPTIND=0
	dostep=''
	while getopts ":aAbc:dD:f:gk:l:LmnN:p:P:qr:s:t:v:V:xU:T:" args $OPTIONS;
	do 
	  if [ "$args" = "x" ]; then
	      dostep='yes' 
	      break
	  fi
	done
	OPTIND=0

	if [ -s "$ntpstep" -o -n "$dostep" ]; then
	    # Synchronize with servers if step-tickers exists
	    # or the -x option is used

	    # get the servers from step-ticker
	    tickers=''
	    if [ -s "$ntpstep" ]; then
		tickers=`/bin/sed -e 's/\#.*$//g' $ntpstep`
	    fi
	    if [ -z "$tickers" ]; then
		tickers=`/bin/awk '$1=="peer"||$1=="server"{print $2}' $ntpconf`
	    fi

	    echo -n $"$prog: Synchronizing with time server: "
	    /usr/sbin/ntpdate -s -b -p 8 $tickers 2>/dev/null >/dev/null
	    RETVAL=$?
	    [ $RETVAL -eq 0 ] && success || failure
	    echo
	    if [ $RETVAL -ne 0 ]; then
	            OPTIONS="$OPTIONS -g"
	    fi
	else
	    # -g can replace the grep for time servers
	    # as it permits ntpd to violate its 1000s limit once.
	    OPTIONS="$OPTIONS -g"
	fi
        # Start daemons.
        echo -n $"Starting $prog: "
        daemon ntpd $OPTIONS
	RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ntpd
	return $RETVAL
}

stop() {
        # Stop daemons.
        echo -n $"Shutting down $prog: "
	killproc ntpd
	RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ntpd
	return $RETVAL
}

# See how we were called.
case "$1" in
  start)
	start
        ;;
  stop)
	stop
        ;;
  status)
	status ntpd
	RETVAL=$?
	;;
  restart|reload)
	stop
	start
	RETVAL=$?
	;;
  condrestart)
	if [ -f /var/lock/subsys/ntpd ]; then
	    stop
	    start
	    RETVAL=$?
	fi
	;;
  *)
        echo $"Usage: $0 {start|stop|restart|condrestart|status}"
        exit 1
esac

exit $RETVAL

起動設定後、デーモンとして起動。

# chkconfig ntpd on
# service ntpd start

ハードウェアクロックを同期させておく。

# hwclock -w