自己安装和配置了一个NTP服务器的一些心得,希望与大家分享。写了一个文档包含了各个命令和参数的具体含义,由于不能上传无法与大家分享。以后还希望大家多多支持和帮助我们共同成长,我会不断做把这些年的经营和教训与大家分享。

在日常生活中,我们会遇到服务器或我们的PC时间不准确的问题。特别是在一些比较重要的行业中,系统对时间的要求又比较高。系统需要一个准确而可靠的时钟源来保障应用的运行。特别在证券行业中,时间的要求更加严格。一般可以根据证交所提供的时间为准,在报盘系统的工作站上,证交所会每天强制更新其时间,以达到该时间与交易所配置的标准时间为准。我们可以设置该工作站为NTP服务器,为其他系统提供与交易所相同的时间服务。同时在互联网上有大量的时间服务器可以连接,可以配置为其客户端来校准我们主机的时间。

1 NTP服务介绍

Network Time Protocol(NTP)是用来使计算机时间同步化的一种协议,它可以使计算机对其服务器或时钟源(如石英钟,GPS等等)做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒,WAN上几十毫秒),且可介由加密确认的方式来防止恶毒的协议攻击。NTP可以利用多个途径和来源的时间服务器来更加精确的校正时间。

现在绝大部分的操作系统都支持NTP,比如在Unix和Windows中都有他们自己的NTP服务。比如在Windows中的SNTP。由于各个系统厂商会根据自己的系统情况对NTP来进行优化和设置,更加适合他自己的系统,对于其他系统的兼容性就会差很多。还有不同时期的系统会使用不同版本的NTP服务。最新版本位V4,由于每个版本都要他自己的一些特征。所以在设置NTP服务器时会有一些兼容性问题。因此,在多类型操作系统的环境中,尽量使用NTP官方组织提供的软件进行设置而不使用其他厂商在系统中默认提供的NTP服务器。NTP官方组织为 www.ntp.org

2  NTP服务器的运行方式

NTP服务器的使用方式包括,固定连接和动态连接方式。在固定连接中,客户端仅仅接收指定的服务器端的连接,无论服务端是否正常连接他都不会去换另外的服务器端接收时间。一般客户/服务器方式为这种模式。另外一直为动态连接,客户端在不停接收服务器端的广播信息,当一台服务器停止服务,只要有服务器广播出来的正确可靠的时间信息,客户端就可以正常的更新时间。一般为广播方式连接。

服务器/客户端方式

客户服务器方式为在互联网上使用最为广泛的一种方法,在设定服务器后,他可以灵活的配置客户端,让客户端选择是否使用NTP服务器或使用那台NTP服务器。客户服务器方式使用常用的RPC(remote-procedure-call)方式来传输时间信息。他们运行的过程为,客户端发出时间请求给服务器端,然后根据服务器端的答复来调节时间。

一般在客户端可以定义他们同步时间的间隔,和他们请求最大和最小的时间间隔。客户端会根据自己时钟时间和NTP服务器时间进行比对,如果客户端本机时钟比较准确,他们查询的时间间隔就会变长,如果本机时间出现误差较大,客户端会在比较短的时间内做出时间请求,来保障客户端时间的精确度。

广播/多播方式

多播和广播方式利用在以太网上的广播和多播协议来进行时间同步,时间服务器会定时发出广播和多播信息给指定的网段。使用广播和多播需要网络设备支持该协议,同时客户端也支持该协议。可以使用multicasting和manycasting在不同网段进行广播信息,来达到在包含多个网段的复杂网络中使用广播和多播来提供NTP服务。

主动/被动方式

主动/被动方式最多使用在集群系统中,由于集群系统对同一集群内的所有服务器的时间同步要求比较严格,他们相互配置为NTP服务器端和客户端,在不停的提供时钟同步服务,当其中的一台服务器出现停顿时不会影响到其他服务器的时间同步。可以说时互备的方式来进行时间同步服务。

3 NTP配置文件

文件名

默认位置

选项

使用命令

配置文件

/etc/ntp.conf

-c

none

频率文件

/etc/ntp.drift

-f

driftfile

进程pid文件

None

-p

pidfile

日志文件

system log

-l

logfile

库文件

None

none

includefile

状态信息文件

/var/NTP

-s

statsdir

密码文件

/usr/local/etc

-k

keysdir

4 NTP服务器的配置

服务器端配置

在NTP服务器端的默认配置文件为/etc/ntp.conf文件(根据不同OS可能在不同位置,如在Solaris下为 /etc/inet/ntp.conf)。

配置文件的参数:

主要的四个参数:

server address [options ...]

peer address [options ...]

broadcast address [options ...]

manycastclient address [options ...]

这四个参数主要是指定NTP服务器使用的服务器名称和IP地址以及他们的运行模式。名称或地址可以是主机名、IP地址和DNS解析后的域名。

Server一般用于服务器端,该服务器不会去同步其他服务器时间,一般server后可以跟  127.127.1.0 该地址代表本级的时钟,如果Server后跟其他服务器IP,表示会去同步其他时间服务器的地址。

