LoginSignup
0
1

More than 3 years have passed since last update.

LinuxでNTP設定メモ

Posted at

CentOS 7でNTPの設定をしてみた

今回、NTPの設定をしてみたので、備忘録兼ねてメモで記載します。
他にも記載されている方もいらっしゃるかとは思いますが、悪しからず。。

まず、初めにおおまかな流れから。

  1. NTPサービスをインストール
  2. ntp.confファイルの設定値を入れる
  3. ntpupdateコマンドで時刻を合わせる
  4. ntpdサービスの開始

では、実際にそれぞれの詳細を記載します。

1.NTPサービスをインストール

※実行する際はrootユーザーです
以下のコマンドでNTPサービスをインストールします。
yum install ntp

2.ntp.confファイルの設定値を入れる

ntp.confの設定ファイルは下記にあります。
/etc/ntp.conf

2-1.
まず、ntp.confのバックアップをとります。
cp -p /etc/ntp.conf /etc/バックアップファイル名(任意).conf

2-2.
次にntp.confファイルの編集をします。
vi /etc/ntp.conf

ntp.confのファイルの中身に以下の内容が記載されているので、「#」でコメントアウトします。
その上で設定したいNTPサーバの情報を記載します。
※今回は例としてNICT(http://jjy.nict.go.jp/ntp/)
のNTPサーバとMULTIFEED(https://www.mfeed.ad.jp/ntp/overview.html)
のNTPサーバを記載します。

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
server ntp1.jst.mfeed.ad.jp
#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

3.ntpupdateコマンドで時刻を合わせる

※時刻がズレているとうまく同期ができないので本手順を実施します。
以下のコマンドを実施します。
date
ntpupdate NTPサーバ
date
1回目のdateではずれている可能性がありますが、ntpupdateを実施したあとの2回目のdateでは時刻があっています。

4.ntpdサービスの開始

以下のコマンドを実施しNTPサービスをを再起動します。
service ntpd restart

NTPサービスがrunningになっていることを確認します。
service ntpd status

0
1
1

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
0
1