LoginSignup
10
5

More than 5 years have passed since last update.

CentOS7で時間のずれを調整してみた

Last updated at Posted at 2017-11-20

CentOS7、64bit環境の時刻を調整します。

$ cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
$ arch
x86_64

現在時刻を確認します。

$ date
2017年 11月 20日 月曜日 06:40:09 UTC

今は15:40くらい。UTCに設定されているので当然9時間ずれています。タイムゾーンを設定して再度時刻を確認します。

$ sudo timedatectl set-timezone Asia/Tokyo
$ date
2017年 11月 20日 月曜日 15:40:45 JST

直った。と思いたいのですがなんか2分くらいずれています。こちらを参考にさらに調整してみます。

chronydをyumでインストールします。

$ sudo yum install -y chronyd
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
パッケージ chrony-3.1-2.el7.centos.x86_64 はインストール済みか最新バージョンです
何もしません

Vagrant+VirrualBox+bento/centos-7.3の場合は最初から入っているようです。chronydを起動します。

$ sudo systemctl start chronyd

状態をチェック

$ systemctl status chronyd
● chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
   Active: active (running) since 月 2017-11-20 14:51:31 JST; 59min ago
     Docs: man:chronyd(8)
           man:chrony.conf(5)
 Main PID: 5613 (chronyd)
   CGroup: /system.slice/chronyd.service
           └─5613 /usr/sbin/chronyd

動いていますね。一旦停止して再度状態をチェックします。

$ sudo systemctl stop chronyd
$ systemctl status chronyd
● chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since 月 2017-11-20 15:59:07 JST; 8s ago
     Docs: man:chronyd(8)
           man:chrony.conf(5)
 Main PID: 5613 (code=exited, status=0/SUCCESS)

止まっています。再起動しましょう。

$ sudo systemctl restart chronyd

起動時にサービスを自動的に起動するようにします。

$ sudo systemctl enable chronyd

設定をしていきます。

$ sudo vi /etc/chrony.conf

参照サーバの再設定 + 時刻同期許可設定です

/etc/chrony.conf

#デフォルトの参照サーバをコメントアウト
# 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 ntp1.jst.mfeed.ad.jp
server ntp2.jst.mfeed.ad.jp
server ntp3.jst.mfeed.ad.jp

#LAN内のマシンからの時刻同期許可
Allow 192.168.33.10

設定が終了したらサービスを再起動して時刻を確認します。

$ chronyc sources
210 Number of sources = 4
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* sv01.azsx.net                 2   6   377    54  -1225us[-1973us] +/- 6313us
^- secure.opticnerve.asia        2   6   377    56   -820us[-1568us] +/-   81ms
^- x.ns.gin.ntt.net              2   6   377    55  +3749us[+3749us] +/-   78ms
^- 34nm.com                      2   6   157    54  +3836us[+3836us] +/-  186ms
$ date
2017年 11月 20日 月曜日 16:07:39 JST

ずれてない。直りました。

こんなの自分でできないですよね。。。

10
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
5