Linux 系统有两个时间,一个是操作系统时间,还有个硬件时间,并且这两个时间不会自动同步,其中系统时间可以通过ntpdate 命令来同步,硬件时钟可以通过 hwclock 命令来同步,下面是简单实验过程:
同步 Linux 系统时间
1 |
[root@pgb init.d]# date -s " 2012-02-12 12:00:00" |
更改硬件时钟
1 |
[root@pgb init.d] |
显示当前硬件时钟
1 |
[root@pgb init.d]# hwclock --show |
备注: –systohc set the hardware clock to the current system time 将硬件时间和当前系统时间保持同步。
加入 Crontab
每小时同步系统时间和硬件时间,如下:
1 |
|
附: 网络时间服务器
微软公司授时主机(美国)
time.windows.com
台警大授时中心(台湾)
asia.pool.ntp.org
中科院授时中心(西安)
210.72.145.44
网通授时中心(北京)
219.158.14.130
Hwclock 命令说明
NAME
hwclock – query and set the hardware clock (RTC)
SYNOPSIS
hwclock -r or hwclock –show
hwclock -w or hwclock –systohc
hwclock -s or hwclock –hctosys
hwclock -a or hwclock –adjust
hwclock -v or hwclock –version
hwclock –set –date=newdate
hwclock –getepoch
hwclock –setepoch –epoch=year
DESCRIPTION
hwclock is a tool for accessing the Hardware Clock. You can display the current time, set the Hardware Clock
to a specified time, set the Hardware Clock to the System Time, and set the System Time from the Hardware
Clock.
You can also run hwclock periodically to insert or remove time from the Hardware Clock to compensate for sys-
tematic drift (where the clock consistently gains or loses time at a certain rate if left to run).
Ntpdate 命令说明
NAME
ntpdate – set the date and time via NTP
Disclaimer: The functionality of this program is now available in the ntpd program. See the -q command line
option in the ntpd – Network Time Protocol (NTP) daemon page. After a suitable period of mourning, the ntpdate
program is to be retired from this distribution
ntpdate sets the local date and time by polling the Network Time Protocol (NTP) server(s) given as the server
arguments to determine the correct time. It must be run as root on the local host. A number of samples are
obtained from each of the servers specified and a subset of the NTP clock filter and selection algorithms are
applied to select the best of these. Note that the accuracy and reliability of ntpdate depends on the number of
servers, the number of polls each time it is run and the interval between runs.
参考资料
- http://blog.sina.com.cn/s/blog_721cd3390101anth.html
- http://www.cnblogs.com/kaiyuanlee/articles/1921634.html
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/237822.html