CentOS定时同步系统时间

      使用Linux.VPS次日,发现系统时间不正确,手动修改或者同步正确一次后,运行半天发觉时间又快了几分钟,反正是运行得越久就越快,难道VPS穿越啦? linux

      和VPS管理员沟通无果,再上网搜索一番后,决定使用定时器自动同步时间算啦。 shell

ssh执行命令:
#crontab -e
执行后加入一行:(和vi命令同样,按i进入编辑模式,Esc返回命令模式,:w保存修改,:q退出)
*/30 * * * * /usr/sbin/ntpdate asia.pool.ntp.org >> /var/log/ntp.log 2>&1
数字30表示30分钟执行一次,保存和退出后,还须要重启定时任务器才行哦:
#service crond restart windows

后面的>> /var/log/crontab.log 表示把定时执行状况写入到日志文件中去,方便查看有无异常。 bash

注意utpdate要写完整路径,网上有些人的例子没写完整路径会致使如下异常:
/bin/sh: ntpdate: command not found ssh


若是你的linux系统根本没有ntpdate这个命令 spa

yum install ntp
#微软:time.windows.com
#台湾:asia.pool.ntp.org
#中科院:210.72.145.44

#网通:219.158.14.130 rest

ntp.sh 日志

#!/bin/bash
###################
. /etc/profile
. ~/.bash_profile
###################
#微软:time.windows.com
#台湾:asia.pool.ntp.org
#中科院:210.72.145.44
#网通:219.158.14.130

# crontab -e
# 1 * * * * sh /root/ntp.sh >> /var/log/ntp.log 2>&1

ntpdate asia.pool.ntp.org
相关文章
相关标签/搜索