今回はNTPサーバーを構築してサーバーのシステム日付を自動設定します。
NTPサーバーインストール
[centos@centos ~]$ su -
パスワード: rootユーザーのパスワード
NTPサーバーをインストールします
[root@centos ~]# yum -y install ntp
Loaded plugins: fastestmirror, priorities
Loading mirror speeds from cached hostfile
* base: ftp.iij.ad.jp
* updates: rsync.atworks.co.jp
* addons: www.ftp.ne.jp
* extras: www.ftp.ne.jp
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
–> Running transaction check
—> Package ntp.i386 0:x.x.xxx-x.xxx.centos set to be updated
–> Finished Dependency Resolution
Dependencies Resolved
===================================================================================================================================
Package Arch Version Repository Size
===================================================================================================================================
Installing:
ntp i386 x.x.xxx-x.xxx.centos base 1.3 M
Transaction Summary
===================================================================================================================================
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 1.3 M
Downloading Packages:
ntp-x.x.xxx-x.xxx.centos.i386.rpm | 1.3 MB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : ntp [1/1]
Installed: ntp.i386 x:x.x.xxx-x.xxx.centos
Complete!
NTPサーバー設定
viエディタが起動するのでNTPサーバー設定ファイルを修正します
# 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
# 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
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
ローカルネットワークの時間同期を許可します
※設定しているIPアドレスはyasuの環境になりますので、ご自身の環境にあわせて設定をしてください
restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
NTP/推奨公開サーバ – wiki@nothingを参考にして時間同期する為のNTPサーバーを変更します
#server 0.centos.pool.ntp.org 先頭に#をつけてコメント
#server 1.centos.pool.ntp.org 先頭に#をつけてコメント
#server 2.centos.pool.ntp.org 先頭に#をつけてコメント
日本標準時プロジェクトのNTPサーバー
server ntp.nict.jp
server ntp.nict.jp
server ntp.nict.jp
インターネットマルチフィード時刻情報サービスのNTPサーバー
server ntp1.jst.mfeed.ad.jp
server ntp2.jst.mfeed.ad.jp
server ntp3.jst.mfeed.ad.jp
#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
# 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
内容を保存しviエディタを終了します
NTPサーバーをローカルネットワークに公開する為に、CentOSのファイアウォールの設定を変更します。
viエディタが起動するので設定ファイルを変更します。
# Firewall configuration written by system-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT – [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp –icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp –dport 5353 -d 224.0.0.251 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp –dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp –dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 53 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m udp -p udp –dport 53 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
下記2行を追加してTCPとUDPの123番ポート(ntp)を開放します
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 123 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m udp -p udp –dport 123 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 443 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT –reject-with icmp-host-prohibited
内容を保存しviエディタを終了します
設定内容を反映します
[root@centos ~]# /etc/rc.d/init.d/iptables restart
ファイアウォールルールを適用中: [ OK ]
チェインポリシーを ACCEPT に設定中filter [ OK ]
iptables モジュールを取り外し中 [ OK ]
iptables ファイアウォールルールを適用中: [ OK ]
iptables モジュールを読み込み中ip_conntrack_netbios_ns [ OK ]
NTPサーバー起動と確認
[root@centos html]# ntpdate ntp.nict.jp
2 Apr 14:26:50 ntpdate[3542]: step time server 133.243.238.244 offset -94.600070 sec
NTPサーバーを起動します
[root@centos ~]# /etc/rc.d/init.d/ntpd start
ntpd を起動中: [ OK ]
NTPサーバーの自動起動設定を行います
[root@centos =]# chkconfig ntpd on
[root@centos =]# chkconfig –list ntpd
ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
NTPサーバーの自動時間同期の確認を行います
[root@centos ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
+ntp-b3.nict.go. .NICT. 1 u 46 64 17 9.557 -0.351 0.152
*ntp-b2.nict.go. .NICT. 1 u 49 64 17 10.121 -0.547 0.707
+ntp-a3.nict.go. .NICT. 1 u 47 64 17 8.473 -0.385 1.096
ntp1.jst.mfeed. 210.173.160.56 2 u 40 64 17 5.442 0.648 0.428
-ntp2.jst.mfeed. 210.173.176.4 2 u 44 64 17 5.619 0.330 0.855
ntp3.jst.mfeed. 210.173.160.86 2 u 40 64 17 5.867 0.890 0.166
LOCAL(0) .LOCL. 10 l 43 64 17 0.000 0.000 0.004
ntpq出力結果の説明はこちら
ローカルネットワーク内のパソコンも自宅サーバーと時間同期するよう設定したいと思います。
Windows(XP)の場合
右下の時計を右クリックして[日付と時刻の調整]をクリックします。
[インターネット時刻]タブを選択して、自動的にインターネット時刻サーバーと同期するのリストボックスに「sa-sa-ki.jp」と入力して[今すぐ更新(U)]ボタンをクリックすれば時間同期が完了します。
MacOSX(Leopard)の場合、メニューバーの時計の箇所をクリックして”日付と時刻”を開くをクリックします。
日付と時刻を自動的に設定:のリストボックスに「sa-sa-ki.jp」と入力すれば自動的に時間同期が完了します。
Ubuntuの場合、/etc/default/ntpdateファイルに参照するNTPサーバーを入力してサービスを再起動します。
ubuntu@ubuntu:~$ sudo vi /etc/default/ntpdate
[sudo] password for ubuntu: ubuntuユーザのパスワードを応答します
viエディタが起動するのでNTPサーバー設定ファイルを修正します
# The settings in this file are used by the program ntpdate-debian, but not
# by the upstream program ntpdate.
# Set to “yes” to take the server list from /etc/ntp.conf, from package ntp,
# so you only have to keep it in one place.
NTPDATE_USE_NTP_CONF=yes
# List of NTP servers to use (Separate multiple servers with spaces.)
# Not used if NTPDATE_USE_NTP_CONF is yes.
NTPSERVERS=“sa-sa-ki.jp”
# Additional options to pass to ntpdate
NTPOPTIONS=”"
内容を保存しviエディタを終了します
設定内容を反映します
ubuntu@ubuntu:~$ sudo /etc/network/if-up.d/ntpdate
■ 参考サイト ■
NTPサーバー構築(ntpd) – CentOSで自宅サーバー構築
NTP/プロバイダ・機関別 – wiki@nothing
日本標準時プロジェクト 公開NTP
[Think IT] 第3回:Ubuntuサーバの管理 (3/3)
————————————————————————————————–
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その17 WordPressのセキュリティ対策
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 番外編その1 CentOS 5.3 のリリースと導入済みソフトウェアのアップデート
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その16 CentOS 5.2 にWordPressを導入してブログサイトを構築する
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その15 Apacheにサーバー証明書を導入する
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その14 CentOS 5.2 にLAMP環境構築(MySQL編)
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その13 CentOS 5.2 にLAMP環境構築(Apache、PHP編)
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その12 CentOS 5.2 にDNSサーバーを導入して名前解決(確認編)
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その11 CentOS 5.2 にDNSサーバーを導入して名前解決(設定編)
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その10 CentOS 5.2 SSHサーバーを構築して外部からリモート接続&リモートファイル転送
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その9 CentOS 5.2 にバッファオーバーフロー攻撃対策を行う
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その8 CentOS 5.2 にrootkit検知ツールを導入する
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その7 CentOS 5.2 にファイル改竄検知システムを導入する
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その6 CentOS 5.2 にアンチウィルスソフトを導入する
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その5 CentOS 5.2 ファイル転送準備
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その4 CentOS 5.2 インストール後の初期設定
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その3 インストールしたCentOS 5.2 にリモート接続準備
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その2 CentOS 5.2 をインストールする
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その1 導入を検討する






