|
NTPクライアント設定 for RedHat
NTPクライアント設定 for RedHat
0.改訂履歴
- 2005.10.07 新規作成
- 2005.10.14 説明の追加
- 2007.06.11 最新の事情に合わせた.
1.はじめに
このドキュメントでは,ntpdの設定手順を説明する. NTPは,Network Time Protocolの略で,ネットワークを経由して時間を同期するものである. 今回は,外部の公開タイムサーバにと同期をとる為の設定を行う.
なお,使用しているOSは,RedHat Linux ES3.0である.
2.環境の確認と設定
[root@juno root]# rpm -qa | grep ntp
ntp-4.1.2-4.EL3.1
chkfontpath-1.9.10-1.RHEL
[root@juno root]#
|
- パッケージがインストールされている事が確認できた.
- 設定ファイルの存在を確認する.
[root@juno root]# locate ntp.conf
/etc/ntp.conf
[root@juno root]#
|
/etc/ntp.confファイルの設定
変更前 |
[root@juno root]# cat /etc/ntp.conf
# Prohibit general access to this service.
restrict default ignore
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
# -- CLIENT NETWORK -------
# Permit systems on this network to synchronize with this
# time service. Do not permit those systems to modify the
# configuration of this service. Also, do not use those
# systems as peers for synchronization.
# restrict 192.168.1.0 mask 255.255.255.0 notrust nomodify notrap
# --- OUR TIMESERVERS -----
# or remove the default restrict line
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
# restrict mytrustedtimeserverip mask 255.255.255.255 nomodify notrap noquery
# server mytrustedtimeserverip
# --- NTP MULTICASTCLIENT ---
#multicastclient # listen on default 224.0.1.1
# restrict 224.0.1.1 mask 255.255.255.255 notrust nomodify notrap
# restrict 192.168.1.0 mask 255.255.255.0 notrust nomodify notrap
# --- GENERAL CONFIGURATION ---
#
# 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
#
# 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 /var/lib/ntp/drift
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 yes
#
# 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
[root@juno root]#
|
変更後 |
[root@juno root]# cat /etc/ntp.conf
# Prohibit general access to this service.
restrict default ignore
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict ntp1.jst.mfeed.ad.jp
restrict ntp2.jst.mfeed.ad.jp
restrict ntp3.jst.mfeed.ad.jp
restrict 127.0.0.1
restrict 210.196.107.0 mask 255.255.255.240 nopeer nomodify notrap
restrict 210.173.160.27 nomodify notrap noquery
restrict 210.173.160.57 nomodify notrap noquery
restrict 210.173.160.87 nomodify notrap noquery
# -- CLIENT NETWORK -------
# Permit systems on this network to synchronize with this
# time service. Do not permit those systems to modify the
# configuration of this service. Also, do not use those
# systems as peers for synchronization.
# restrict 192.168.1.0 mask 255.255.255.0 notrust nomodify notrap
# --- OUR TIMESERVERS -----
# or remove the default restrict line
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
# restrict mytrustedtimeserverip mask 255.255.255.255 nomodify notrap noquery
# server mytrustedtimeserverip
server ntp1.jst.mfeed.ad.jp
server ntp2.jst.mfeed.ad.jp
server ntp3.jst.mfeed.ad.jp
server 210.173.160.27 # ntp server
server 210.173.160.57 # ntp server
server 210.173.160.87 # ntp server
server 133.31.180.6 # ntp server
# --- NTP MULTICASTCLIENT ---
#multicastclient # listen on default 224.0.1.1
# restrict 224.0.1.1 mask 255.255.255.255 notrust nomodify notrap
# restrict 192.168.1.0 mask 255.255.255.0 notrust nomodify notrap
# --- GENERAL CONFIGURATION ---
#
# 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
#
# 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 /var/lib/ntp/drift
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 yes
#
# 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
[root@juno root]#
|
- restrictによって,許可されたサーバを指定.
- serverによって,上位のNTPサーバを指定.
3.自動起動設定と起動
[root@juno root]# /sbin/chkconfig --list | grep ntp
ntpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@juno root]#
|
- すべてのランレベルでoff担っていることが確認できた.
- ランレベル3と5をonにする.
[root@juno root]# /sbin/chkconfig --level 35 ntpd on
[root@juno root]#
|
[root@juno root]# /sbin/chkconfig --list | grep ntp
ntpd 0:off 1:off 2:off 3:on 4:off 5:on 6:off
[root@juno root]#
|
[root@juno root]# ps -ef | grep ntpd
root 21805 21732 0 17:24 pts/1 00:00:00 grep ntpd
[root@juno root]#
|
[root@juno shinnai]# /sbin/service ntpd start
ntpdを起動中: [ OK ]
[root@juno shinnai]#
|
[root@juno root]# ps -ef | grep ntpd
ntp 21907 1 0 17:26 ? 00:00:00 ntpd -U ntp -p
/var/run/ntpd.pid -g
root 21913 21732 0 17:27 pts/1 00:00:00 grep ntpd
[root@juno root]#
|
[root@juno root]# locate ntpq
/dev/ntpqic11
/dev/ntpqic120
/dev/ntpqic150
/dev/ntpqic24
/usr/share/doc/ntp-4.1.2/ntpq.htm
/usr/share/man/man1/ntpq.1.gz
/usr/sbin/ntpq
[root@juno root]#
|
[root@juno root]# /usr/sbin/ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*LOCAL(0) LOCAL(0) 10 l 61 64 37 0.000 0.000 0.008
ntp1.jst.mfeed. 0.0.0.0 16 u - 64 0 0.000 0.000 4000.00
ntp2.jst.mfeed. 0.0.0.0 16 u - 64 0 0.000 0.000 4000.00
ntp3.jst.mfeed. 0.0.0.0 16 u - 64 0 0.000 0.000 4000.00
[root@juno root]#
|
- 先頭に*がついているものを現在参照しているサーバ.
- この先頭に表示されている文字によって,サーバのステータスが表現されている.
- 代表的なステータスは次の通り.
ntpqでリストされるステータスの意味(抜粋)
文字 |
意味 |
*
|
現在同期されているサーバ. |
+
|
|
x
|
falseticker検査でNogoodになっている. |
-
|
クラスタリング検査でNogoodになっている. |
|
通信できないなどで使用しないサーバ. |
- 現在,このステータスでは,次にようなステータスがわかる.
- ローカルのシステム時刻を参照してることになっている.
- サーバの名前解決は行われている.
- LOCAL以外は,先頭文字がブランクなので,通信できていないない状態.
- このサーバを試した環境では,firewallを利用していると,LOCALが同期元になったりしていた.
4.Firewallについて
- Firewallを設置している環境では,NTPが通過するポート番号を許可しなければならない.
- 通信ポートを確認する.
[root@juno root]# cat /etc/services | grep ntp
nntp 119/tcp readnews untp # USENET News Transfer Protocol
nntp 119/udp readnews untp # USENET News Transfer Protocol
ntp 123/tcp
ntp 123/udp # Network Time Protocol
nntps 563/tcp # NNTP over SSL
nntps 563/udp # NNTP over SSL
trnsprntproxy 3346/tcp # Trnsprnt Proxy
trnsprntproxy 3346/udp # Trnsprnt Proxy
[root@juno root]#
|
- 123番を使っている.
- firewallで,123番ポートが許可されているかを確認し,必要であれば通過設定を行う.
- 設定が完了したら,NTPdを再起動する.
[root@juno shinnai]# /sbin/service ntpd stop
ntpdを停止中: [ OK ]
[root@juno shinnai]# /sbin/service ntpd start
ntpdを起動中: [ OK ]
[root@juno shinnai]#
|
5.時刻同期の確認
[root@juno root]# /usr/sbin/ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
ntp1.jst.mfeed. 0.0.0.0 16 u - 64 0 0.000 0.000 4000.00
ntp2.jst.mfeed. 0.0.0.0 16 u - 64 0 0.000 0.000 4000.00
ntp3.jst.mfeed. 0.0.0.0 16 u - 64 0 0.000 0.000 4000.00
sutntp.sut.ac.j 0.0.0.0 16 u - 64 0 0.000 0.000 4000.00
LOCAL(0) LOCAL(0) 10 l 1 64 1 0.000 0.000 0.008
[root@juno root]# /usr/sbin/ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
ntp1.jst.mfeed. ote-ntp1.jpnap. 2 u 2 64 1 5.127 306596. 0.008
ntp2.jst.mfeed. ote-ntp1.jpnap. 2 u 5 64 1 5.376 306597. 0.008
ntp3.jst.mfeed. ote-ntp1.jpnap. 2 u 5 64 1 5.699 306597. 0.008
sutntp.sut.ac.j 0.0.0.0 16 u - 64 0 0.000 0.000 4000.00
LOCAL(0) LOCAL(0) 10 l 17 64 1 0.000 0.000 0.008
[root@juno root]#
|
- delay部分に遅れている時間が表示されている.
- つまり,指定した上位NTPサーバと通信できたことが確認できる.
- NTPの通信は即時に行われるわけではないので,時間をかけて2〜3分ごとにウォッチしてみる.
- 再度確認してみる.
[root@juno root]# /usr/sbin/ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*ntp1.jst.mfeed. ote-ntp1.jpnap. 2 u 19 64 177 5.825 306600. 0.549
+ntp2.jst.mfeed. ote-ntp1.jpnap. 2 u 15 64 177 5.437 306600. 0.489
+ntp3.jst.mfeed. ote-ntp1.jpnap. 2 u 16 64 177 5.515 306600. 0.910
sutntp.sut.ac.j 0.0.0.0 16 u - 64 0 0.000 0.000 4000.00
LOCAL(0) LOCAL(0) 10 l 33 64 177 0.000 0.000 0.008
[root@juno root]#
|
- 先頭文字が設定されて,優先順位などが設定されている.
- 順次,時間が同期されていくので,dateコマンドなどで確認する.
6.ntpqのリストの説明
- ntpqコマンドで出力されるリストの意味について,説明する.
[root@juno root]# /usr/sbin/ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
+ntp1.jst.mfeed. ote-ntp1.jpnap. 2 u 33 64 377 1.501 -27.576 3.244
-ntp2.jst.mfeed. ote-ntp1.jpnap. 2 u 21 64 377 1.439 -27.243 0.276
+ntp3.jst.mfeed. ote-ntp1.jpnap. 2 u 33 64 377 1.548 -27.652 0.307
*sutntp.sut.ac.j .GPS. 1 u 34 64 377 7.044 -27.834 0.540
LOCAL(0) LOCAL(0) 10 l 38 64 377 0.000 0.000 0.008
[root@juno root]#
|
ntpqコマンドの読み方表
項目 |
説明 |
remote |
タイムサーバとステータスが表示される. |
refid |
remoteで表示されているサーバの情報源を表示する. 上位NTPサーバや,GPS等が表示されることがある. |
st |
サーバの階層を示す番号になり,16が設定してあると16段目となる.段数が多い方が,どちらかというと信頼性が低くなる可能性が高い. |
t |
階層の種類. ( l: local, u: unicast, m: multicast, b:broadcast ) |
when |
remoteから最後のパケットを受け取ってからの経過時間. |
poll |
ポーリング間隔 |
reach |
8進数で到達可能レジスタが表されている. |
delay |
時間の遅延見積もりを,ミリ秒単位で表示している. |
offset |
remoteとの時刻のずれを,ミリ秒単位で表示. |
jitter |
remoteの分散をミリ単位で表示. |
|
|