内容が古い可能性がありますのでご注意ください。
時刻合わせの為のNTPサーバーを構築します。
NTPサーバを立てると、NTPサーバはほかのサーバを参照して時刻を正確に保ちつつ、ほかのパソコンに対して、時刻の同期を取るための、NTPサービス を提供することが出来るようになる。
引用元:tech.ckme.co.jp
サーバー自身の時刻合わせのみならば、デフォルトでインストールされているntpdateコマンドをcronで動かせば良いようです。
ntpdのインストールと設定
ntpdの起動時に時刻があまりにもズレているとntpdが起動出来ない場合があるそうなので、事前に手動で時刻を合わせておきます。
[html]sudo ntpdate ntp.nict.jp[/html]
時刻を合わせたら、パッケージをインストールします。
[html]sudo aptitude install ntp[/html]
インストール後、自動的にntpdサービスが起動します。
次に、ntpの設定を行います。
[html]sudo cp /etc/ntp.conf /etc/ntp.conf.original
#↑バックアップ作成
sudo nano /etc/ntp.conf
# Enable this if you want statistics to be logged.
statsdir /var/log/ntpstats/
#↑コメントアウトを削除し、専用のログを有効にします。
# You do need to talk to an NTP server or two (or three).
#server ntp.ubuntu.com
server ntp.nict.jp
server ntp.nict.jp
server ntp.nict.jp
server ntp.jst.mfeed.ad.jp
#↑NTPサーバーを指定します。デフォルトではntp.ubuntu.comになっているのでコメントアウトし、国内のNTPサーバーを指定します。
#NTPサーバーは複数指定可です。stratumの数値が少ないほど優先されます。ntp.nict.jpはstratum1、ntp.jst.mfeed.ad.jpはstratum2以降のようです。
# By default, exchange time with everybody, but don’t allow configuration.
#restrict -4 default kod notrap nomodify nopeer noquery
#restrict -6 default kod notrap nomodify nopeer noquery
restrict default ignore
#初期設定では全てのアクセスを許可しないようにします。
# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1
#自宅サーバー自身は全てのアクセスを許可します。
# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 mask 255.255.255.0 notrust
#restrict 192.168.0.0 mask 255.255.0.0 noquery nomodify nopeer notrust notrap
restrict 192.168.xxx.0 mask 255.255.255.0 notrust nomodify notrap nopeer
restrict 192.168.xxx.0 mask 255.255.255.0 notrust nomodify notrap nopeer
#自宅LAN内からは、時刻問い合わせのみ許可します。
#ファイルの末尾に下記内容を追加します。
restrict ntp.nict.jp noquery notrap nomodify
restrict ntp.jst.mfeed.ad.jp noquery notrap nomodify
#指定したNTPサーバへの問い合わせを許可[/html]
設定が終わったら、ntpdを再起動します。
[html]sudo /etc/init.d/ntp restart[/html]
NTPサーバーの動作確認は、ntpq -pコマンドで確認出来ます。
[html]ntpq -p
remote refid st t when
==========================
*210.171.226.40 .NICT. 1 u 48 …
ntp3.jst.mfeed. .STEP. 16 u – 256 …
[/html]
remoteの先頭に*がついたものが同期が取れたNTPサーバーになります。
同期が取れるまでは少し時間がかかりますので、ntpdの再起動後10分から20分後位にコマンドを実行してみて下さい。
参考サイト様
- NTPサーバー構築|CentOSで自宅サーバー構築
- NTP|架空線 はてな避難所
(今回、こちらの記事を大変参考にさせて頂きました) - NTPの設定|tech.ckme.co.jp
- ubuntu server NTP(時刻調整)|uniunix
- NTP/推奨公開サーバ|wiki@nothing
- NTPを設定してみよう|ピーチネットワーク
notrap
ピンバック: このブログについて « SkyGarden出張所