オーナーの部屋

Windows の部屋

Windows 11

Windows 10

Windows 8,7,XP

Linux の部屋

色々なLinux

古いPCにLinuxを

Linuxサーバー

CentOS

CentOS ?

CentOS-1

 - DownLoad -

CentOS-2

 - Install-1 -

CentOS-3

 - パーティション設定 -

CentOS-4

 - Install-2 -

CentOS-5

 - パッケージグループ -

CentOS-6

 - 基本設定 -

CentOS-7

 - ntpdの構築 -

CentOS-8

 - sambaの設定 -

CentOS-9

 - apacheの設定 -

CentOS-10

 - プリンタサーバの設定 -

Vine Linux

Android の部屋

PCの遍歴

徒然なるままに・・

インストール (その7)

ntpd の構築

CentOS のインストール、基本的な設定が終ったら、最初に設定します。
インターネット上で世界標準時時刻 (GMTやUTC) を発信している「NTPサーバー」に接続し、自動的に、サーバー機の時計の時刻調整を行う設定を示します。
これにより、サーバー機の時計の誤差を気にしなくても良くなります。

CentOS 5 を インストール すると、ntpd とその設定に必要なファイル類は、既にサーバーにインストールされています。
CentOS にインストールされている ntpd で、操作や設定が必要なファイルを以下に示します。

ntpd の本体プログラムは "/usr/sbin/ntpd" ですが、これを直接呼び出すことはまずなく、実際にはこの "/usr/sbin/ntpd" を用いて、 起動や終了を容易にコントロールできるように記述された スクリプトである "/etc/rc.d/init.d/ntpd" を用います。
また、ntpd の設定ファイルは "/etc/ntp.conf" です。

例えば、以下のような使い方になります。

"/etc/init.d/ntpd start"

← ntpd の起動

"/etc/init.d/ntpd stop"

← ntpd の停止

■ "/etc/ntp.conf" の編集

(1)

ネット内のクライアント機から (SSHで) 、サーバーにログインする

(2)

su コマンドで "root" に変更し、 cp コマンドでバックアップを作成する

(3)

nano エディタで "/etc/ntp.conf" を開き編集する (下記参照)

[xxx@xxxx]$ su - [Ent]

← "root" に変更

パスワード: ・・・・・・・・ [Ent]

← パスワード入力(表示されない)

[xxx@xxxx]# cp /etc/ntp.conf /etc/ntp.conf.org [Ent]

← バックアップ作成

[xxx@xxxx]# nano /etc/ntp.conf [Ent]

← "/etc/ntp.conf"を開く

(4)

"/etc/ntp. conf" を保存し、nanoエディタを終了します。

( [Ctrl] + [x] → 保存確認( y or n ) → y:保存ファイル名の変更 (上書き/変更し [Ent] )
※ [Ctrl] + [c] で保存のキャンセルができる

(5)

ntpd の起動または再起動を行って設定を有効化します。

< 停止と起動 >

/etc/init.d/ntpd stop 「Ent]

← ntpd の停止

/etc/init.d/ntpd start [Ent]

← ntpd の起動

< 再起動 >

/etc/init.d/ntpd restart [Ent]

← ntpd の再起動

(6)

ntpd が稼動してるかどうかを確認します。
以下の "status" コマンドと "ps" コマンドで起動プロセスを確認します。

/etc/init.d/ntpd status [Ent]

← ntpdの状態確認(status)

[xxx@xxxx]# /etc/init.d/ntpd status [Ent]

ntpd (pid IO92)を実行中...

[xxx@xxxx]# ps ax | grep ntpd [Ent]

1092?     SL     0:00 ntpd -U ntp -p /var/run/ntpd.pid

↑ ntpdがシステムアカウント"ntp"で実行中であることを示す

1356 pts/O   S      0:OO grep ntpd

← このgrepコマンドのプロセス

[xxx@xxxx]# /etc/init.d/ntpd stop [Ent]

ntpdを停止中:           [ OK ]

[xxx@xxxx]# /etc/init.d/ntpd status [Ent]

ntpdは停止しています

[xxx@xxxx]# ps ax l grep ntpd [Ent]

1374 pts/0   S      0:00 grep ntpd

[xxx@xxxx]#

*

ntpd は、ntpd の起動前のサーバーの時刻と、参照する NTP サーバーの時刻に大幅な開きがあると、きちんと動作しないことがあります。
ntpd を起動、再起動した後は、必ず、以下を参考に具体的な動作内容の確認を行なう必要があります。
(すみません。省略です。)〔参照URL:http://www.obenri.com/_ntp_sshserver/ntpd_check.html 〕

■ ntpd を自動的に起動する

