CentOS7设置时间与windows同步

使用ntp使CentOS服务器的系统时间与机器时间同步于windows服务器

思路是将windows服务器作为ntp服务端Centos7设置设置时间与windows同步,centOS服务器作为ntp客户端,以满足一套系统的时间一致性。

centOS有系统时间和硬件时间,可以在同步时间后

windows 时间同步出错_windows 时间同步出错_windows 时间同步出错

当然windows 时间同步出错,其他服务器也适用。

centOS机器安装ntp

有离线和在线安装两种方式windows 时间同步出错,网上一查一大堆,此处略,有时间再补。

windows 时间同步出错_windows 时间同步出错_windows 时间同步出错

windows安装ntp

其实win已经自带ntp,本文是将win服务器作为服务端,所以只需启动NtpServer即可。

首先打开注册表(win + R快捷键输入regedit),找到如下图所示目录的Enabled,将该值从0修改为1(1为启用NTP服务器):

windows 时间同步出错_windows 时间同步出错_windows 时间同步出错

在这里插入图片描述

再将如下图所示目录的AnnounceFlags,把默认的10改为5(5的意思就是自身为可靠的时间源):

在这里插入图片描述

windows 时间同步出错_windows 时间同步出错_windows 时间同步出错

关闭注册表Centos7设置设置时间与windows同步,重启Ntp服务(net stop w32Time,net start w32Time):

在这里插入图片描述

同步时间

windows 时间同步出错_windows 时间同步出错_windows 时间同步出错

一个命令就可以解决了:/usr/sbin/ntpdate xxx.xxx.xxx.xxx> /dev/null 2>&1; /sbin/hwclock -w

解释一下找个命令:

/usr/sbin/ntpdate xxx.xxx.xxx.xxx中xxx.xxx.xxx.xxx是刚才配置的ntp服务端的win服务器ip地址,这个命令是将win服务器的时间同步到本机的系统时间> /dev/null 2>&1;是禁止输出和错误输出/sbin/hwclock -w是将系统时间写入硬件时间

我们可以将这个命令配置在定时任务中,也可以配置为开机启动同步,如:

  • 评论列表 (0)

留言评论