http://blog./archives/6397.html linux下同步時間,至少有兩種方法: rdate,ntpdate兩種。centos最小化安裝默認不安裝,先確認已經(jīng)安裝過,否則先安裝。 其中rdate本身是用來獲取遠程時間服務器上時間用的,帶上 -s 參數(shù),就可以將獲取到的時間應用到本地系統(tǒng)。 NAME rdate - get the time via the network SYNOPSIS rdate [-p] [-s] [-u] [-l] [-t sec] [host...] DESCRIPTION rdate connects to an RFC 868 time server over a TCP/IP network, printing the returned time and/or setting the system clock. OPTIONS -p Print the time returned by the remote machine. -s Set the system time to the returned time. -u Use UDP instead of TCP as the transport. -l Use syslog to output errors (cron.warning) and output (cron.info). -t Set timeout in seconds for every attempt to retreive date. rdate -s time.nist.gov ntpdate 本身就是用來同步時間的工具。 示例 :ntpdate ntp.sjtu.edu.cn NAME ntpdate - set the date and time via NTP Disclaimer: The functionality of this program is now available in the ntpd program. See the -q com- mand line option in the ntpd - Network Time Protocol (NTP) daemon page. After a suitable period of mourning, the ntpdate program is to be retired from this distribution SYNOPSIS ntpdate [ -46bBdqsuv ] [ -a key ] [ -e authdelay ] [ -k keyfile ] [ -o version ] [ -p samples ] [ -t timeout ] [ -U user_name ] server [ ... ] DESCRIPTION [略,具體參看linux man手冊] 日期時間服務器同步時間,就必須有時間服務器。通常情況下,我們完全沒必要自己搭建,使用公共的時間服務就可以。 參看 國內(nèi)常用NTP服務器地址及IP http://www.douban.com/note/171309770/ 其中國家授時中心的似乎不能用,推薦使用上海交大ntp服務 ntp.sjtu.edu.cn 或美國授時中心 time.nist.gov 上代碼,拷了就可以用 rdate -s time.nist.gov ntpdate ntp.sjtu.edu.cn 可以加到crontab里定時執(zhí)行。 |
|