天天看點

NTP時間伺服器安裝部署文檔

系統環境:CentOS5.4

文檔版本:

1.0.1

更新時間:

2011-01-07

目 錄

<a target="_blank" href="http://blog.chinaunix.net/chinaunixeditor.php?op=blank&amp;charset=gbk#_Toc293656544">NTP時間伺服器</a>

安裝部署文檔... 1

<a target="_blank" href="http://blog.chinaunix.net/chinaunixeditor.php?op=blank&amp;charset=gbk#_Toc293656545">1 文檔更新記錄... 3</a>

<a target="_blank" href="http://blog.chinaunix.net/chinaunixeditor.php?op=blank&amp;charset=gbk#_Toc293656546">2 文檔說明... 3</a>

<a target="_blank" href="http://blog.chinaunix.net/chinaunixeditor.php?op=blank&amp;charset=gbk#_Toc293656547">3 配置時間同步... 3</a>

<a target="_blank" href="http://blog.chinaunix.net/chinaunixeditor.php?op=blank&amp;charset=gbk#_Toc293656548">3.1 服務端的配置... 3</a>

<a target="_blank" href="http://blog.chinaunix.net/chinaunixeditor.php?op=blank&amp;charset=gbk#_Toc293656549">3.1.1 啟動ntpd服務:... 4</a>

<a target="_blank" href="http://blog.chinaunix.net/chinaunixeditor.php?op=blank&amp;charset=gbk#_Toc293656550">3.1.2 檢查時間伺服器的同步狀态:... 4</a>

<a target="_blank" href="http://blog.chinaunix.net/chinaunixeditor.php?op=blank&amp;charset=gbk#_Toc293656551">3.1.3 檢視時間伺服器的監控端口:... 4</a>

<a target="_blank" href="http://blog.chinaunix.net/chinaunixeditor.php?op=blank&amp;charset=gbk#_Toc293656552">4 用戶端配置:... 5</a>

<a target="_blank" href="http://blog.chinaunix.net/chinaunixeditor.php?op=blank&amp;charset=gbk#_Toc293656553">4.1 執行同步指令... 5</a>

<a target="_blank" href="http://blog.chinaunix.net/chinaunixeditor.php?op=blank&amp;charset=gbk#_Toc293656554">4.2 添加計劃任務... 5</a>

<a target="_blank" href="http://blog.chinaunix.net/chinaunixeditor.php?op=blank&amp;charset=gbk#_Toc293656555">5 注意事項... 5</a>

<a target="_blank" href="http://blog.chinaunix.net/chinaunixeditor.php?op=blank&amp;charset=gbk#_Toc293656556">6 傳遞... 6</a>

時間

修改人

版本号

修改說明

2011.01.04

kevin

1.0.0

建立文檔

2011.01.07

更新目錄,規範文檔格式

本文檔規範NTP時間伺服器安裝流程及安裝内容,供運維人員在部署新的營運環境時參考使用。

所有的節點的時間必須同步。可以通過NTP服務來實作。如果網絡中已經有時間伺服器,那麼所有節點可以都使用這個時間伺服器。否則可以配置内網中一台伺服器作為時間伺服器。NTP占用的資源非常的少,是以可以在内網上建立一個NTP伺服器。

g-ntpd-01作為NTP伺服器

[root@g-ntpd-01 ~]# mv /etc/ntp.conf /etc/ntp.conf_bak

[root@g-ntpd-01 ~]# vi /etc/ntp.conf

添加以下内容:

server 0.centos.pool.ntp.org

server 1.centos.pool.ntp.org

server 2.centos.pool.ntp.org

server 127.127.1.0 #local clock

fudge 127.127.1.0 stratum 10

driftfile /var/lib/ntp/drift

broadcastdelay 0.008

[root@g-ntpd-01 ~]# ps -ef|grep ntp

root 22113 4333 0 18:43 pts/2 00:00:00 grep ntp

[root@g-ntpd-01 ~]# /etc/init.d/ntpd start

Starting ntpd: [ OK ]

ntp 22127 1 0 18:44 ? 00:00:00 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g

root 22130 4333 0 18:44 pts/2 00:00:00 grep ntp

[root@g-ntpd-01 ~]# ntpq -p

remote refid st t when poll reach delay offset jitter

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

+www.chinaepg.ne 218.75.4.130 3 u 28 64 377 5.396 -467570 3.711

*61.153.197.226 66.220.9.122 2 u 31 64 377 138.291 -467570 1.439

+221.7.129.79 192.43.244.18 2 u 20 64 377 73.794 -467570 3.176

LOCAL(0) .LOCL. 10 l 25 64 377 0.000 0.000 0.001

[root@g-ntpd-01 ~]# netstat -atnpu|grep ntp

udp 0 0 192.168.1.187:123 0.0.0.0:* 3136/ntpd

udp 0 0 127.0.0.1:123   0.0.0.0:* 3136/ntpd

udp 0  0 0.0.0.0:123  0.0.0.0:*  3136/ntpd

udp 0 0 fe80::20c:29ff:fe76:123 :::*   3136/ntpd

udp 0 0 ::1:123  :::*   3136/ntpd

udp 0 0 :::123    :::* 3136/ntpd

在用戶端台機器上運作如下的指令,與ntpd服務端進行時間同步。

[root@g-ntpd-client-01 ~]# /usr/sbin/ntpdate 192.168.1.187

29 Dec 17:30:03 ntpdate[2959]: adjust time server 192.168.1.187 offset 0.000061 sec

若不能出現上面的同步,可能退出root使用者再登陸,或者切換一下使用者,也有可能不能馬上同步,需要一定的時間(一般時間為服務端ntpd服務啟動五分鐘後即可)

可以将這個指令作為一個周期性運作的指令。

[root@g-ntpd-client-01 ~]# crontab -l

*/5 * * * * /usr/sbin/ntpdate 192.168.1.187 &amp;&amp; /usr/sbin/hwclock --systohc

注意:将用戶端和伺服器端的這個參數修改成yes。同步成功以後,自動的更新BIOS.

[root@g-ntpd-client-01 ~]# vi /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=no

SYNC_HWCLOCK=yes

# Additional options for ntpdate

NTPDATE_OPTIONS=""

到此,時間伺服器的服務端及用戶端的配置就已經成功了。

測試沒有問題後,即可傳遞,進行生産環境的安裝及部署。

    本文轉自vcdog 51CTO部落格,原文連結:http://blog.51cto.com/255361/837706,如需轉載請自行聯系原作者