サーバ時刻同期 NTP
NTPとは「Network Time Protocol」の略。基準となるサーバ機器と時刻を定期的に同期させる。
目的
サーバの時刻を基準となるサーバ(NTPサーバ)と同期させ、時刻を正確に保つ。
構築条件
構築方法
- 仮想サーバ SUN VirtualBox 4.3/Hyper-V で構築
作成環境
OS | CentOS 6.5 64bit版 |
サーバ作成条件
サーバIP | 192.168.0.10/24 |
ホスト名 | hogehogeServer |
user | hogehoge |
userpasswd | hogehogepass |
NTPサーバ | 192.168.0.1 |
手順記入ルール
- コマンド行頭記号で 「$」はユーザ権限 「#」はスーパーユーザー権限 を表示
- コマンドが長くなる場合は、行末に「\」を記述し複数行に記述。
前準備
- CentOSインストール 実施
- yumリポジトリ設定 実施
インストール
【telnet】
- rootでログイン
$ su パスワード:
- 確認
# yum list install ntp
ntp.x86_64 4.2.6p5-1.el6.centos @anaconda-CentOS-201311272149.x86_64/6.5
★installedでない場合、以下コマンドにてインストール実施
- インストール
# yum install ntp
設定
- 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 iburst server 1.centos.pool.ntp.org iburst server 2.centos.pool.ntp.org iburst server 3.centos.pool.ntp.org iburst server 192.168.0.1 ←追加
起動
(1)起動登録
- ntp手動時刻合わせ
# ntpdate 0.centos.pool.ntp.org
18 Feb 22:49:26 ntpdate[1622]: step time server 176.34.56.18 offset -5.361246 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
==============================================================================
+extendwings.com 133.243.238.163 2 u 2 64 3 5.601 1.587 15.894
*chobi.paina.jp 131.112.181.48 2 u 3 64 3 40.936 23.101 30.861
+felixx.tsn.or.j 133.243.238.163 2 u 1 64 3 29.557 14.709 35.106
-sylph.white-voi 203.178.138.38 3 u 1 64 3 34.093 11.827 31.774
*192.168.0.1 xxx.x.xx.xx 3 u 40 64 7 0.652 -14.994 0.688
★サーバの前に「*」があることを確認・・ない場合は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