close

當一個網路環境有大量的Server的時候,而這些Server都不允許連外,可以透過Time Server來做校時,避免排程、備份校時錯誤。


預設目標找到台灣的TimeServer進行校時
tock.stdtime.gov.tw
tick.stdtime.gov.tw
time.stdtime.gov.tw

在CentOS6.5環境進行架設,NTP Server


SETP.1 安裝 ntp 
shell# yum instal ntp


SETP.2 主要設定檔
shell# vim /etc/ntp.conf

#紀錄每次時間校時所偏移的數值,需要有ntp的權限才能寫入
driftfile /var/lib/ntp/drift
 
#再來是一些使用 ntp的權限設定
restrict default kod nomodify notrap nopeer noquery     #拒絕所有ipv4
restrict -6 default kod nomodify notrap nopeer noquery    #拒絕所有ipv6
 
#允許上層time server
restrict tock.stdtime.gov.tw
restrict tick.stdtime.gov.tw
restrict time.stdtime.gov.tw
 
restrict 127.0.0.1  #預設 不動
restrice -6: :1       #預設 不動
 
#允許192.168.121.0/24網段對time server校時,但不給予修改ntp的權限
restrict 192.168.121.0  mask 255.255.255.0 nomodify

#設定time server校時來源,prefer為優先校時
server tock.stdtime.gov.tw prefer
server tick.stdtime.gov.tw
server time.stdtime.gov.tw
 
#一般 linux 若要校正內部server,也是在此輸入內部server 的位置
#如:
server 192.168.1.100(這是範例)
 
 
SETP.3 NTP啟動與確認
shell# service ntpd start
shell# chkconfig ntpd on
 
#檢查messages是否有error
#netstat檢查UDP 123 port是否Listen
shell# netstat -tunlp | grep ntpd
 
 
 
須等待5~10分鐘與上層校時,請注意在校時的這段時間Client是無法對Time Server進行校時的
 
可以使用 ntpstat 指令來確認是否成功,如閜圖已找到上層NTP Server (118.163.81.61)
 
 
Client 測試 for CentOS
 
#1目前時間
shell# date
一 12月 23 11:45:18 CST 2013

#2隨便更改一個時間
shell# date 072816332011
四  7月 28 16:33:00 CST 2011

#3進行對時
shell# /usr/sbin/ntpdate -s 192.168.1.109

#4檢查時間是否正確
shell# date
三 3月 19 01:24:08 CST 2014
 
 
Client 測試 for Windows
 
#1 右下角時間點選→變更日期和時間設定值
 
 
#2 選擇【網際網路時間】,並點選變更設定
 
 
#3 將伺服器改為NTP Time Server,並立即更新即可得成功同步的訊息。
 
 


硬體: 將BIOS時間也同步調整

shell# vim /etc/sysconfig/ntpd
# Drop root to id 'ntp:ntp' by default. OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g" SYNC_HWCLOCK=yes

防火牆

允許192.168.121.0/24網段
shell# iptables -A INPUT -p UDP -s 192.168.121.0/24 --dport 123 -j ACCEPT

因需要與上層TimeServer校時,故也須將OutPut開啟


參考資料:
http://www.ntp.org/
http://linux.vbird.org/linux_server/0440ntp.php#server
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 chengyu0701988 的頭像
    chengyu0701988

    chengyu0701988的部落格

    chengyu0701988 發表在 痞客邦 留言(0) 人氣()