CentOS下日期時間自動同步設定
linux下同步時間,至少有兩種方法:
rdate,ntpdate兩種。centos迷你安裝預設不安裝,先確認已經安裝過,否則先安裝。
其中rdate本身是用來擷取遠程時間伺服器上時間用的,帶上 -s 參數,就可以將擷取到的時間應用到本地系統。
NAME rdate - get the time via the networkSYNOPSIS 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 distributionSYNOPSIS ntpdate [ -46bBdqsuv ] [ -a key ] [ -e authdelay ] [ -k keyfile ] [ -o version ] [ -p samples ] [ -t timeout ] [ -U user_name ] server [ ... ]DESCRIPTION[略,具體參看linux man手冊]
日期時間伺服器
同步時間,就必須有時間伺服器。通常情況下,我們完全沒必要自己搭建,使用公用的時間服務就可以。
參看 國內常用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裡定時執行。