NTP时间同步

1)安装NTP服务

自行安装,在命令行终端输入:

ruoshui@ruoshui-VMware7-1:~/桌面$ sudo apt-get -y install ntp

(2)修改配置文件/etc/ntp.conf 

以服务器 192.168.20.21 的时间与 ntp.ubuntu.com 同步,允许同步的 NTP 客户端所在的网段为192.168.20.0/255.255.255.0为例

ruoshui@ruoshui-VMware7-1:~/桌面$  sudo vim /etc/ntp.conf

以下为配置文件内容:

driftfile /var/lib/ntp/ntp.drift

statistics loopstats peerstats clockstats

filegen loopstats file loopstats type day enable

filegen peerstats file peerstats type day enable

filegen clockstats file clockstats type day enable

server ntp.ubuntu.com

restrict -4 default kod notrap nomodify nopeer noquery  limited

restrict -6 default kod notrap nomodify nopeer noquery  limited

restrict 192.168.20.0 mask 255.255.255.0 nomodify

restrict 127.0.0.1

restrict ::1

Tips:其中 server ntp.ubuntu.com,当连接外网的时候,本机首先要同步的就是 ntp.ubuntu.com 的时间;当用局域网的时候,应把地址设为标准时间的机器IP。如果在同步时间的时候出现“Service dropped: strata too high”的报错,应对配置文件的 server 进行如下修改:

server 127.127.1.0 fudge

127.127.1.0 stratum 8

重启服务生效:

ruoshui@ruoshui-VMware7-1:~/桌面$  sudo systemctl restart ntp

(3)在客户端执行下列命令就可以进行同步:

ruoshui@ruoshui-VMware7-1:~/桌面$ sudo ntpdate 192.168.20.21

需等待几分钟时间才能同步完成。可同时查看服务器的硬件时钟并进行更改:

ruoshui@ruoshui-VMware7-1:~/桌面$  sudo hwclock

ruoshui@ruoshui-VMware7-1:~/桌面$  sudo hwclock -w

(4)可以在服务器端执行下面的命令来查看同步的过程:

 ntpq -p

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值