CentOS5.5/ntp

Last-modified: 2011-02-07 (月) 23:32:55
最終更新:2011-02-07 (月) 23:32:55
アクセス数(合計):?
利用者; ? アクセス数(本日):? アクセス数(昨日):?

サーバ時刻同期 NTP

NTPとは「Network Time Protocol」の略。基準となるサーバ機器と時刻を定期的に同期させる。


目的

サーバの時刻を基準となるサーバ(NTPサーバ)と同期させ、時刻を正確に保つ。

構築条件

構築方法

作成環境

OS    CentOS 5.5 64bit版

サーバ作成条件

サーバIP192.168.0.10/24
ホスト名hogehogeServer
user   hogehoge
userpasswdhogehogepass
NTPサーバ192.168.0.1

手順記入ルール

  • コマンド行頭記号で 「$」はユーザ権限 「#」はスーパーユーザー権限 を表示
  • コマンドが長くなる場合は、行末に「\」を記述し複数行に記述。

前準備

  1. CentOSインストール 実施
  2. yumリポジトリ設定 実施

インストール

【telnet】

  • rootでログイン
$ su
パスワード:
  • 確認
# yum list install ntp
ntp.x86_64                       4.2.2p1-9.el5.centos.2.1                        installed

★installedでない場合、以下コマンドにてインストール実施

  • インストール
# yum install ntp

   :

Complete!

設定

  • ntp.conf ファイル編集
# vi /etc/ntp.conf
  • ネットワーク内からの同期許可
    # Hosts on local network are less restricted.
    #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
    restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap ←追加
  • ネットワーク内ntpサーバの追加
    # Please consider joining the pool (http://www.pool.ntp.org/join.html).
    server 0.centos.pool.ntp.org
    server 1.centos.pool.ntp.org
    server 2.centos.pool.ntp.org
    server 192.168.0.1 ←追加

起動

(1)起動登録

  • 再ログイン
# su -
  • ntp手動時刻合わせ
# ntpdate 192.168.0.1
 1 Feb 11:50:10 ntpdate[12551]: step time server 192.168.0.1 offset 18.393302 sec
  • ntp起動
# /etc/rc.d/init.d/ntpd start
ntpd を起動中:                                             [  OK  ]
  • ntp自動起動設定
# chkconfig ntpd on
  • 確認
# chkconfig --list ntpd
ntpd            0:off   1:off   2:on    3:on    4:on    5:on    6:off

(2)同期確認

  • 同期確認
# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*192.168.0.1    xxx.x.xx.xx       3 u   40   64    7    0.652  -14.994   0.688
 LOCAL(0)        .LOCL.          10 l   35   64    7    0.000    0.000   0.001

★サーバの前に「*」があることを確認・・ない場合は10分程度時間を置いて再コマンド投入

  • 終了
# exit
 exit
$

遭遇したトラブル

ntpq -pでエラー「Temporary failure in name resolution」発生

問題:
ntpq -p で以下エラーが出る

Temporary failure in name resolution

原因:
hostsの設定が誤っている。以下コマンドでhostsを確認

# vi /etc/hosts
127.0.0.1              hogehogeServer localhost.localdomain localhost

  ↑コメントアウトされている。localhostが消えている等の場合エラーとなる

謝辞

テキスト作成に当たり、以下サイトを参考にさせて頂きました。ありがとうございます。

http://centossrv.com/ntp.shtml
http://www.ipa.go.jp/security/awareness/administrator/secure-web/chap4/4_ntpd.html
http://realde.seesaa.net/article/153666704.html