Chronyを使用してLinuxの時刻を日本標準時と合わせる方法。
1.Chronyのインストール
[bash]
yum install -y chrony
[/bash]
2.Chronyの設定ファイル
/etc/chrony.confが設定ファイル。
ファイルの中身は下記。
[bash]
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
[/bash]
3.NICTと同期する設定を追記
viなどで上記ファイルを開き、
[bash] [root@localhost ~] # vi /etc/chrony.conf [/bash]
server 3.centos.pool.ntp.org iburst の後に下記を追記
[bash] server ntp.nict.jp iburst [/bash]
「Esc」キー→「:wq」→「Enter」キーで保存
4.自動起動の設定
[bash] [root@localhost ~] # systemctl enable chronyd [/bash]
5.同期されているか確認
[bash] [root@localhost ~] # systemctl status chronyd [/bash]
下記のように表示される。
[bash] ● chronyd.service - NTP client/server Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled) Active: active (running) since 月 2017-01-09 17:22:01 JST; 5h 15min ago Main PID: 654 (chronyd) CGroup: /system.slice/chronyd.service mq654 /usr/sbin/chronyd
1月 09 17:21:59 localhost.localdomain chronyd[654]: chronyd version 2.1.1 s... 1月 09 17:22:01 localhost.localdomain chronyd[654]: Frequency -11.743 +/- 0... 1月 09 17:22:14 localhost.localdomain chronyd[654]: Selected source 133.130... 1月 09 17:22:14 localhost.localdomain chronyd[654]: System clock wrong by 2... Hint: Some lines were ellipsized, use -l to show in full. [/bash]
※参考サイト http://qiita.com/Kenji_TAJIMA/items/88ec9985a0585e66ef33
時刻合わせのためntpdateコマンドをインストール
ntpdateコマンドを実行して、以下のように表示される場合はntpdateコマンドがインストールされていない。
[bash] [root@localhost ~]# ntpdate ntp.nict.jp -bash: ntpdate: コマンドが見つかりません [/bash]
ntpdateコマンドをインストール。
[bash] [root@localhost ~]# yum list ntpdate [/bash]
ntpdateコマンドがインストールされたか確認。
[bash] [root@localhost ~]# rpm -q ntpdate ntpdate-4.2.6p5-25.el7.centos.2.x86_64 [/bash]
ntpdateコマンドで時刻を合わせる。
[bash] [root@localhost ~]# ntpdate ntp.nict.jp 26 May 07:21:22 ntpdate[31838]: adjust time server 133.243.238.244 offset -0.000194 sec [/bash]
現在時刻を確認
[bash] [root@localhost ~]# date 2017年 5月 26日 金曜日 07:21:49 JST [/bash]