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
下一篇 2015-03-28

相關推薦

  • 8.1-用戶和組(作業篇)

     1、將/etc/issue文件中的內容轉換為大寫后保存至/tmp/issue.out文件中。 [root@localhost ~]# tr a-z A-Z </etc/issue > /tmp/issue.out [root@localhost ~]#&n…

    Linux干貨 2016-08-04
  • 簡單的文本處理工具和正則表達式

    一、文本工具     在linux中,有很多優秀且功能強大的文本處理工具,對文件內容進行查找、替換、刪除、排序等操作,是linux進行文本處理變得特別方便。日常工作中,經常會用文本處理進行日志分析,文本抽取等,所以掌握文本處理,將會對我們的工作起到極大的作用。 cat:查看文件    &n…

    Linux干貨 2016-08-10
  • 推薦-tree命令的安裝和使用

    一、前言     tree命令是可以把指定文件夾的所以文件用樹狀羅列出來,呈現目錄形式的一個命令。在Centos 6.5中默認不能直接使用: 輸入type tree命令(type COMMAND:區別是內建命令還是外部命令)提示不存在: 二、安裝       …

    系統運維 2016-03-27
  • 第四周:/etc/passwd、/etc/group文件熟悉及配合grep使用正則表達式

    1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。 [root@wlm ~]# useradd tuser1 [root@wlm ~]# cp -r etc/skel/ /home/tuser1/…

    Linux干貨 2016-10-13
  • 馬哥教育網絡班21期-第九周課程練習

    第九周作業 1、寫一個腳本,判斷當前系統上所有用戶的shell是否為可登錄shell(即用戶的shell不是/sbin/nologin);分別這兩類用戶的個數;通過字符串比較來實現; #!/bin/bash # declare -i nologin=0 declare -i other=0   &n…

    Linux干貨 2016-09-19
  • 內核編譯

    下載內核并解壓:tar -xvf linux-4.14.9.tar.xz -C ./linux/     接下來是 ? ?make ? config ?。 (具體參照 ? ?《make ? config ?的幾種類型》) 一般采用??# ?make ? menuconfig?? 的方式 是這個樣子的: 此處有可能需要幾個包,選擇最簡單的y…

    2018-01-01

評論列表(2條)

  • stanley
    stanley 2015-03-27 23:27

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

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

      @stanley好的,謝謝了

欧美性久久久久