Peer一般配置中表示,服务器接收其他服务器的地址,同时也会为其他设备提供NTP服务器。

Broadcast配置为广播地址

Manycastclient配置为多播地址

具体解释如下:

server

For type s and r addresses (only), this command normally mobilizes a persistent client mode association with the specified remote server or local reference clock. If the preempt flag is specified, a preemptable association is mobilized instead. In client mode the client clock can synchronize to the remote server or local reference clock, but the remote server can never be synchronized to the client clock. This command should NOT be used for type b or m addresses.

peer

For type s addresses (only), this command mobilizes a persistent symmetric-active mode association with the specified remote peer. In this mode the local clock can be synchronized to the remote peer or the remote peer can be synchronized to the local clock. This is useful in a network of servers where, depending on various failure scenarios, either the local or remote peer may be the better source of time. This command should NOT be used for type b, m or r addresses.

broadcast

For type b and m addresses (only), this command mobilizes a persistent broadcast mode association. Multiple commands can be used to specify multiple local broadcast interfaces (subnets) and/or multiple multicast groups. Note that local broadcast messages go only to the interface associated with the subnet specified, but multicast messages go to all interfaces.

In broadcast mode the local server sends periodic broadcast messages to a client population at the address specified, which is usually the broadcast address on (one of) the local network(s) or a multicast address assigned to NTP. The IANA has assigned the multicast group address IPv4 224.0.1.1 and IPv6 ff05::101 (site local) exclusively to NTP, but other nonconflicting addresses can be used to contain the messages within administrative boundaries. Ordinarily, this specification applies only to the local server operating as a sender; for operation as a broadcast client, see the broadcastclient or multicastclient commands below.

manycastclient

For type m addresses (only), this command mobilizes a preemptable manycast client mode association for the multicast group address specified. In this mode a specific address must be supplied which matches the address used on the manycastserver command for the designated manycast servers. The NTP multicast address 224.0.1.1 assigned by the IANA should NOT be used, unless specific means are taken to avoid spraying large areas of the Internet with these messages and causing a possibly massive implosion of replies at the sender.

The manycastclient command specifies that the host is to operate in client mode with the remote servers that are discovered as the result of broadcast/multicast messages. The client broadcasts a request message to the group address associated with the specified address and specifically enabled servers respond to these messages. The client selects the servers providing the best time and continues as with the server command. The remaining servers are discarded as if never heard.

 

附加选项参数:

同时还可以添加一下的参数来控制NTP服务

autokey

burst

iburst

key key

minpoll minpoll
maxpoll maxpoll

noselect

preempt

prefer

true

ttl ttl

version version

dynamic

同时NTP服务器还有配置安全,加密,在不同网段等的配置,具体可以参照 www.ntp.org.

客户端配置

1.      UNIX、Linux服务器的配置方法为:

编辑/etc/ntp.conf(在Solaris中为/etc/inet/ntp.conf)

在文件中加入 server   IPADDRESS

2.      在Windows 2000中配置方式:

在命令行模式输入:

net time /SETSNTP:10.20.0.1  (指定NTP服务器IP)

net stop w32time        (关闭NTP服务)

Net start w32time      (启动NTP服务)

w32tm –s                (同步NTP时间)

3.      在Windows XP中配置为:

控制面板à日期、时间、语言和区域设置à日期和时间

在服务器筐中添加NTP服务器的IP地址就可以了。

5  NTP中的命令

ntpd命令

ntpd命令为NTP服务的配置进程,同时ntpd命令可以配置ntp服务。执行时ntpd从配置文件/etc/ntp.conf中读取配置信息然后去执行该配置文件中指定的属性。

ntpd命令的参数选项使用方法:

ntpd [ -46aAbdDgLmnNqx ] [ -c conffile ] [ -f driftfile ] [ -i jaildir ] [ -k keyfile ] [ -l logfile ] [ -p pidfile ] [ -Ppriority ] [ -r broadcastdelay ] [ -s statsdir ] [ -t key ] [ -u user[:group] ] [ -U interface_update_interval ] [ -v variable ] [ -V variable ]

Ntpq命令

Ntpq命令是用来查询ntp服务的命令,可以查询比较详细的信息,其中包含参数命令模式和交互命令模式。

ntpq [-inp] [-c command] [host] [...]

Ntpdc命令

Ntpdc是一个特殊的ntp查询命令

ntpdc [ -ilnps ] [ -c command ] [ host ] [ ... ]

Ntptrace命令

Ntptrace命令是追踪ntp服务传输信息的命令,可以查看服务的传输状况,查找ntp信息从那个服务器发出以及命令传输的过程。

ntptrace [ -vdn ] [ -r retries ] [ -t timeout ] [ server ]

