最近公司客戶的調度系統GPS天文時鐘出現故障,導致整個調度系統失去時間源,時間積累誤差達十幾分鐘。去現場更換時鐘很不方便,所有就想用現場的一臺win xp(可上網)的遠程機器做NTPserver,然后給linux系統對時。上網查了好多資料,終于找到了一個有效的解決方案,具體內容和步驟如下:首先下載一個Windows下的NTP服務軟件。這個軟件可以搭建windows下的NTP服務器。http://www.meinberg.de/english/sw/下載對應的windows 系統上軟件即可。安裝配置特別簡單,可以參考軟件隨機的文檔。只要進行幾個簡單的步驟就可以完成linux和windows之間的時間同步了:
1、下載windows NTP 軟件,并安裝配置,安裝過程中需要輸入NTP服務器的IP時直接輸入Windows服務器本機IP就行了
此軟件有一個ntp.conf的配置文件(我本機的配置文件):
# NTP Network Time Protocol # Configuration File created by Windows Binary Distribution Installer Rev.: 1.22 mbg # please check http://www.ntp.org for additional documentation and background information # Use drift file driftfile "C:Program FilesNTPetc tp.drift" # your local system clock, should be used as a backup # (this is only useful if you need to distribute time no matter how good or bad it is) server 127.127.1.0 prefer # but it operates at a high stratum level to let the clients know and force them to # use any other timesource they may have. fudge 127.127.1.0 stratum 12 # Use a NTP server from the ntp pool project (see http://www.pool.ntp.org) # Please note that you need at least four different servers to be at least protected against # one falseticker. If you only rely on internet time, it is highly recommended to add # additional servers here. # The 'iburst' keyword speeds up initial synchronization, please check the documentation for more details! server 0.asia.pool.ntp.org iburst server 1.asia.pool.ntp.org iburst server 2.asia.pool.ntp.org iburst server 0.us.pool.ntp.org iburst server 1.us.pool.ntp.org iburst server 2.us.pool.ntp.org iburst # Use specific NTP servers server 100.100.100.251 # End of generated ntp.conf --- Please edit this to suite your needs
2、啟動NTP服務,在linux端運行以下命令同步時間
ntpdate timeserver_ip
在linux下終端里執行如下命令即可實現對時:
ntpdate 100.100.100.251 (可多執行幾次使其對時精確一些)
命令執行成功后,會發現linux和windows的時間已經相同了
3、要想使Linux系統保持定時對時,可在/etc/cron.d/目錄里新建一個date.cron的文件,里面輸入如下內容:
# 每5分鐘執行一次對時操作
*/5 * * * * /usr/sbin/ntpdate 100.100.100.251
然后在終端中執行
crontab date.cron
這樣可以該定時操作就成為該用戶的crontab文件了,可以利用如下命令進行查看
crontab -l
#每隔5分鐘執行一次對時操作
*/5 * * * * /usr/sbin/ntpdate 100.100.100.251
.4、要想查看定時對時是否正常執行,可以執行如下命令查看日志文件
tail /var/log/cron Mar 19 14:25:01 server1 crond[26973]: (root) CMD (/usr/sbin/ntpdate 100.100.100.251) Mar 19 14:30:01 server1 crond[27062]: (root) CMD (/usr/sbin/ntpdate 100.100.100.251) Mar 19 14:35:01 server1 crond[27122]: (root) CMD (/usr/sbin/ntpdate 100.100.100.251) Mar 19 14:40:01 server1 crond[27185]: (root) CMD (/usr/sbin/ntpdate 100.100.100.251) Mar 19 14:45:01 server1 crond[27250]: (root) CMD (/usr/sbin/ntpdate 100.100.100.251) Mar 19 14:50:01 server1 crond[27311]: (root) CMD (/usr/sbin/ntpdate 100.100.100.251) Mar 19 14:55:01 server1 crond[27379]: (root) CMD (/usr/sbin/ntpdate 100.100.100.251) Mar 19 15:00:01 server1 crond[27442]: (root) CMD (/usr/sbin/ntpdate 100.100.100.251) Mar 19 15:01:01 server1 crond[27485]: (root) CMD (run-parts /etc/cron.hourly) Mar 19 15:05:01 server1 crond[27536]: (root) CMD (/usr/sbin/ntpdate 100.100.100.251)
由上內容即可看出每隔5分鐘便執行對時操作了了。
常見問題:
-
linux端運行ntpdate timeserver_name提示 ntpdate[2120]: the NTP socket is in use, exitinglinux幾經啟動了ntp進程,可以找著kill掉,重新運行命令
-
linux端運行ntpdate timeserver_name提示 No Server suitable for synchronization found檢查windows 防火墻設置,配置防火墻通過這個ntp請求
-
需要修改ntp.conf文件時必須停止ntp服務,修改完后重新啟動ntp服務舉個例子: ls [*]*a.txt 查找以*開頭中間有任意字符以a.txt結尾的文件
原創文章,作者:蝙蝠俠?杰,如若轉載,請注明出處:http://www.www58058.com/1714
幫你格式化了代碼段和字體的調整,這樣的調整會使文章整體看起來更為專業美觀。 請提交前多使用預覽功能。
@stanley:好的,謝謝了