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

版权声明:转载请附带本文地址 https://blog.csdn.net/liuyifeng1920/article/details/84380411

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

公司项目中调用接口,其中有一些接口需要以当前时间加密,接口要求误差时间不能超过一分钟,但是LINUX服务器长时间运行,时间会不准确导致接口调用失败。

ntp常用服务器:
中国国家授时中心:210.72.145.44
NTP服务器(上海) :ntp.api.bz
美国:time.nist.gov
复旦:ntp.fudan.edu.cn
微软公司授时主机(美国) :time.windows.com
台警大授时中心(台湾):asia.pool.ntp.org

我这次用的是上海的 ntp.api.bz 发现美国的这个本机和linux都ping不通。

[root@localhost /]# ntpdate ntp.api.bz
23 Nov 11:25:55 ntpdate[17145]: adjust time server 47.98.146.45 offset -0.002469 sec
[root@localhost /]# cron
crond crontab
[root@localhost /]# crontab -e
先手动同步一下
然后放入定时任务中每隔10分钟执行一次

*/10 * * * * ntpdate ntp.api.bz
然后重启定时任务
[root@localhost /]# service crond restart
Stopping crond: [ OK ]
Starting crond: [ OK ]

查询是否安装ntp,若没有安装的话使用yum进行安装
rpm -q ntp
yum –y install ntp

猜你喜欢

转载自blog.csdn.net/liuyifeng1920/article/details/84380411