目的
Raspberry Pi 3B+ に新しい ntpd を入れたい!
オリジナルの ntpd よりもセキュリティーが高く OpenNTPD みたいに機能が削られていない ntpsec を使います。
gpsd 経由で GPS モジュールの PPS 信号を使って同期を取る。→ NTPsec だと時刻合わせの間隔が 1秒毎にできる。
必要なもの
以下のものが入っていること
OpenSSL 1.0.1 以上 (TLS 1.2 が必要)
Python 2.6 以上、又は Python 3.3 以上
python の gps モジュール が必要 (GPS レシーバのモジュールをコンパイルする場合)
python3 を使おうとするとコンパイルの最後で失敗しますので、python2 でいきます。
GPS モジュールのインストール
> sudo pip install gps
ダウンロード ~ コンパイル ~ インストール
refclock に必要なのは shm だけなので、all ではなく shm でコンパイルします。
> curl -O ftp://ftp.ntpsec.org/pub/releases/ntpsec-1.1.7.tar.gz
> tar xzf ntpsec-1.1.7.tar.gz
> cd ntpsec-1.1.7/
> sudo ./buildprep
> ./waf --refclock=shm --prefix=$HOME/opt --python=/usr/bin/python2 configure
> ./waf build -j4
> ./waf install
.....
とインストールすると、インストールがエラーで止まってしまいます。systemd の自動起動スクリプト類ですので、取り敢えずインストール先を /tmp にでも書き換えてしまいましょう。
※これらは後程、手動設定することにします。
> diff -u build/c4che/main_cache.py.orig build/c4che/main_cache.py
--- build/c4che/main_cache.py.orig 2019-10-03 20:16:15.467744311 +0900
+++ build/c4che/main_cache.py 2019-10-03 20:16:33.616631462 +0900
@@ -159,7 +159,7 @@
STLIB_ST = '-l%s'
STRERROR_CHAR = 1
SYSCONFDIR = '/home/pi/opt/etc'
-SYSTEMD_systemdsystemunitdir = '/lib/systemd/system'
+SYSTEMD_systemdsystemunitdir = '/tmp'
cfg_files = ['/home/pi/opt/SRC/ntpsec-1.1.7/build/config.h']
cprogram_PATTERN = '%s'
cshlib_PATTERN = 'lib%s.so'
再度./waf install
してインストールを完了して下さい。
systemd 設定
...続く
ntplogtemp サービスをインストールする
NTPsec に入っている ntplogtemp をサービスとして追加する。
温度が時間安定度に影響を及ぼすかを判断することができる。(間接的に CPU 負荷の影響を知ることもできる)
手順 1. systemd にファイルを追加
[Unit]
Description = temperature recoed daemon (by NTPsec)
[Service]
ExecStart = /home/pi/opt/bin/ntplogtemp -l /var/log/ntpstats/temps -w 300
Restart = always
Type = simple
[Install]
WantedBy = multi-user.target
手順 2. サービスが認識されていることを確認し有効化する
> sudo systemctl daemon-reload
> sudo systemctl list-unit-files --type=service | grep ntplogtemp
ntplogtemp.service disabled
サービスが認識され、無効となっていることを確認
> sudo systemctl enable ntplogtemp
Created symlink /etc/systemd/system/multi-user.target.wants/ntplogtemp.service → /etc/systemd/system/ntplogtemp.service.
> sudo systemctl is-enabled ntplogtemp
enabled
> sudo systemctl status ntplogtemp
● ntplogtemp.service - temperature recoed daemon (by NTPsec)
Loaded: loaded (/etc/systemd/system/ntplogtemp.service; enabled; vendor preset: enabled)
Active: inactive (dead)
サービスが有効化され起動されていないことを確認。
> sudo systemctl start ntplogtemp
> sudo systemctl status ntplogtemp
● ntplogtemp.service - temperature recoed daemon (by NTPsec)
Loaded: loaded (/etc/systemd/system/ntplogtemp.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2019-10-06 19:17:49 JST; 3s ago
Main PID: 15513 (python)
CGroup: /system.slice/ntplogtemp.service
└─15513 python /home/pi/opt/bin/ntplogtemp -l /var/log/ntpstats/temps -w 300
10月 06 19:17:49 Ras1 systemd[1]: Started temperature recoed daemon (by NTPsec).
サービスを起動し、ステータスを確認。