NTPを使ってUbuntuの時刻合わせ

PHPの勉強で日付に関することをやっていたら、まるで合っていないことに気がついたので、これを合わせることにする。

最近はもっぱらVMware FusionにインストールしているUbuntu Server上での作業なので、NTP(Network Time Protocol)を使って、このUbuntu Serverの時刻合わせをする。

UbuntuにはデフォルトでNTPに関するパッケージはインストールされていないので、apt-getコマンドを使ってntpのパッケージをインストールする。

$ sudo apt-get install ntp
Reading package lists… Done
Building dependency tree
Reading state information… Done
Suggested packages:
ntp-doc
The following NEW packages will be installed:
ntp
0 upgraded, 1 newly installed, 0 to remove and 36 not upgraded.
Need to get 487kB of archives.
After this operation, 1221kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com intrepid-updates/main ntp 1:4.2.4p4+dfsg-6ubuntu2.3 [487kB]
Fetched 487kB in 2s (185kB/s)
tar: ./postinst: time stamp 2009-05-13 17:11:21 is 13029726.148910012 s in the future
tar: ./prerm: time stamp 2009-05-13 17:11:21 is 13029726.147629681 s in the future
tar: ./postrm: time stamp 2009-05-13 17:11:21 is 13029726.146984068 s in the future
tar: ./conffiles: time stamp 2009-05-13 17:11:21 is 13029726.146313312 s in the future
tar: ./md5sums: time stamp 2009-05-13 17:11:25 is 13029730.145565452 s in the future
tar: ./control: time stamp 2009-05-13 17:11:25 is 13029730.144971801 s in the future
tar: .: time stamp 2009-05-13 17:11:25 is 13029730.144455813 s in the future
Selecting previously deselected package ntp.
(Reading database … 28691 files and directories currently installed.)
Unpacking ntp (from …/ntp_1%3a4.2.4p4+dfsg-6ubuntu2.3_amd64.deb) …
Processing triggers for man-db …
Setting up ntp (1:4.2.4p4+dfsg-6ubuntu2.3) …
* Starting NTP server ntpd
…done.

これでパッケージのインストールは完了。つづいて、設定ファイルを編集する。

$ sudo vim /etc/ntp.conf
このntp.confという設定ファイル内にある「server ntp.ubuntu.com」という行をコメントアウトし、あらたに「server ntp.nict.jp」という文字列を三行、追加する。

# server ntp.ubuntu.com
server ntp.nict.jp
server ntp.nict.jp
server ntp.nict.jp

NTPサーバの再起動

$ sudo /etc/init.d/ntp restart

動作確認

 $ sudo ntpq -p
    remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 ntp-b3.nict.go. .NICT.           1 u   45   64    1    8.439  1944422   0.001
 ntp-a2.nict.go. .NICT.           1 u   44   64    1    6.520  1944422   0.001
 ntp-a3.nict.go. .NICT.           1 u   43   64    1    7.686  1944422   0.001

でも、なぜこれが動作確認になるのかよくわかっていない。

このままだと、冒頭のPHPのほうはまだ時刻は修正されないので、Apacheを再起動する。

$ sudo /etc/init.d/apache2 restart
[sudo] password for showjin:
 * Restarting web server apache2
 ... waiting    ...done.

PHPのほうを確認すると、ちゃんと現在時刻になっていた。

 

Tags: , ,

Comments

No comments so far.

  • Leave a Reply
     
    Your gravatar
    Your Name
     
     
     

    コメントリンクを nofollow free に設定することも出来ます。