温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Linux date 时间设置同步命令分享

发布时间:2020-10-25 10:20:16 来源:脚本之家 阅读:181 作者:北漂的SA 栏目:服务器

date命令:

#date
显示系统时间

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

#hwclock
显示硬件时间
#hwclock -w
将系统时间写入到系统硬件当中

ntpdate

ntpdate 是一个linux时间同步服务软件,具体的详细资料请参考下百度,有很多详细的资料

查看本机是否安装ntpdate服务,如果没有安装,请 yum install -y ntpdate

同步时间

输入ntpdate time.nist.gov同步网络时间

结果:3 Jun 15:42:39 ntpdate[4721]: adjust time server 211.115.194.21 offset -0.005885 sec

出现上述结果代表时间同步成功,上面的大致意思为调整时间为服务器211.115.194.21的时间,相差-0.005885秒的时间
如果上面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

同步时间成功后调整硬件时间

#hwclock -w

执行成功后, 查看系统硬件时间(不出意外的话,现在date和hwclock现实的时间均为internet时间)

#date
#hwclock

执行上述命令,显示的时间应该一样的

定时执行时间同步任务,所以我们利用crontab -e 来添加定时任务

/1 ntpdate time.nuri.net;hwclock -w

即:#每隔一个小时同步一下internet时间,并写入硬件

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI