时间同步-使用win7做server,linux做client端

2 篇文章 0 订阅
1 篇文章 0 订阅

  在调试分布式系统时,日志是个很好的工具,比如使用log4j记录的日志。然而如果各机器的时间不一致,则不能方便地判断各事件的顺序。因此时间同步就很有用了,广为人知的是ntp协议。本文探讨如何使用win7作ntp server,linux做ntp client使得win7和linux系统的时间保持一致。
  
  1. 在win7上安装ntp server
  1) 首先从http://www.meinberg.de/english/sw/ntp.htm#ntp_nt_stable上下载一个最新的ntp服务器,写本文时该页面如下图,红色部分为要下载的ntp server。
 
  

  2) 直接安装(默认会安装到C:\Program Files\NTP目录),中间会出现让你选择上级服务器(即本机时间以其为基准定期同步),安装时先保留默认值。
  安装完成后,生成开始菜单如下图所示:
    
  3)打开C:\Program Files\NTP\etc\ntp.conf文件,修改配置:(可通过资源管理器浏览打开,从开始菜单"Edit NTP Configuration"打开时要右键以管理员身份打开,以能保存修改)
  我的配置文件内容如下:

# NTP Network Time Protocol 

# **** ATTENTION ****: *You have to restart the NTP service when you change this file to activate the changes* 

# PLEASE CHECK THIS FILE CAREFULLY AND MODIFY IT IF REQUIRED 

# Configuration File created by Windows Binary Distribution Installer Rev.: 1.26  mbg

# please check http://www.ntp.org for additional documentation and background information

# Use drift file 

driftfile "D:\develop\NTP\etc\ntp.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

# 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

# End of generated ntp.conf --- Please edit this to suite your needs


  注意,上面的时间服务器如果不可用可以从网上找出可用的服务器ip来替换。

  4) 关闭防火墙。注意一定要关闭win7操作系统自带的防火墙。否则在客户端更新时会出现“No Server suitable for synchronization found ” 错误。
  5) 从开始菜单重启NTP Service。
  6) 确定ntp service是否工作:使用命令ntpq -p

  2. 在linux系统上配置定期与win7时间同步
  执行ntpdate 192.168.1.32 可将本机时间与win7同步(192.168.1.32为win7的ip)。
  注意:linux上运行了ntpd进程时,ntpdate命令执行会失败,出现the NTP socket is in use, exiting。执行:ps -aef | grep ntpd找到该进程,然后kill掉即可。
  
  一般情况下我们希望定期进行同步,这可使用linux中的cron实现:
  如我想每隔10分钟和win7同步时间可以使用crontab -e 编辑crontab工作内容如下:
   */10 * * * * /usr/sbin/ntpdate 192.168.1.32&&/sbin/hwclock-w 
  
  上面的hwclock-w命令是用于更新BIOS时间,从而在系统重启时间时间能够保存。 
  


  
  

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值