解决一个服务器时间滞后的问题

这两天测试发现服务器时间(虚拟机)明显滞后于标准时间,大概慢了20多秒。原因是虚拟机没有晶振,时间会不准确。为了解决这个问题在服务器上安装了ntp服务,同步阿里云ntp服务器时间。

1. 安装ntp服务

sudo yum update
sudo yum install ntp

2.修改ntp.conf,将原有ntp server优先替换为aliyun ntp server

restrict default nomodify
server ntp1.aliyun.com
server time.nist.gov

3. 启动ntp服务

sudo /etc/init.d/ntpd start

4.查询ntp服务状态,等待5-10分钟后如果看到阿里云ntp服务器前面标注了*,表示ntp同步成功。

[root@localhost ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*time5.aliyun.co 10.137.38.86     2 u  589 1024  377   67.667   -0.574   1.625
 time-d-b.nist.g .NIST.           1 u   7h 1024    0  221.886  -13.338   0.000

ps.如果迟迟没有同步,有可能因为差异太大,可以先手动ntpdate一下,然后启动ntp服务。

sudo /etc/init.d/ntpd stop
sudo ntpdate ntp1.aliyun.com
date
sudo /etc/init.d/ntpd start

现在运行了4天左右,服务器和标准时间的误差在1秒以内了。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值