-
date命令:
$ date
:显示系统时间 -
hwclock命令 (即hardwareclock系统硬件时间)
$ hwclock
:显示硬件时间
$ hwclock -w
:将系统时间写入到系统硬件当中 -
ntpdate命令
ntpdate 是一个linux时间同步服务软件
$ yum install -y ntpdate
$ ntpdate 0.asia.pool.ntp.org
:同步网络时间
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 命令
$ vi /etc/crontab
30 4 * * * root ntpdate 0.asia.pool.ntp.org && hwclock -w
每天 4:30:00 执行一次时间同步
网友评论