比思論壇

標題: NTP(3) [打印本頁]

作者: zhaoxu6679    時間: 2015-4-27 17:32
標題: NTP(3)

3. Real Time Clock(RTC) and System Clock说道设置时间这里还要明确另外一个概念就是在一台计算机上我们有两个时钟:一个称之为硬件时间时钟(RTC),还有一个称之为系统时钟(System Clock)
硬件时钟是指嵌在主板上的特殊的电路, 它的存在就是平时我们关机之后还可以计算时间的原因
系统时钟就是操作系统的kernel所用来计算时间的时钟. 它从1970年1月1日00:00:00 UTC时间到目前为止秒数总和的值 在Linux下系统时间在开机的时候会和硬件时间同步(synchronization),之后也就各自独立运行了那么既然两个时钟独自运行,那么时间久了必然就会产生误差了,下面我们来看一个例子

# date
Fri Jul 6 00:27:13 BST 2007

[root@rhe5 /]# hwclock --help
hwclock - query and set the hardware clock (RTC)

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

Functions:
  --help        show this help
  --show        read hardware clock and print result
  --set         set the rtc to the time given with --date
  --hctosys     set the system time from the hardware clock
  --systohc     set the hardware clock to the current system time
  --adjust      adjust the rtc to account for systematic drift since
                the clock was last set or adjusted
  --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
  --version     print out the version of hwclock to stdout

Options:
  --utc         the hardware clock is kept in coordinated universal time
  --localtime   the hardware clock is kept in local time
  --directisa   access the ISA bus directly instead of /dev/rtc
  --badyear     ignore rtc's year because the bios is broken
  --date        specifies the time to which to set the hardware clock
  --epoch=year  specifies the year which is the beginning of the
                hardware clock's epoch value
  --noadjfile   do not access /etc/adjtime. Requires the use of
                either --utc or --localtime

# hwclock --show
Fri 06 Jul 2007 12:27:17 AM BST -0.968931 seconds通过hwclock --show命令我们可以查看机器上的硬件时间(always in local time zone), 我们可以看到它和系统时间还是有一定的误差的, 那么我们就需要把他们同步
# hwclock –hctosys  把硬件时间设置成系统时间

# hwclock –systohc  把系统时间设置成硬件时间

# hwclock --set --date="mm/dd/yy hh:mm:ss"   设置硬件时间我们可以开机的时候在BIOS里设定.也可以用hwclock命令

# date -s "dd/mm/yyyy hh:mm:ss" 修改系统时间用date命令就最简单了

现在我们知道了如何设置系统和硬件的时间. 但问题是如果这两个时间都不准确了怎么办? 那么我们就需要在互联网上找到一个可以提供我们准确时间的服务器然后通过一种协议来同步我们的系统时间,那么这个协议就是NTP了. 接下去我们所要说的同步就都是指系统时间和网络服务器之间的同步了



作者: 13457585991    時間: 2015-4-27 17:52
脑洞大开啊




歡迎光臨 比思論壇 (http://108.170.10.236/) Powered by Discuz! X2.5