CentOS 5.5 下配置NTP服務器

首先檢查是否安裝了組建:
[root@testmechine ~]# rpm -qa ntp
ntp-4.2.2p1-9.el5.centos.1
假如沒有安裝則yum install ntp來進行安裝。
所需要的配置文件:
1./etc/ntp.conf
linux各版本雖然目錄不同,但文件名相同。可以用which ntp.conf 或者locate ntp.conf來查找。這是NTP唯一的一個設置文件。
2./usr/share/zoneinfo/
這個裏面規定了這個主要時區的時間設置文件。
3./etc/sysconfig/clock
這個文件是linux的主要時區設置文件,每次開機後linux會自動讀取這個文件來設置系統所默認的顯示時間,可以看看它裏面到底設置了什麼:
[root@testmechine sysconfig]# cat /etc/sysconfig/clock
# The ZONE parameter is only evaluated by system-config-date.
# The timezone of the system is defined by the contents of /etc/localtime.
ZONE="Asia/Shanghai"
UTC=true
ARC=false
4./etc/localtime
本地端時間配置文件。
5./bin/date
這個是時間的修改命令,除了輸出時間,還可以修改時間。
6./sbin/hwclock
因爲linux系統上面BIOS時間與linux系統時間是分開的,所以使用date這個指令調整了時間之後,還需要使用hwclock才能將修改過的時間寫入BIOS中。
7./usr/sbin/ntpd
這是NTP的daemon文件,需要啓動它才能提供NTP服務,這個命令會讀取/etc/ntp.conf裏面的設置。
8./usr/sbin/ntpdate
這是client用來連接NTP Server的主要執行文件,如果您不想啓用NTP,只想啓用NTP Client功能的話,可以只應用此命令。
9,/usr/sbin/ntptrace
可以用來追蹤某臺時間服務器的時間對應關係。


配置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

restrict default nomodify noquery notrap
restrict 202.112.10.60
restrict 202.106.199.36
restrict 202.112.7.150
restrict 127.0.0.1 mask 255.0.0.0
restrict 192.168.0.0 mask 255.255.255.0 nomodify  
 

 

第一行restrict、default定義默認訪問規則,nomodify禁止遠程主機修改本地服務器配置,notrap拒絕特殊的ntpdq捕獲消息,noquery拒絕btodq/ntpdc查詢(這裏的查詢是服務器本身狀態查詢)。
# 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

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 210.72.145.44
server 1.centos.pool.ntp.org
server 2.centos.pool.ntp.org
此處填的是互聯網上公開的NTP server地址可以參見:http://support.ntp.org/bin/view/Servers/NTPPoolServers
#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

以上是ntp.conf的最終設置。

然後我們修改/etc/sysconfig/ntpd:

# Drop root to id 'ntp:ntp' by default.
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid"

# Set to 'yes' to sync hw clock after successful ntpdate
SYNC_HWCLOCK=yes #make no into yes; BIOS的時間也會跟着修改

# Additional options for ntpdate
NTPDATE_OPTIONS=""

編輯vim /etc/ntp/step-tickers

添加:210.72.145.44

啓動ntp服務器時候會同步服務器本身的時間

啓動NTP:service ntpd start

等待10分鐘左右的時間之後,在客戶端上使用ntpdate 192.168.55.23 就可以進行時間同步

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章