NTP多种模式的配置的更多相关文章

  1. ntp时间同步,各种配置方法

    1 Windows xp NTP服务器的配置(2003配置方式一样) 1) 首先需要关闭作为NTP服务器的windows系统自带的防火墙,否则将同步不成功. 2) 单击“开始”,单击“运行”,键入 r ...

  2. LVS-NAT模式的配置详解

    由于实验室拟态存储的项目需要通过NAT模式来映射NFS服务器已实现负载均衡的目的,通过调研了多种负载均衡机制,笔者最终选择了LVS的NAT模式来实现需求,接下来通过博客来记录一下LVS-NAT模式的配 ...

  3. 新书出版《.NET框架设计—模式、配置、工具》感恩回馈社区!

    很高兴我的第一本书由图灵出版社出版.本书总结了我这些年来对框架学习.研究的总结,里面纯干货,无半句废话. 书的详情请看互动网的销售页面:http://product.china-pub.com/377 ...

  4. linux网卡速率和双工模式的配置

    linux网卡速率和双工模式的配置 (2012-09-06 14:39:57) 转载▼ 标签: 科技 网络接口 协商 网卡 工具 it 分类: Linux 改变网络接口的速度和协商方式的工具miito ...

  5. windows server 2012 R2 远程桌面授权模式尚未配置

    windows server 2012 R2 远程桌面授权模式尚未配置,远程桌面服务将在120天内停止工作.如何破解这个宽限期,目前企业7位协议号码均不包含2012 R2以上授权. 那么只能蛋疼的“破 ...

  6. nginx 隐藏 index.php 和 开启 pathinfo 模式的配置

    nginx 通过 location 的规则匹配将 php 转发给 php-fpm 处理后获取结果然后返回给客户端,转发模式可以通过 unix sock 或 tcp socket 方式.百度了好多文章我 ...

  7. MT7628如何配置使用 Openwrt路由模式 (校园网配置)

    1.设置wan,把网线插入wan口 1) 在 MT7628 开发板上的 3 个网口默认都是“LAN 口”功能,但拨号上网一般需要用到“WAN口”的功能,所以我们需要将其中一个切换为“WAN 口”,这里 ...

  8. Hadoop单机模式的配置与安装

    Hadoop单机模式的配置与安装 单机hadoop集群正常启动后进程情况 ResourceManager NodeManager SecondaryNameNode NameNode DataNode ...

  9. ntp时间服务器--Linux配置

       时间服务器作用: 大数据产生与处理系统是各种计算设备集群的,计算设备将统一.同步的标准时间用于记录各种事件发生时序, 如E-MAIL信息.文件创建和访问时间.数据库处理时间等. 大数据系统内不同 ...

随机推荐

  1. [转帖] 一文看懂:"边缘计算"究竟是什么?为何潜力无限?

    一文看懂:"边缘计算"究竟是什么?为何潜力无限? 转载cnbeta   云计算 雾计算 边缘计算...   知名创投调研机构CB Insights撰文详述了边缘计算的发展和应用前景 ...

  2. spring注入 属性注入 构造器注入 set方法注入

    spring注入 属性注入 构造器注入 set方法注入(外部bean注入)

  3. Appium+python自动化环境搭建(小白适用)

    写在前面: 没开始搭建前听好多人说,学习appium80%的人都死于环境搭建,所以一开始很紧张,在搭建环境中也确实遇到了好几个问题,由于之前本人使用app测试经验很少,所以相当于app小白,因此有的问 ...

  4. 【CF522A】Reposts

    题目大意:给定一个有向图,求图中最长路. 题解:直接拓扑排序后按照拓扑序枚举即可.处理时应将字符串通过 map 映射成一个点,同时注意字符串大小写转换,C++ string 中没有提供直接大小写转换的 ...

  5. NO.2: 尽量以const,enum,inline 替换 #define

    1.首先#define 定义不重视作用域(scope),虽然可以#undef控制,但是不美观,还存在多次替换的问题,以及没有任何封装性. 2.const XXX_XX,保证其常量性以及可控的作用域,如 ...

  6. php Mockery 错误 "call_user_func_array() expects parameter 1 to be a valid callback, class 'Mockery\Expectation' does not have a method"

    错误写法 $mock = Mockery::mock(MyClass::class) ->shouldReceive('foo') ->once() ->with($arg) -&g ...

  7. linux driver ------ 三星公司uboot模式下更改分区(EMMC)大小fdisk命令 ------ iTOP4412 开发板烧写

    核心板 SCP 1G eMMC:KLM8G------>8G 终端(串口)输入(如果执行过,只需要执行最后一句即可): 开发板一启动,立马在终端按回车,进入 uboot 模式 fdisk -c ...

  8. JAVA (字符串学习)

    String类 String类是不可改变的,所以你一旦创建了String对象,那它的值就无法改变了. 如果需要对字符串做很多修改,那么应该选择使用StringBuffer&StringBuil ...

  9. [机器学习]-SVD奇异值分解的基本原理和运用

    SVD奇异值分解: SVD是一种可靠的正交矩阵分解法.可以把A矩阵分解成U,∑,VT三个矩阵相乘的形式.(Svd(A)=[U*∑*VT],A不必是方阵,U,VT必定是正交阵,S是对角阵<以奇异值 ...

  10. Tomcat权威指南-读书摘要系列10

    Tomcat集群 一些集群技术 DNS请求分配 TCP网络地址转换请求分配 Mod_proxy_balance负载均衡与故障复原 JDBC请求分布与故障复原