C. 时钟同步

在实践中,会发现编译机和版本控制服务器的时钟同步非常重要。因为编译机确定编译的时间,是从本地取时钟,编译成功后,要将编译时间 checkin 到版本控制服务器,以便下次执行自动编译时,从该文件获取上次编译时间,比较两个时间间隔内有否代码改动。如果发布机的时钟和版本控制系统的时钟不一致,会导致代码更新的误判。

最近在网上发现了一篇文章,《A Beginner's Guide to Network Time Protocol--Other Time Software》,非常巧合的是,我在选择时间同步方案的时候,走了几乎相同的路。

对于工作组内平台相对单一,时钟同步是一件非常简单的事情:

加入 Windows 域的 Windows 平台的机器会定期和域控制服务器时钟同步。亦可以使用命令"net time /setsntp" 和 ntp 服务器时钟同步。

对于Unix服务器来说,则有更多选择的余地。例如:从最简单的使用13端口的 RFC867 daytime 协议;使用基于 RFC868 Time Protocol 的 rdate 命令从服务器读取时间来设置本地时间;运行 timed,保持 unix 机器自动同步时钟;以及用 ntp 协议和国际标准时同步。

对于复杂的网络环境,使用 ntp 确是上选。

Servers that provide synchronization to a sizeable population of clients normally operate as a group of three or more mutually redundant servers, each operating with three or more stratum-one or stratum-two servers in client-server modes, as well as all other members of the group in symmetric modes. This provides protection against malfunctions in which one or more servers fail to operate or provide incorrect time. The NTP algorithms have been specifically engineered to resist attacks where some fraction of the configured synchronization sources accidently or purposely provide incorrect time. In these cases a special voting procedure is used to identify spurious sources and discard their data.

参见:《A Beginner's Guide to Network Time Protocol (NTP)》, 《Notes on setting up a NTP subnet》...

Unix上的 NTP软件:

下载...

Windows上的 NTP客户端的配置: