2009年6月12日 星期五

自動對時-ntpdate

在Debian類的linux下安裝套件是件幸福的事,當然各版本各有其優點,只是習慣了atp-get
鍵入apt-get install ntpdate執行,按一下y,就完成安裝ntpdate.真是方便.

執行
#/usr/sbin/ntpdate -s clock.stdtime.gov.tw
即可對時;其中參數 s 代表將執行後的messages交由 syslog 來記錄,例如記錄在 /var/log/messages檔案。
clock.stdtime.gov.tw是time server的名稱
可參考這個說明
http://www.stdtime.gov.tw/chinese/Bulletin/NTP%B7s%BCW%C0W%BCe.txt

再執行
#/sbin/hwclock -w
將正確的時間更新BIOS內時間

當然還要排入crontab
#vim /etc/crontab 
* 8 * * * root (/usr/sbin/ntpdate -s clock.stdtime.gov.tw;/sbin/hwclock -w) > /dev/null

這樣就完成網路校時及自動執行的程序

******
1.http://www.ntp.org/downloads.html下載release檔案
wget ftp://ftp.udel.edu/pub/ntp/ntp4/ntp-4.2.4p7-RC2.tar.gz
2.解壓縮
tar zxvf ntp-4.2.4p7-RC2.tar.gz
3.開始編譯
cd ntp-4.2.4p7-RC2
./configure
make
make install 安裝完成。
4.cron裡定時執行:
* 8 * * * /usr/sbin/ntpdate time.stdtime.gov.tw
表示每天八點與ntp-server執行校時動作
******

沒有留言:

張貼留言