首页 » 操作系统 » Linux » CentOS服务器用ntpdate同步网络时间

CentOS服务器用ntpdate同步网络时间

 

如有多台CentOS服务器运行相同的服务,且对时间准确性要求较高,那必须保证多台服务器时间统一。
 
最简单的就是每台服务器都用ntpdate同步同一台网络时间服务器的时间。
 
1、输入ntpdate time.nist.gov同步网络时间

[root@localhost ~]# ntpdate time.nist.gov  
Mon Dec 17:11:43 ntpdate[5014]: adjust time server 207.200.81.113 offset -0.018788 sec  
##如果出现上面的内容说明同步成功了,可以打开北京时间看看,1秒不差

注:如提示命令不存在,直接输入:yum install ntp -y安装ntp软件包。
 
2、设置crontab计划任务,使其定时自动同步
输入命令crontab -e,按键盘字母"i"进入编辑状态,然后按需求复制下面任意一条计划内容到其中,最后按键盘“ESC”,并输入“:wq!”保存即可。

[root@localhost ~]# crontab -e
#每隔1小时同步一次
* */1 * * * ntpdate time.nist.gov
或者
#每周六凌晨1点同步一次
0 1 * * 6 ntpdate time.nist.gov

如果上面time.nist.gov服务器同步不了,可以换下面几个时间服务器试试:
time.nist.gov
time.nuri.net
0.asia.pool.ntp.org
1.asia.pool.ntp.org
2.asia.pool.ntp.org
3.asia.pool.ntp.org

原文链接:CentOS服务器用ntpdate同步网络时间,转载请注明来源!

4