Linux下使用ntpdate命令进行时间同步

        最近做了一个功能(Java),默认查询当天开始时间(00:00:00)到当前时间节点的数据,问题就出现在当前时间节点上,发现两台服务器的时间有误差,然后把获取当前时间的代码去掉(new Date().toLocaleString()),再进行部署测试,发现可以了,但觉得这不是很好的一种解决方式,搜索一下,发现可以用ntpdate命令来进行时间同步。

        进入liunx命令控制台,输入date命令;输出如下:

若要更新时间,使用  date -s hh:mm:ss 即可

若要和Internet时间同步,使用ntpdate -u time.nist.gov同步网络时间,如果发现提示

说明服务器还没有安装ntpdate,我们使用yum install ntpdate -y 进行安装即可,

最后再使用  ntpdate - u  time.nist.gov同步网络时间,如果上面time.nist.gov服务器同步不了,提示如下:

19 Apr 12:02:42 ntpdate[1495]: no server suitable for synchronization found,可以换下面几个时间服务器试试:

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

hwclock命令   (即hardwareclock系统硬件时间)

#hwclock

显示硬件时间

#hwclock -w

将系统时间写入到系统硬件当中




猜你喜欢

转载自blog.csdn.net/cainiaobulan/article/details/80004814