ntpd は常に動作させて時刻調整を行い続けるようデーモンとして動作させるため、サーバーの起動時に自動的に起動するように設定します。
設定は "ntsysv" コマンド( [xxx@xxxx]# ntsysv [Ent] )で設定画面を開き、"ntpd" にチェックを入れます。

設定が終ったら念のため、一度、サーバーを "reboot" コマンドで再起動し、ntpd が起動しているかを確認します。

■ ntpd の動作チェック

ntpd は、 NTP サーバーがダウンしていても、"/var/lib/ntp/drift" の値を参照して見かけ上は正常に動作しており、実際の動作状態を確認するには、 root アカウントで、"ntpq" コマンド("-p"オプション)で実行します。
( ntpd は直ぐには安定動作にならないので ntpd を起動後、適当に間隔をおいて実行する。)

[xxx@xxxx]# /etc/init.d/ntpd start [Ent]

ntpd:時間サーバと同期中:        [ OK ]

ntpdを起動中:              [ OK ]

[xxx@xxxx]# ntpq -p [Ent]

← ntpd起動後すぐに実行

   remote      refid   st t when poll reach  delay  offset jitter

==============================================================================

ntp1.jst.mfeed. 0.0.0.0     16 u  -  64  0  0.000  0.000 4000.00

ntp2.jst.mfeed. 0.0.0.0     16 u  -  64  0  0.000  0.000 4000.00

ntp3.jst.mfeed. 0.0.0.0     16 u  -  64  0  0.000  0.000 4000.00

[xxxxxxxx]# ntpq -p [Ent]

← ntpd起動から20秒後に実行

   remote      refid   st t when poll reach  delay  offset jitter

==============================================================================

ntp1.jst.mfeed. ote-ntp1.jpnap. 2 u  17  64  1  36.063  27.966  0.008

ntp2.jst.mfeed. fs-monntp1.mfee 2 u  18  64  1  35.643  27.438  0.008

ntp3.jst.mfeed. fs-monntp1.mfee 2 u  14  64  1  35.663  28.134  0.008

[xxxxxxxx]# ntpq -p [Ent]

← ntpd起動から20分後に実行

   remote      refid   st t when poll reach  delay  offset jitter

==============================================================================

* ntp1.jst.mfeed. ote-ntp1.jpnap. 2 u 124 128 377  36.528 -30.583  4.519

* ntp2.jst.mfeed. fs-monntp1.mfee 2 u 117 128 377  35.252 -31.144  4.763

* ntp3.jst.mfeed. fs-monntp1.mfee 2 u  50 128 377  35.810 -32.446  4.050

[xxx@xxxx]#

※ ntpd が安定動作に入ると、"*"、"+" の記号を左端に表示する

 "*":現在同期に使用している NTP サーバー

 "+":予備の NTP サーバー

インターネット接続は正常で、1時間ほど経ってもこの記号が付かない場合は、ntpd が正常に機能していないので、"ntpq -p" の結果から以下の点をチェックする

1.

"refid" の表示が "0.0.0.0" のまま変わらない(NTP サーバーとの接続が成立していない)

"/etc/ntp. conf" の設定をもう一度見直す

2.

"refid" には FQDN が表示されているが、いつまで経っても "*"、"+" の符号が付かない

NTP サーバーの指定を変更

ntpd を一度停止し、ホスト機のシステム時計を "ntpdate" コマンドで手動調整し、"reboot" コマンドでシステムを再起動する

※ CentOS のホスト機では2種類の時計が動作している

① マザーボード上に組込まれているクウォーツ時計 (ハードウェアクロック)

② CentOS がソフトウェア的に動作させている時計  (システムクロック)

ntpd や、ntpdate コマンドなどで調整され、CentOS のシステムやアプリケーションが参照するのはこのシステムクロックで、OS の起動時に、一度だけハードウェアクロックを 参照してシステムクロックの動作を開始し、次回の起動作業までハードウェアクロックを参照することはない。
CentOS は poweroff や reboot コマンドの実行など、システム終了時に実行するスクリプトでハードウェアクロックをシステムクロックに合せる。


< "/etc/ntp.conf" を開き編集して保存 >

# Permit time synchronization with our time source, but do not

# permit the source to query or modify the service on this system.

# restrict default kod nomodify notrap nopeer noquery

← コメントアウト

# restrict -6 default kod nomodify notrap nopeer noquery

← IPv6の設定削除

# Permit all access over the loopback interface. This could

# be tightened as well, but to do so would effect some of

# the administrative functions.

# restrict 127.0.0.1

← コメントアウト

# restrict -6 ::1

← IPv6の設定削除

server 0.jp.pool.ntp.org

← 変更

server 1.jp.pool.ntp.org

← 変更

server 2.jp.pool.ntp.org

← 変更

# broadcast 192.168.1.255 key 42    # broadcast server

# broadcastclient            # broadcast client

# broadcast 224.0.1.1 key 42      # multicast server

# multicastclient 224.0.1.1       # multicast client

# manycastserver 239.255.254.254    # manycast server

# manycastclient 239.255.254.254 key 42 # manycast client

# Undisciplined Local Clock. This is a fake driver intended for backup

# and when no outside source of synchronized time is available.

# server 127.127.1.0          # local clock

← コメントアウト

# fudge 127.127.1.0 stratum 10

← コメントアウト

# Drift file. Put this in a directory which the daemon can write to.

# No symbolic links allowed, either, since the daemon updates the file

# by creating a temporary in the same directory and then rename()'ing

# it to the file.

driftfile /var/lib/ntp/drift

← 変更せず

broadcastdelay 0.004

← 変更せず

# Key file containing the keys and key identifiers used when operating

# with symmetric key cryptography.

# keys /etc/ntp/keys

← コメントアウト

# Specify the key identifiers which are trusted.

# trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.

# requestkey 8

# Specify the key identifier to use with the ntpq utility.

# controlkey 8


<< 解説 >>

全ての NTP 通信を拒否する

"restrict" で通信制御を行わない場合(コメントアウト)、「全てのホストとNTP通信を行う」という振舞いになり、② の設定と共に無効にすると、すべてのホストと自由に NTP 通信を行えるようになる。

restrict default kod nomodify notrap nopeer noquery

restrict -6 default kod nomodify notrap nopeer noquery

  ↓ コメントアウト

# restrict default kod nomodify notrap nopeer noquery

# restrict -6 default kod nomodify notrap nopeer noquery

← IPv6の設定削除

すべてのホストと NTP 通信を行うようにする

自分自身からのみ NTP 通信を許可しているが、コメントアウトですべてのホストと NTP 通信を行うようにする。

estrict 127.0.0.1

restrict -6 ::1

  ↓コメントアウト

# estrict 127.0.0.1

# restrict -6 ::1

← IPv6の設定削除

NTP サーバーを変更する

デフォルトは、「pool.ntp.org the internet cluster of ntp servers」が提供しているものだが、 日本国内の比較的安定して利用できる「インターネットマルチフィード時刻情報サービス for PubIic」の NTP サーバーに変更する。

server 0.rhel.pool.ntp.org

server 1.rhel.pool.ntp.org

server 2.rhel.pool.ntp.org

  ↓ 変更

server ntp1.jst.mfeed.ad.jp または server 210.173.160.27

server ntp2.jst.mfeed.ad.jp または server 210.173.160.57

server ntp3.jst.mfeed.ad.jp または server 210.173.160.87

ホスト機本体のハードウェア時計の時刻を参照しない

"server 127.127.1.0" の "127.127.1.0" はマザーボード上のハードウェア時計のアドレスで、「 ntpd はホスト機マザーボードの時計の時刻を参照する 」の設定になっています。
これは、参照する NTP サーバーが設定されない場合に対処する設定であリ、この設定はコメントアウトする。

server 127.127.1.0   # local clock

  ↓ コメントアウト

# server 127.127.1.0   #local clock

指定したホストを独立したNTPサーバーとして宣言する

デフォルトの "fudge 127.127.1.O stratum 10" は、「ntpd はホスト機本体のマザーボードの時計の時刻を NTP サーバーとして動作させる」の設定であり、この設定はコメントアウトする。

fudge 127.127.1.O stratum lO

  ↓ コメントアウト

# fudge 127.127.1.O stratum lO

ホスト機の時刻と NTP サーバーの時刻の誤差を記録するファイルを指定

ntpd がホスト機の時刻の進み方と、NTP サーバーの時刻の進み方との誤差を記録するファイルを指定する設定で、参照する NTP サーバーと時刻を同期するとき、一時間当りの誤差を "driftfiIe" に記録し、 1時間以上 NTP サーバーから時刻惰報が得られないとき、"driftfile" に記録された時間を元に暫定的に時刻調整を実施する。

driftfile/var/lib/ntp/drift

← 変更しない

NTP サーバーとの通信で生じる時間誤差を指定する

ntpd が NTP サーバーと時刻を同期するときにブロードキャストで生じる同期タイミングの遅れを修正する時間の設定で、"/etc/ntp. conf" には、"broadcastdeIay" の記述はないがデフォルトで "0.004" が設定される。
通信環境は様々で、この値は絶対的ではないが、実測してこの値の微調整を行っても、実用上の影響はなく、そのまま利用する。

broadcastdelay O.OO4

← 変更しない

構築中のサーバーを NTP サーバーとして運用させない

ntpd が NTP サーバーとして利用されるときに、認証を行う際のキーファイルの所在を指定するが、構築中のサーバーは、NTP サーバーとして運用させないので、この部分はコメントアウトする。

keys /etc/ntp/keys

  ↓ コメントアウト

# keys /etc/ntp/keys

[←CentOS-6]

[CentOS-8→]

ページ先頭へ

- Copyright (C) 2013. D71030 -