RasbibanにインストールされているNTP(時刻合わせプログラム)をより高機能(基板の水晶振動子のずれも補正してくれる)chronyに入れ替えます。
また、Raspberry Piにはリアルタイムクロック(RTC:シャットダウン時も内蔵電源で時間を保持しておく。起動時に読み込まれる。)が無いのでその対策をします。
参考URL
どうでもいい日記帳
Day After Day
PCリンクス
半歩先
ntpを止める
sudo chkconfig ntp off
chronyのインストール
sudo apt-get install chrony
(途中の質問はy)
chrony設定ファイルの修正
sudo cp /etc/chrony/chrony.conf /etc/chrony/chrony.conf.org
sudo vi /etc/chrony/chrony.conf
20行目付近の問い合わせ先サーバを日本のサーバーに変更します。
#server 0.debian.pool.ntp.org offline minpoll 8 ←もとのサーバーをコメントアウト(以下3行も)
#server 1.debian.pool.ntp.org offline minpoll 8
#server 2.debian.pool.ntp.org offline minpoll 8
#server 3.debian.pool.ntp.org offline minpoll 8
server ntp.nict.jp minpoll 12 maxpoll 14 ←日本のNTPサーバーを追加(以下2行も)
server ntp.jst.mfeed.ad.jp minpoll 12 maxpoll 14
server ntp.ring.gr.jp minpoll 12 maxpoll 14
chronyを再起動
sudo /etc/init.d/chrony restart
これで設定が反映されます。
起動時の時刻合わせ
始めに書きましたがRPiにはRTCが無いので起動時に大きく時間が狂ってたりします。
時間が大きく狂っているとchronyが止まることがあるようなので
そうならないように起動時に一発時間を合わせてやります。
ntpdateのインストール
sudo apt-get install ntpdate
起動時にntpdateを実行するようにする
sudo cp /etc/rc.local /etc/rc.local.org
sudo vi /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will “exit 0” on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
ntpdate jp.pool.ntp.org ←この行を追加
# Print the IP address
_IP=$(hostname -I) || true
if [ “$_IP” ]; then
printf “My IP address is %s\n” “$_IP”
fi
exit 0
一度再起動してみます。
sudo reboot
ログインしたら現在の時刻を表示
date
Sun Apr 13 12:45:55 JST 2014
きちんと現在の時刻が表示されました。
今回はここまでです。
次回はSSHのログイン方式を暗号鍵方式に変更します。
2014年4月12日作成
2014年5月5日草稿公開