CentOS服务器设置自动时间同步

在虚拟机中使用centos的时候,经常进行挂起等操作,这样导致时间经常不准确,于是进行自动时间同步的设置,服务器同理。

安装ntpdate

1
yum install ntp

安装完成后,无需其他配置,直接执行

1
ntpdate time.nist.gov

如果出现以下内容,说明同步成功了。

1
15 Jan 11:40:25 ntpdate[804]: adjust time server 132.163.4.101 offset 0.093992 sec

然后在crontab里面加上以下内容

1
*/10 * * * * ntpdate time.nist.gov   #域名或IP

每隔十分钟同步一次。推荐几个时间服务器:

1
2
3
4
5
6
time.nist.gov
time.nuri.net
asia.pool.ntp.org
asia.pool.ntp.org
asia.pool.ntp.org
asia.pool.ntp.org