CentOSでntpサーバと時刻を同期する
vagrantでCentOSを仮想マシン上で立ち上げて使っているけど、時間設定しないとだったので。
まずタイムゾーン設定
$ date 2014年 6月 29日 日曜日 05:40:37 UTC
(ここら辺はとりとめもない独り言)
/usr/share/zoneinfo
の中の適切なファイルを/etc/localtime
にコピー、でもいいがtzselect
使うか。あ、これは環境変数TZの設定方法を教えてくれるだけで、実際には変更しないw すぐに反映されるわけでもない。
tzconfig
がいいのかな。tzconfigがない・・・だと?
(独り言終わり)
tzselect
で一応確認した後、
/home/vagrant/.bash_profile
を編集、export TZ="Asia/Tokyo"
を追加
# .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin export PATH export TZ="Asia/Tokyo"
source .bash_profile
で変更内容反映。
env
で確認。TZ=Asia/Tokyo
があった。
$ date 2014年 6月 29日 日曜日 15:01:52 JST
JSTになってるー。
ntpで時刻同期
ここを参考に
CentOSにntpサーバを入れて、日本標準時刻に自動的に合わせるためのメモ - Qiita
$ sudo vi 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で参照するようにするものらしい。
NICTとDebianの時刻同期をIPv4に固定する - labunix の ラボゆにっくす
上記記事はDebianでの例だが。
編集後、スタート
$ sudo service ntpd start Starting ntpd: [ OK ]
ステイタス確認
$ ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== *ntp-b2.nict.go. .NICT. 1 u 50 64 37 104.977 -157.39 92.921 +ntp1.jst.mfeed. 133.243.236.19 2 u 34 64 77 105.378 -169.13 127.393 +ntp2.jst.mfeed. 133.243.236.17 2 u 44 64 77 108.712 -159.79 111.898 +ntp3.jst.mfeed. 172.29.3.50 2 u 49 64 77 104.008 -160.66 118.294
この、サーバ名の前に*とか+がでるまでにちょっと時間はかかりますが、まあ気長に。
自動起動の設定
$ sudo chkconfig ntpd on $ chkconfig --list ntpd ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off