[CentOS 7] ntp を使って時刻同期させる為、yum でインストールする方法と設定内容

CentOS 7 からは ntp の代わりに chrony (chronyd) を使う、と書いているブログが多いみたいですが ntp でマズイ理由がわからないので僕は ntp をインストールすることにします。

yum でインストールするのでまずパッケージ名を調べます。

$ yum search ntp | grep 64
ntp.x86_64 : The NTP daemon and utilities
ntpdate.x86_64 : Utility to set the date and time via NTP
chrony.x86_64 : An NTP client/server
cyrus-imapd.x86_64 : A high-performance mail server with IMAP, POP3, NNTP and
sntp.x86_64 : Standard Simple Network Time Protocol program
$

ntp.x86_64 をインストールすれば良さそうなのでさっそくインストールします。

$ sudo yum install ntp.x86_64
[sudo] password for oredayo:
読み込んだプラグイン:fastestmirror
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
updates/7/x86_64/primary_db | 3.2 MB 00:00:10
Loading mirror speeds from cached hostfile
* base: ftp.riken.jp
* extras: ftp.riken.jp
* updates: ftp.riken.jp
依存性の解決をしています
–> トランザクションの確認を実行しています。
—> パッケージ ntp.x86_64 0:4.2.6p5-22.el7.centos.1 を インストール
–> 依存性の処理をしています: ntpdate = 4.2.6p5-22.el7.centos.1 のパッケージ: ntp-4.2.6p5-22.el7.centos.1.x86_64
–> 依存性の処理をしています: libopts.so.25()(64bit) のパッケージ: ntp-4.2.6p5-22.el7.centos.1.x86_64
–> トランザクションの確認を実行しています。
—> パッケージ autogen-libopts.x86_64 0:5.18-5.el7 を インストール
—> パッケージ ntpdate.x86_64 0:4.2.6p5-22.el7.centos.1 を インストール
–> 依存性解決を終了しました。依存性を解決しました====================================================================================================================================
Package アーキテクチャー バージョン リポジトリー 容量
====================================================================================================================================
インストール中:
ntp x86_64 4.2.6p5-22.el7.centos.1 updates 543 k
依存性関連でのインストールをします:
autogen-libopts x86_64 5.18-5.el7 base 66 k
ntpdate x86_64 4.2.6p5-22.el7.centos.1 updates 84 kトランザクションの要約
====================================================================================================================================
インストール 1 パッケージ (+2 個の依存関係のパッケージ)総ダウンロード容量: 693 k
インストール容量: 1.6 M
Is this ok [y/d/N]: y
Downloading packages:
(1/3): autogen-libopts-5.18-5.el7.x86_64.rpm | 66 kB 00:00:00
(2/3): ntpdate-4.2.6p5-22.el7.centos.1.x86_64.rpm | 84 kB 00:00:00
(3/3): ntp-4.2.6p5-22.el7.centos.1.x86_64.rpm | 543 kB 00:00:01
————————————————————————————————————————————
合計 352 kB/s | 693 kB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
インストール中 : autogen-libopts-5.18-5.el7.x86_64 1/3
インストール中 : ntpdate-4.2.6p5-22.el7.centos.1.x86_64 2/3
インストール中 : ntp-4.2.6p5-22.el7.centos.1.x86_64 3/3
検証中 : ntp-4.2.6p5-22.el7.centos.1.x86_64 1/3
検証中 : ntpdate-4.2.6p5-22.el7.centos.1.x86_64 2/3
検証中 : autogen-libopts-5.18-5.el7.x86_64 3/3インストール:
ntp.x86_64 0:4.2.6p5-22.el7.centos.1依存性関連をインストールしました:
autogen-libopts.x86_64 0:5.18-5.el7 ntpdate.x86_64 0:4.2.6p5-22.el7.centos.1完了しました!
$

あとは ntpd のプロセスを起動してあげます。systemctl コマンドでいきましょう。まず systemctl status ntpd で確認します。

$ systemctl status ntpd
● ntpd.service – Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)
$

inactive になっているのが確認できますので起動します。

$ systemctl start ntpd
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: root
Password:
==== AUTHENTICATION COMPLETE ===
$

sudo をうっかり入れ忘れたら root のパスワードを入れよ!と指示してきたので root のパスワードをいれてあげたら ntpd を起動できたみたいです。

やるやないけ CentOS 使いやすくなってやがるな。

$ systemctl status ntpd
● ntpd.service – Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
Active: active (running) since 水 2016-03-23 06:57:04 JST; 8h left
Process: 2917 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 2918 (ntpd)
CGroup: /system.slice/ntpd.service
└─2918 /usr/sbin/ntpd -u ntp:ntp -g
$

ntpd のステータスをもう一回確認するとちゃんと active に変わりました。

$ which ntpq
/usr/sbin/ntpq
$ ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
+v157-7-235-92.z 103.1.106.69 2 u 50 64 7 5.086 1.898 1.737
-y.ns.gin.ntt.ne 249.224.99.213 2 u 52 64 7 3.720 -2.406 1.587
+chobi.paina.jp 131.112.125.48 2 u 49 64 7 5.484 1.432 1.233
*sv2.localdomain 133.243.238.243 2 u 48 64 7 4.993 1.517 1.270
$

ntpq コマンドもインストールされたみたいなので時刻同期の状況を ntpq -p で確認してみると、もう同期されていました。

設定ファイルに NTP サーバーをねちねち書かなくていいって本当楽ちん。いいぞ〜、セントオーエース!引続き使いやすくてステーブルなサーバーとして頑張ってくれー!!

コメントを残す

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

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