1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

docker-machine で作ったEC2上にntp を設定

Last updated at Posted at 2019-07-29

docker-machine で作ったEC2 のホストで時間が無茶苦茶ズレている事に気づいた。
ntp を設定する

$ docker-machine ssh my-machine
$ sudo apt update
$ sudo apt install chrony
$ sudo vi /etc/chrony/chrony.conf
server 169.254.169.123 prefer iburst minpoll 4 maxpoll 4
# ↑pool の前の行にこの行を追加
pool 2.debian.pool.ntp.org offline iburst

## 中略一番下
# ポートを無効化してサーバーとして動作させない
pool 0
$ sudo systemctl restart chrony
$ chronyc sources -v
210 Number of sources = 5

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^* 169.254.169.123               3   4   377     0  -2985ns[-3000ns] +/-  430us
^- ntp.netviscom.com             2   6    37     1  +6070us[+6070us] +/-   82ms
^- 74.208.26.225                 1   6    37     2  +6171us[+6171us] +/-   39ms
^- 0.time.dbsinet.com            2   6    37     1   +816us[ +816us] +/-   55ms
^- ha82.smatwebdesign.com        2   6    37     1   +828us[ +828us] +/-   61ms

返される出力では、^* が優先時刻ソースを示します。

とのこと

すでに時間がめっちゃズレているので 強制的に合わせる
password は root のパスワードではなく、 /etc/chrony/chrony.keys に書いてある

$ sudo chronyc
chrony version 2.1.1
Copyright (C) 1997-2003, 2007, 2009-2015 Richard P. Curnow and others
chrony comes with ABSOLUTELY NO WARRANTY.  This is free software, and
you are welcome to redistribute it under certain conditions.  See the
GNU General Public License version 2 for details.

chronyc> password
Password: # ここ
200 OK
chronyc> makestep
200 OK
chronyc> ^D

時間が合ったら成功

ubuntu@tdb-dev:~$ date
Wed Jul 17 02:25:30 UTC 2019
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?