linux系統從windows xp上同步時間

最近公司客戶的調度系統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分鐘便執行對時操作了了。

常見問題:

  1. linux端運行ntpdate timeserver_name提示 ntpdate[2120]: the NTP socket is in use, exitinglinux幾經啟動了ntp進程,可以找著kill掉,重新運行命令 

  2. linux端運行ntpdate timeserver_name提示 No Server suitable for synchronization found檢查windows 防火墻設置,配置防火墻通過這個ntp請求

  3. 需要修改ntp.conf文件時必須停止ntp服務,修改完后重新啟動ntp服務舉個例子:  ls [*]*a.txt   查找以*開頭中間有任意字符以a.txt結尾的文件

原創文章,作者:蝙蝠俠?杰,如若轉載,請注明出處:http://www.www58058.com/1714

(0)
蝙蝠俠?杰蝙蝠俠?杰
上一篇 2015-03-27 23:11
下一篇 2015-03-28 22:38

相關推薦

  • 磁盤管理(二)Raid與LVM邏輯卷

    概述:本章主要講解raid和邏輯卷 什么是RAID RAID:Redundant Arrays of Inexpensive(Independent) Disks 1988年由加利福尼亞大學伯克利分校( University ofCalifornia-Berkeley) “ A Case for RedundantArrays of Inexpensive …

    Linux干貨 2016-09-05
  • find 和 壓縮工具

    find命令 一、find命令基本介紹 1、find作用 通過遍歷指定路徑實時查找符合條件的文件。 find工作特點 2、find工作特點 ?查找速度較慢 ?精確查找 ?實時查找 ?用戶只能搜索有讀取和執行權限的目錄 3、語法 find [OPTIONS]… [查找路徑] [查找條件] [處理方式] 查找路徑:指定…

    Linux干貨 2016-08-16
  • 企業實時同步方案—-Rsync+Sersync

    原創作品,允許轉載,轉載時請務必以超鏈接形式標明文章 原始出處 、作者信息和本聲明。否則將追究法律責任。http://nolinux.blog.51cto.com/4824967/1433623     在博文企業實時同步方案—-Sersync介紹中我們詳細介紹了Sersync的原理,設計架構以及…

    Linux干貨 2015-03-30
  • linux基礎知識:文件管理,bash特性

    本文簡要介紹了文件類的管理命令,包括mv、cp、mkdir等等。還介紹了一些萬用字符的用法。

    2017-12-12
  • 第九周作業

    awk基礎 簡介        AWK是一種優良的文本處理工具。它是 Linux 中也是任何環境中現有的功能最強大的數據處理引擎之一,相比sed常常作用于一整行的處理,awk比較傾向于將一行分成數個“字段”來處理。所以,awk相當適合處理小型的數據處理。 基礎用法 awk[選項] ‘program’…

    2017-07-16
  • ls、shutdown命令使用及命令提示符格式修改

        ls、shutdown命令使用及命令提示符格式修改                      &nbs…

    Linux干貨 2016-10-17

評論列表(2條)

  • stanley
    stanley 2015-03-27 23:27

    幫你格式化了代碼段和字體的調整,這樣的調整會使文章整體看起來更為專業美觀。 請提交前多使用預覽功能。

    • 蝙蝠俠?杰
      蝙蝠俠?杰 2015-03-28 11:44

      @stanley好的,謝謝了

欧美性久久久久