CentOS の時刻を、日本時刻に設定する手順を書いていきます。NTP で日本標準時と同期して、タイムゾーンを JST に変更します。
※ 作業は全て root で実施しました。
手順1. NTP インストール
yum
で NTP をインストールします
# yum install ntp
手順2. 時刻合わせ
ntpdate
で時刻を合わせます。
# ntpdate ntp.nict.jp
コマンドの引数「ntp.nict.jp」は、NICT の NTPサーバです。
手順3. /etc/ntp.conf の編集
vi などで /etc/ntp.conf
の一部を、次のとおり変更します。
変更前
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 -4 ntp.nict.jp server -4 ntp1.jst.mfeed.ad.jp server -4 ntp2.jst.mfeed.ad.jp server -4 ntp3.jst.mfeed.ad.jp
変更後の「server -4」は、IPv4 で NTP サーバに接続するということです。2~3行目の接続先は MFEED のサーバで、NICT と同期しているみたいです。
手順4. ntpd の起動
次のコマンドで、NTP のデーモンを起動します。
# service ntpd start
手順5. ntpd の起動設定
次のコマンドを実行します。次回のサーバ起動時は、自動で NTP デーモンが起動するようになります。
# chkconfig ntpd on
手順6. タイムゾーンの確認
date コマンドで、タイムゾーンが UTC であることを確認します。
# date Fri Mar 27 03:10:36 UTC 2015
UTC の箇所が JST だったら、次の手順は不要になります。
手順7. タイムゾーンの変更
まずは、現在のタイムゾーンのバックアップを取ります(任意)。
# cp /etc/localtime /etc/localtime.bak
# cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
手順8. 日時の確認
date
コマンドで、日時が正しいか確認します。
# date Fri Mar 27 12:16:23 JST 2015