CentOS7 での時刻同期について紹介します。
概要
CentOS7では時刻同期は、Chrony Chronydを利用します。
Chronyd の状態確認
Chronyd が起動しているか確認します。通常はデフォルトで自動起動する設定になっています。
systemctl status Chronyd.service
コマンドを実行します。
サービスの起動
サービスが起動していない場合は、サービスを起動します。
systemctl start Chronyd.service
コマンドでサービスを起動できます。
サービスの停止
systemctl stop Chronyd.service
コマンドでサービスを停止できます。
Chronyd の設定変更
Chronydの設定は /etc/chrony.conf ファイルに記載されています。
デフォルトでは、0.centos.pool.ntp.org, 1.centos.pool.ntp.org, 2.centos.pool.ntp.org, 3.centos.pool.ntp.org のNTPサーバーを参照する設定になっています。参照する、NTPサーバーを変更する場合は、先頭部分を編集します。
また、このサーバーを参照して時刻同期するクライアントがある場合は、allow にクライアントのIPアドレス、またはネットワークアドレスを追記します。(#allow 192.168/16 の部分のコメントを外し、ネットワークアドレスを変更します。)
/etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
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
# Ignore stratum in source selection.
stratumweight 0
# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift
# Enable kernel RTC synchronization.
rtcsync
# In first three updates step the system clock instead of slew
# if the adjustment is larger than 10 seconds.
makestep 10 3
# Allow NTP client access from local network.
#allow 192.168/16
# Listen for commands only on localhost.
bindcmdaddress 127.0.0.1
bindcmdaddress ::1
# Serve time even if not synchronized to any NTP server.
#local stratum 10
keyfile /etc/chrony.keys
# Specify the key used as password for chronyc.
commandkey 1
# Generate command key if missing.
generatecommandkey
# Disable logging of client accesses.
noclientlog
# Send a message to syslog if a clock adjustment is larger than 0.5 seconds.
logchange 0.5
logdir /var/log/chrony
#log measurements statistics tracking
著者
かつて日本を代表したスーパーエンジニア (自称)
ハードウェア、電気設備、ガーデニング関係の記事を担当。
最終更新日: 2024-01-04
作成日: 2016-09-05