局域网中主机间的时间同步

1、启动 CentOS NTP 服务

(1) 安装 ntpd 服务,并启动服务:

~# yum -y install ntp ntpdate

(2) 编辑 /etc/ntp.conf 文件

设置服务器 ip:20.0.8.61
在这里插入图片描述

(3) 启动 ntpd 服务

可以直接执行 ntpd 命令

ntpd

通过 pidof ntpd 确认服务已经启动!

2、CentOS 时间同步

Linux的时间分为System Clock(系统时间)和Real Time Clock (硬件时间,简称RTC)。

  • 系统时间:指当前Linux Kernel中的时间。
  • 硬件时间:主板上有电池供电的时间。

查看系统时间的命令:

~# date

设置系统时间的命令:date –set(月/日/年 时:分:秒)

~# date –set “10/11/10 10:15”

查看硬件时间的命令:

~# hwclock

设置硬件时间的命令:

~# hwclock –set –date = (月/日/年 时:分:秒)

手动设置时间到一个时间点,可能与当前网络的时间有误差。下面介绍一下与时间服务器上的时间同步的方法:

(1) 安装 ntpdate 工具

~# yum -y install ntp ntpdate

(2) 设置系统时间与时间服务器同步

~# ntpdate 20.0.8.61

(3) 将系统时间写入硬件时间

~# hwclock --systohc

(4) 强制系统时间写入 CMOS 中放置重启失效

~# hwclock -w

3、Windows 时间同步

Windows 提供的 w32tm 程序可以用来设置时间同步服务器,其用法如下:

(1) 指定外部时间源并与之同步(需要管理员权限执行)

w32tm /config /manualpeerlist:“20.0.8.61” /syncfromflags:manual /reliable:yes /update

  • /manualpeerlist表示外部时间源服务器列表,多个服务器之间可用空格分隔,210.72.145.44 是中国国家授时中心的时间服务器ip地址
  • /syncfromflags:manual表示与指定的外部时间源服务器列表中的服务器进行同步
  • /reliable:yes设置此计算机是一个可靠的时间源。此设置只对域控制器有意义。
  • /update向时间服务发出配置已更改的通知,使更改生效

(2) 显示本地时间与目的时间的时间差

w32tm /stripchart /computer:20.0.8.61 /samples:30 /dataonly

在这里插入图片描述

(3) 显示目前服务器指定的外部时间源

w32tm /query /source

(4) 恢复 Windows Time Service 的预设值

net stop w32time
w32tm /unregister
w32tm /register
net start w32time

在域环境中,只需设置根域控制器的外部时间源即可,其它服务器在添加进域中时将自动设置与域控制器时间同步。改设置可解决域控制器的时间同步问题 如:Time-Service EventID:36

(5) 同步时间

w32tm /resync

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以按照以下步骤来配置 Linux-1 为其他 Linux 主机提供时间同步服务: 1. 在 Linux-1 上安装 chrony: ``` sudo apt-get update sudo apt-get install chrony ``` 2. 修改 chrony 配置文件 `/etc/chrony/chrony.conf`,将以下行添加到文件末尾: ``` allow 192.168.1.0/24 ``` 其 `192.168.1.0/24` 是你的局域网地址段,允许这个地址段的主机与 Linux-1 同步时间。 3. 启动 chrony 服务: ``` sudo systemctl start chrony ``` 4. 验证 chrony 是否正常工作: ``` chronyc sources ``` 如果输出类似以下内容,则表示 chrony 已经正常工作: ``` 210 Number of sources = 1 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^+ time.nist.gov 1 6 37 30 -294us[ -625us] +/- 161ms ``` 5. 在其他 Linux 主机上安装 chrony: ``` sudo apt-get update sudo apt-get install chrony ``` 6. 修改 chrony 配置文件 `/etc/chrony/chrony.conf`,将以下行添加到文件末尾: ``` server linux-1 ``` 其 `linux-1` 是 Linux-1 的主机名或 IP 地址。 7. 启动 chrony 服务: ``` sudo systemctl start chrony ``` 8. 验证时间同步是否正常: ``` chronyc tracking ``` 如果输出类似以下内容,则表示时间同步已经正常: ``` Reference ID : 192.168.1.100 (linux-1) Stratum : 2 Ref time (UTC) : Tue Sep 07 07:52:26 2021 System time : 0.000000000 seconds slow of NTP time Last offset : -0.000000000 seconds RMS offset : 0.000000000 seconds Frequency : 1.814 ppm slow Residual freq : -0.004 ppm Skew : 0.000 ppm Root delay : 0.002045309 seconds Root dispersion : 0.000534147 seconds Update interval : 64.0 seconds Leap status : Normal ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值