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.178linux.com/1714

(0)
蝙蝠侠•杰蝙蝠侠•杰
上一篇 2015-03-27
下一篇 2015-03-28

相关推荐

  • 二叉树的应用详解 – 数据结构

    概述: 平衡树——特点:所有结点左右子树深度差≤1 排序树——特点:所有结点“左小右大字典树——由字符串构成的二叉排序树判定树——特点:分支查找树(例如12个球如何只称3次便分出轻重)带权树——特点:路径带权值(例如长度) 最优树——是带权路径长度最短的树,又称 Huffman树,用途之一是通信中的压缩编码。 1. 二叉排序树(二叉查找树 Bina…

    Linux干货 2015-04-07
  • Linux之网络管理

    Linux之网络管理     在学习linux的过程中,Linux网络的管理和配置中是很重要的,几乎学习的后期都离不开网络的概念和配置,如集群中的使用,学习好Linux网络至关重要。     Linux网络IP地址有两种配置方式:静态指定和动态分配 动态分配就是利用DHCP服务器,动态的给linux主机分配IP地址。静…

    Linux干货 2016-09-05
  • select case的用法-函数练习-20160819

    §·select  case的用法 *介绍select 循环与菜单 ◎语法 select  variable  in  list[ ] do 循环体命令 Done  ◎select 循环主要用于创建菜单,按数字顺序排列的菜单项将显示在标准错误上,并显示PS3 提示符,等待用户输 入 ◎用户…

    Linux干货 2016-08-19
  • 数据库的备份和恢复

    数据库的备份和恢复 一 (理论篇)、数据库备份与恢复基础 1、数据库的备份与恢复 备份:存储的数据副本; 原始数据:持续改变; 恢复:把副本应用到线上系统; 仅能恢复至备份操作时刻的数据状态; 时间点恢复: binary logs; 2、为什么备份? 灾难恢复: 硬件故障(冗余)、软件故障(bug)、自然灾害、黑客攻击、误操作、…&nb…

    2016-11-22
  • 8.3作业

    创建sysadmins组  将user1 user2 user3 加入组中 将user3设置为管理员 用user3登录,将user2从组中移除 设置sysadmins口令centos 设置user1在创建新文件时所属组为sysadmins 删除User1-3 删除sysadmins [root@localhost testdir]#&nb…

    Linux干货 2016-08-04
  • bash之脚本入门及课后作业

    概述: shell是一个工具程序,在用户登录后后系统启动,它解释并运行由命令或脚本文件输入的命令,从而实现用户与内核之间的交互。bash是Linux操作系统上默认的shell,在交互和编程两方面,bash提供了许多Bourne shell没有的功能,并且还结合了C shell和Kron shell最有用的功能。 bash的语法和结构   …

    Linux干货 2016-08-15

评论列表(2条)

  • stanley
    stanley 2015-03-27 23:27

    帮你格式化了代码段和字体的调整,这样的调整会使文章整体看起来更为专业美观。 请提交前多使用预览功能。

    • 蝙蝠侠•杰
      蝙蝠侠•杰 2015-03-28 11:44

      @stanley好的,谢谢了