ntpをインストールしLINUXサーバの時刻を修正

May 30, 2019 – 7:25 am

最近、crontabの時刻が実時間とズレを持つようになっているのに気づいた。

この原因、我がLinuxサーバの時刻のズレにあった。サーバー更新時に時刻同期用のntpをインストールしてなかったため、こういう事態が生じたようだ。Linuxの時計が狂うのは電池のヘタリの兆候なんてことも考えてみた。

ということで、ntpをインストールし、デーモンを動作させることにした。

以下、作業ログを記録しておいた。

nptのインストールログ

[root@localhost ~]# yum -y install ntp
 (省 略)
Dependencies Resolved
===============================================================================================================================
 Package                          Arch                    Version                                  Repository             Size
===============================================================================================================================
Installing:
 ntp                              x86_64                  4.2.6p5-28.el7.centos                    base                  549 k
Installing for dependencies:
 autogen-libopts                  x86_64                  5.18-5.el7                               base                   66 k
 ntpdate                          x86_64                  4.2.6p5-28.el7.centos                    base                   86 k

Transaction Summary
===============================================================================================================================
Install  1 Package (+2 Dependent packages)
(以下、省略)

/etc/ntp.confの設定とntpデーモンの動作開始

# 18行目: 時刻同期を許可する範囲を追記
restrict 10.0.0.0 mask 255.255.255.0 nomodify notrap
# 同期をとるサーバーを変更
#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
server ntp.nict.jp iburst
server ntp1.jst.mfeed.ad.jp iburst
server ntp2.jst.mfeed.ad.jp iburst
[root@localhost ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
[root@localhost ~]# firewall-cmd --add-service=ntp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success

動作確認

[root@localhost ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ntp-a2.nict.go. .NICT.           1 u   47   64    1   18.643    1.052   0.915
+ntp1.jst.mfeed. 133.243.236.17   2 u   46   64    1   14.861   -0.988   1.651
+ntp2.jst.mfeed. 133.243.236.17   2 u   45   64    1   17.495   -3.019   0.979

Post a Comment