- 1. 概要
- 2. ports
- 3. /etc/ntp.conf 設定
- 4. /etc/rc.conf 設定
- 5. 起動スクリプトの修正
- 6. 時刻の同期を確かめる
- 7. 起動できないとき
- 8. ログローテーションの設定
1. 概要
「ntp」についての説明は「ウィキペディア - ntp」を参照ください。
2. ports
「ntpd」は比較的長い歴史のあるプログラムですが、案外、頻繁に更新が行われます。
デフォルトで「/usr/sbin/ntpd」が存在していますが。
「ports」から、最新版を取得して、更新が発生したらすぐに適用できるようにしておきます。
cd /usr/ports/net/ntp
make config
オプションがすごく多くなっていますが、デフォルトのままで問題ないかと思います。
一応、オプションを掲載しておきます。
cd /usr/ports/net/ntp
make NO_DIALOG=yes
make reinstall
インストール時のメッセージを掲載しておきます。
===> Deinstalling for ntp
===> ntp not installed, skipping
===> Installing for ntp-4.2.8p18_4
===> Checking if ntp is already installed
===> Registering installation for ntp-4.2.8p18_4
Installing ntp-4.2.8p18_4...
Please add
ntpd_program="/usr/local/sbin/ntpd"
ntpdate_program="/usr/local/sbin/ntpdate"
to your /etc/rc.conf or run
sysrc ntpd_program="/usr/local/sbin/ntpd"
sysrc ntpdate_program="/usr/local/sbin/ntpdate"
to enable ntp from ports/packages instead of base ntp.
===> SECURITY REPORT:
This port has installed the following files which may act as network
servers and may therefore pose a remote security risk to the system.
/usr/local/sbin/ntpdate
/usr/local/sbin/sntp
/usr/local/sbin/ntpd
If there are vulnerabilities in these programs there may be a security
risk to the system. FreeBSD makes no guarantee about the security of
ports included in the Ports Collection. Please type 'make deinstall'
to deinstall the port if this is a concern.
For more information, and contact details about the security
status of this software, see the following webpage:
https://www.ntp.org/
3. /etc/ntp.conf 設定
「ntp」サーバのコンフィグレーションファイルを編集します。
vi /etc/ntp.conf
自分の上位となる「ntp」サーバの「IP」アドレスを記述します。
「ntp」サーバには、「stratum」という階層構造があります。
一般サーバの「stratum」は、3 か 4 に位置しますので、上位の「ntp」サーバには「stratum」が、2 か 3 あたりのサーバを設定します。
通常は、プロバイダから少なくとも 1 つの「ntp」サーバアドレスを指示してくれているはずです、1 つはそのアドレスを設定します。
こちらを御覧になれば、「ntp」サーバについて情報が得られます。
「ntp」サーバアドレスは、3 つくらい選びます。
複数のサーバとの時刻差を計測することでより正確な時刻が得られます。
仮に、3つの「ntp」サーバの「IP」アドレスに「210.173.160.27」「29.250.35.251」「216.239.35.4」を使用するします。
以下をコメントアウトし。
# The option `iburst' is used for faster initial synchronization.
#
pool 0.freebsd.pool.ntp.org iburst
pool 2.freebsd.pool.ntp.org iburst
最下行に以下のように記述します。
server 210.173.160.27
server 129.250.35.251
server 216.239.35.12
もし、ログファイルを残したいのであれば、以下の記述を加えます。
logfile /var/log/ntpd.log
ログファイルを残す場合、適切なタイミングでローテーションさせるようにします。
ローテーションのさせかたは末尾の方で・・・。
ローカルネットワークアドレスが、「192.168.0.0」で、ローカルネットワーク内のマシンに同期を許可する場合は、以下の記述を加えます。
restrict 192.168.0.0 mask 255.255.0.0 noquery nomodify nopeer notrap
4. /etc/rc.conf 設定
「ntpd」の起動を設定します。
「root」ユーザ権限で。
service ntpd enable
5. 起動スクリプトの修正
起動スクリプトを書き換えます。
「root」ユーザ権限で。
vi /etc/rc.d/ntpd
command="/usr/sbin/${name}"
の部分を(バージョンにより時々、行番号が変わります)。
command="/usr/local/sbin/${name}"
と書き換えます。
ここまで終わったら。
service ntpd start
で起動します。
6. 時刻の同期を確かめる
時刻の同期を確かめるには、
ntpq -p
というコマンドを使います。
起動・再起動直後には、
remote refid st t when poll reach delay offset jitter
==============================================================================
ntp1.jst.mfeed. 133.243.236.17 2 u 4 64 1 23.365 +365.21 0.061
y.ns.gin.ntt.ne 129.250.35.222 2 u 3 64 1 31.630 +359.31 0.061
time4.google.co .GOOG. 1 u 2 64 1 54.875 +363.82 0.061
てな表示になっていると思います。
起動後、長い場合は、15分以上たたないと、時刻の同期は完了しません。
remote refid st t when poll reach delay offset jitter
==============================================================================
+ntp1.jst.mfeed. 133.243.236.17 2 u 26 64 377 21.574 +1.208 3.384
+y.ns.gin.ntt.ne 129.250.35.222 2 u 42 64 377 28.031 -2.854 2.420
*time4.google.co .GOOG. 1 u 12 64 377 53.441 -4.208 3.331
という具合に、ホスト名の前に「*」マークが表示されれば時刻の同期は完了です。
ホスト名の前のマークが同期の状態を示していて以下の意味を持ちます。
| マーク | 意 味 |
| '*' | 参照同期中であると宣言されたサーバ |
| '#' | 参照可能だが, 同期距離が遠いサーバ |
| '+' | 接続テストに合格し, いつでも参照可能なサーバ. 参照リストにある(好ましい)サーバ |
| ' ' | 同期を試み中, もしくはレスポンスがないため, 参照していないサーバ |
| 'x' | falseticker検査で, 参照リストから外れたサーバ |
| '-' | クラスタリング検査で, 参照リストから外れたサーバ |
| '.' | 参照リストから外れたサーバ |
| 'o' | 参照同期中であると宣言されたサーバ(同期はPPS信号から間接的に行なう) |
7. 起動できないとき
「ntpd」は親サーバと 1000秒以上時刻が離れていると停止します。
そもそも 1000秒以上 時刻が離れた状態からの起動はできません。
そういう場合は。
date 1606131627
と「date」コマンドで時刻を合わせる(上記の例は「YYMMDDHHMI」の形式)か。
ntpdate "NTP サーバのホスト名もしくは IP アドレス"
で時刻合わせをします。
時刻合わせ後にサーバを起動します。
8. ログローテーションの設定
「/etc/ntp.conf」でログを出力する設定を行っている場合、ログローテーションの設定をしておきます。
vi /etc/newsyslog.conf.d/ntpd.conf
下記を記述します。
# logfilename [owner:group] mode count size when flags [/pid_file] [sig_num]
/var/log/ntpd.log 644 3 100 * B
「ntpd」のログは、そんなに多くありませんので、100KB で世代交代、3世代管理にしています。
|