GMT时间

经度为零的地点在英国『格林威治』这个城市所在的纵剖面上

格林威治时间为标准时间 (Greenwich Mean Time, GMT 时间)

格林威治以东的区域时间是比较快的(+小时)

因此中国在东八区本地时间 (local time) 会比 GMT 时间快 8 小时 (GMT + 8)

1880 年代的时间标准是以 GMT 时间为主


夏季节约时间(daylight savings)

在夏天的时候,白天的时间会比较长,所以为了节约用电, 因此在夏天的时候某些横跨两个时区的地区会将他们的时间定提早一小时(时区是8点定为9点)


UTC

最准确的计算应该是使用『原子震荡周期』所计算的物理时钟了 (Atomic Clock, 也被称为原子钟) ,也被定义为标准时间 (International Atomic Time)

UTC ( Coordinated Universal Time ,协和标准时间)就是利用这种 Atomic Clock 为基准所定义出来的正确时间


『网络校时』(Network Time Protocol, NTP通讯协议)

  • 软件时钟:由 Linux 操作系统根据 1970/01/01 开始计算的总秒数;

  • 硬件时钟:主机硬件系统上面的时钟,例如 BIOS 记录的时间;但由于芯片问题会有误差存在 所以需要校对

      NTP daemon 也同时以 server/client 及 master/slave 类似主从级架构来提供用户进行网络校时的动作

  1. 首先,主机当然需要启动这个 daemon ,之后,

  2. Client 会向 NTP Server 发送出调校时间的 message ,

  3. 然后 NTP Server 会送出目前的标准时间给 Client ,

  4. Client 接收了来自 Server 的时间后,会据以调整自己的时间,就达成了网络校时咯!


NTP服务器的层级概念

   TP 主机的设定时,都会先选择多部上层的 Time Server 来做为我们这一部 NTP Server 的校正之用

手动校对时间:date,hwclock

[root@clientlinux ~]# date MMDDhhmmYYYY选项与参数:
MM:月份
DD:日期
hh:小时
mm:分钟
YYYY:公元年# 1. 修改时间成为 1 小时后的时间该如何是好?
[root@clientlinux ~]# dateThu Jul 28 15:33:38 CST 2011

[root@clientlinux ~]# date 072816332011Thu Jul 28 16:33:00 CST 2011
# 瞧!时间立刻就变成一个小时后了!

[root@clientlinux ~]# hwclock [-rw]选项与参数:
-r :亦即 read ,读出目前 BIOS 内的时间参数;
-w :亦即 write ,将目前的 Linux 系统时间写入 BIOS 当中啊!
# 2. 查阅 BIOS 时间,并且写入更改过的时间啰!
[root@clientlinux ~]# date; hwclock -r
Thu Jul 28 16:34:00 CST 2011
Thu 28 Jul 2011 03:34:57 PM CST  -0.317679 seconds
# 看一看,是否刚好差异约一个小时啊!这就是 BIOS 时间!
[root@clientlinux ~]# hwclock -w; hwclock -r;
dateThu 28 Jul 2011 04:35:12 PM CST  -0.265656 seconds
Thu Jul 28 16:35:11 CST 2011
# 这样就写入啰~所以软件时钟与硬件时钟就同步啦!

 linux的网络校时

[root@clientlinux ~]# ntpdate [-dv] [NTP IP/hostname]
选项与参数:
-d :进入除错模式 (debug) ,可以显示出更多的有效信息。
-v :有较多讯息的显示。[root@clientlinux ~]# ntpdate 192.168.100.254
28 Jul 17:19:33 ntpdate[3432]: step time server 192.168.100.254 offset -2428.396146 sec
# 最后面会显示微调的时间有多少 (offset)
[root@clientlinux ~]# date; hwclock -r
四  7月 28 17:20:27 CST 2011
公元2011年07月28日 (周四) 18时19分26秒  -0.752303 seconds
# 知道鸟哥想要表达什么吗?对啊!还得 hwclock -w 写入 BIOS 时间才行啊!
[root@clientlinux ~]# vim /etc/crontab
# 加入这一行去!
10 5 * * * root (/usr/sbin/ntpdate tock.stdtime.gov.tw && /sbin/hwclock -w) &> /dev/null

启动NTP服务 主动去更新时间

[root@clientlinux ~]# ntpdate 192.168.100.254
# 由于 ntpd 的 server/client 之间的时间误差不允许超过 1000 秒,
# 因此你得先手动进行时间同步,然后再设定与启动时间服务器呦!
[root@clientlinux ~]# vim /etc/ntp.conf
#server 0.centos.pool.ntp.org
#server 1.centos.pool.ntp.org
#server 2.centos.pool.ntp.org
restrict 192.168.100.254  <==放行服务器来源!
server 192.168.100.254    <==这就是服务器!
# 很简单,就是将原本的 server 项目批注,加入我们要的服务器即可
[root@clientlinux ~]# /etc/init.d/ntpd start
[root@clientlinux ~]# chkconfig ntpd on