[CentOS] yum で NTP をインストールして時刻同期させ自動起動させる方法【設定ファイルの編集不要で簡単】

CentOS を NTP で時刻同期させる設定です。CentOS のバージョンは 6.6 です。

# cat /etc/redhat-release
CentOS release 6.6 (Final)
#

まず yum を使って NTP サーバーをインストールします。

# yum info ntp.i686
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
* base: www.ftp.ne.jp
* extras: www.ftp.ne.jp
* updates: www.ftp.ne.jp
利用可能なパッケージ
名前 : ntp
アーキテクチャ : i686
バージョン : 4.2.6p5
リリース : 5.el6.centos
容量 : 589 k
リポジトリー : base
要約 : The NTP daemon and utilities
URL : http://www.ntp.org
ライセンス : (MIT and BSD and BSD with advertising) and GPLv2
説明 : The Network Time Protocol (NTP) is used to synchronize a computer’s
: time with another reference time source. This package includes ntpd
: (a daemon which continuously adjusts system time) and utilities used
: to query and configure the ntpd daemon.
:
: Perl scripts ntp-wait and ntptrace are in the ntp-perl package and
: the ntpdate program is in the ntpdate package. The documentation is
: in the ntp-doc package.
# yum install ntp.i686
読み込んだプラグイン:fastestmirror
インストール処理の設定をしています
Loading mirror speeds from cached hostfile
* base: www.ftp.ne.jp
* extras: www.ftp.ne.jp
* updates: www.ftp.ne.jp
依存性の解決をしています
–> トランザクションの確認を実行しています。
—> Package ntp.i686 0:4.2.6p5-5.el6.centos will be インストール
–> 依存性の処理をしています: ntpdate = 4.2.6p5-5.el6.centos のパッケージ: ntp-4.2.6p5-5.el6.centos.i686
–> トランザクションの確認を実行しています。
—> Package ntpdate.i686 0:4.2.6p5-5.el6.centos will be インストール
–> 依存性解決を終了しました。依存性を解決しました============================================================================================================================
パッケージ アーキテクチャ バージョン リポジトリー 容量
============================================================================================================================
インストールしています:
ntp i686 4.2.6p5-5.el6.centos base 589 k
依存性関連でのインストールをします。:
ntpdate i686 4.2.6p5-5.el6.centos base 76 kトランザクションの要約
============================================================================================================================
インストール 2 パッケージ総ダウンロード容量: 665 k
インストール済み容量: 1.7 M
これでいいですか? [y/N]y
パッケージをダウンロードしています:
(1/2): ntp-4.2.6p5-5.el6.centos.i686.rpm | 589 kB 00:00
(2/2): ntpdate-4.2.6p5-5.el6.centos.i686.rpm | 76 kB 00:00
—————————————————————————————————————————-
合計 933 kB/s | 665 kB 00:00
rpm_check_debug を実行しています
トランザクションのテストを実行しています
トランザクションのテストを成功しました
トランザクションを実行しています
インストールしています : ntpdate-4.2.6p5-5.el6.centos.i686 1/2
インストールしています : ntp-4.2.6p5-5.el6.centos.i686 2/2
Verifying : ntpdate-4.2.6p5-5.el6.centos.i686 1/2
Verifying : ntp-4.2.6p5-5.el6.centos.i686 2/2インストール:
ntp.i686 0:4.2.6p5-5.el6.centos依存性関連をインストールしました:
ntpdate.i686 0:4.2.6p5-5.el6.centos完了しました!
#

これでインストールが終了しました。

続いて NTP サーバーを起動させます。

設定ファイルは /etc/ntp.conf ですが特に何も設定する必要はありません。最初から NTP サーバーの情報などが定義されています。最近の NTP サーバーの設定は楽になっています。

# service ntpd status
ntpd is stopped
# service ntpd start
Starting ntpd: [ OK ]
# ps -ef | grep ntp
ntp 1795 1 0 21:05 ? 00:00:00 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g
root 1798 1694 0 21:05 pts/0 00:00:00 grep ntp
#

時刻同期できたかどうかを ntpq コマンドで確認します。

# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
+60-56-214-78f2. .GPS. 1 u 22 64 1 18.919 -0.501 0.286
*nipper.paina.jp 131.112.181.48 2 u 25 64 1 3.711 -0.779 2.741
+y.ns.gin.ntt.ne 103.1.106.69 2 u 25 64 1 11.320 -1.349 2.646
-chobi.paina.jp 131.112.181.48 2 u 25 64 1 6.267 -1.704 0.717
#

一番左に米印のついたサーバーと同期が取れています。

最後に OS 起動時に NTP が動くように設定をしておきます。chkconfig コマンドを使います。

# chkconfig –list | grep ntp
ntpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
ntpdate 0:off 1:off 2:off 3:off 4:off 5:off 6:off
# chkconfig ntpd on
# chkconfig –list | grep ntp
ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
ntpdate 0:off 1:off 2:off 3:off 4:off 5:off 6:off
#

これで終了です。OS を再起動しても次回からは ntpd が自動起動して NTP サーバーと時刻同期を始めてくれます。

ホント、簡単になった。Linux の進化はすごいなあとまた感じてしまいました。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください