已索引

Real Time Clock(RTC) and System Clock

关于时间,这里还要明确一个概念:
在一台计算机上我们有两个时钟:一个称之为硬件时间时钟(RTC),还有一个称之为系统时钟(System Clock)

硬件时钟是指嵌在主板上的特殊的电路, 有了它的存在,即使我们的电脑不联网,关机之后还可以计算时间。
系统时钟就是操作系统的kernel所用来计算时间的时钟. 它从1970年1月1日00:00:00 UTC时间到目前为止秒数总和的值。

我们可以使用 date 命令来查看或手动设置系统时钟,使用 hwclock 来查看或手动设置硬件时钟。
尽管我们很少去使用 hwclock 命令来设置硬件时钟,这儿还是打印它的一些帮助来让我们更好地理解上面的概念。

# hwclock --help
hwclock - query and set the hardware clock (RTC)

Usage: hwclock [function] [options...]

Functions:
  -h | --help         show this help
  -r | --show         read hardware clock and print result
       --set          set the rtc to the time given with --date
  -s | --hctosys      set the system time from the hardware clock
  -w | --systohc      set the hardware clock to the current system time
       --systz        set the system time based on the current timezone
       --adjust       adjust the rtc to account for systematic drift since
                      the clock was last set or adjusted
  -c | --compare      periodically compare the system clock with the CMOS clock
       --getepoch     print out the kernel's hardware clock epoch value
       --setepoch     set the kernel's hardware clock epoch value to the
                      value given with --epoch
  -v | --version      print out the version of hwclock to stdout

Options:
       --date         specifies the time to which to set the hardware clock
       --test         do everything except actually updating the hardware clock or anything else

Linux系统在开机的时候,系统时钟会自动和硬件时间同步(synchronization),之后就各自独立运行了。
那么既然两个时钟独自运行,那么时间久了必然就会产生误差了。
我们可以人为把这两个时间同步,但问题是这两个时间其实都不准确。
那么我们就需要在网络上找到一个可以为我们提供准确时间的服务器,然后通过一种协议来同步我们的系统时间。
这个协议就是NTP(Network Time Protocol),我们通常所说的同步都是指系统时间和网络时间服务器之间的同步。
NTP本身是一个很复杂的协议,但与NTP相关的运维工作并不难。

NTP时间同步通常的结构是这样的:
卫星(由原子钟提供准确时间)——> 时间服务器(如寰泰的GTT400) ——> 网关设备 ——> 主机

-- By 许望(RHCA、OCM、VCP)
最后修改:2023 年 09 月 15 日 05 : 06 PM
如果觉得我的文章对你有用,请随意赞赏