NTP服务器的搭建

简介:

一、服务介绍

NTPNetwork Time Protocol,网络时间协议)是用来使计算机时间同步化的一种协议。它可以使计

算机对其服务器或时钟源做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒,

WAN上几十毫秒),且可介由加密确认的方式来防止恶毒的协议攻击。

二、运行模式

模式: C/S 模式

运行模式:

wKiom1ZF8xDzKFVvAABPhWp3Z_k567.png

三、NTP服务器环境的配置

1.实验环境

NTP服务端:localhost1.cn   IP192.168.10.63

NTP客户端:localhost2.cn   IP192.168.10.64


wKiom1ZF81CxL_P1AAAtl3auOfM248.png

 2NTP服务器的配置

[root@localhost ~]# rpm -ivh/mnt/Packages/ntpdate-4.2.6p5-1.el6.x86_64.rpm

[root@localhost ~]# /etc/init.d/ntpd  restart


[root@localhost ~]# vim /etc/ntp.conf            ntp 的配置文件

[root@localhost ~]# ntpdate server0.rhel.pool.ntp.org         同步ntp时间报错

13 Nov 18:33:47 ntpdate[8145]: the NTPsocket is in use, exiting

原因

出现该错误的原因是系统ntpd服务器正在运行中,通过 ps aux | grep ntpd 查看,会看到ntpd正在运行。

wKiom1ZF86WgroAhAAAnHl-fhuM895.png

解决办法

[root@localhost ~]# /etc/init.d/ntpd stop  停止服务


wKiom1ZF89DDeBd2AAA0hMAjgfo819.png

备注:这里需要虚拟机可以连接到外网


搭建一个内网NTP服务器,让内网服务器通过此NTP服务器进行时间同步

[root@localhost ~]# vim /etc/ntp.conf

11 # Permit all access over the loopbackinterface.  This could

 12 #be tightened as well, but to do so would effect some of

 13 #the administrative functions.

 14restrict 127.0.0.1  如果无同步时间,就和本地系统时间同步。

 15restrict -6 ::1

 16

 17 #Hosts on local network are less restricted.

 18 restrict 192.168.10.0mask 255.255.255.0 nomodify notrap

允许同步的本地局域网时间

 19

 20 # Use public serversfrom the pool.ntp.org project.

 21 # Please considerjoining the pool (http://www.pool.ntp.org/join.html).

 22 server 128.138.141.172

指定本NTP服务器的上游NTP服务器为128.138.141.172,并且设置为首先服务器。同步时间为,从上到下,写的越靠上,优先级越高。(写在所有server最前面IP地址为首先服务器,此服务器同步不了时间,寻找下一个NTP服务器)。此IP地址是日本福冈大学NTP服务器。  在原配置文件中添加一个外网NTP服务器

23 server 1.rhel.pool.ntp.org iburst

 24server 2.rhel.pool.ntp.org iburst

 25server 3.rhel.pool.ntp.org iburst

 

在启动NTP服务前,先对提供服务的这台主机手动的校正一次时间。 ntpd 有一个自我保护设置如果本机与上源时间相差太大, ntpd 不运行.

[root@localhost ~]# ntpdate cn.pool.ntp.org

13 Nov 18:58:31 ntpdate[8214]: adjust timeserver 202.112.29.82 offset 0.000931 sec

 

[root@localhost ~]# /etc/init.d/ntpd start  启动服务


wKioL1ZF9GHQsAMxAABUCt8NvpM546.png


[root@localhost ~]# ntpstat

synchronised to NTP server(128.138.141.172) at stratum 2   #可以看到我们当前在2层。

  time correct to within 470 ms   # ms毫秒是一种较为微小的

  polling server every 128 s     轮询时间

 

[root@localhost ~]# ntpq –p  列出我们的NTP服务器与上游服务器的连接状态

    remote           refid      st t when poll reach   delay  offset  jitter

==============================================================================

*utcnist2.colora .ACTS.           1 u 466  128  150 337.011   14.735  60.291

 dns.sjtu.edu.cn .INIT.          16 u    - 1024   0    0.000    0.000  0.000

+dns1.synet.edu. 202.118.1.46     2 u 233  128  176 115.893   99.310  68.327

参数说明

指令“ntpq -p”可以列出目前我们的NTP与相关的上层NTP的状态,以上的几个字段的意义如下:

remote:即remote - 本机和上层ntpip或主机名,“+”表示优先,“*”表示次优先。

refid:参考的上一层NTP主机的地址

st:即stratum阶层             poll:下次更新在几秒之后          offset:时间补偿的结果

客户端同步时间

说明:在启动NTP服务前,先对提供服务的这台主机手动的校正一次时间。 ntpd 有一个自我保护设置如果本机与上源时间相差太大, ntpd 不运行.

[root@localhost ~]# date

2015 11 13 星期五 20:11:34 CST

[root@localhost1 ~]# date  同步时间前

2015 11 13 星期五 20:09:39 CST

[root@localhost1 ~]# ntpdate 192.168.10.63  同步时间

13 Nov 20:12:53 ntpdate[7737]: step timeserver 192.168.10.63 offset 130.847558 sec

[root@localhost1 ~]# date

2015 11 13 星期五 20:13:00 CST

拓展

linux系统时间和BIOS时间是不是一定一样?

查看硬件BIOS时间:

hwclock-r    :读出BIOS的时间参数

hwclock-w    :将当前系统时间写入BIOS中。

 

为了避免主机时间因为长期运作下所导致的时间偏差,进行时间同步(synchronize)的工作是非常必要的。

同步时间,可以使用ntpdate命令,也可以使用ntpd服务。

通常采用crontab 做计划任务

0 12 *  * * /usr/sbin/ntpdate 0.rhel.pool.ntp.org




本文转自 水滴石川1 51CTO博客,原文链接:http://blog.51cto.com/sdsca/1712636,如需转载请自行联系原作者

相关文章
|
Ubuntu 安全 机器人
把Windows打造成一个NTP时间同步服务器
把Windows打造成一个NTP时间同步服务器
把Windows打造成一个NTP时间同步服务器
|
弹性计算 Windows
同步服务器时间NTP
在秒杀、抢券等高并发的活动中,一点点的时间延迟,也会让自己后悔莫及……
1468 0
同步服务器时间NTP
|
Ubuntu Linux 虚拟化
使用阿里云镜像站NTP服务搭建NTP服务器(基于CentOS 7系统)
使用阿里云镜像站NTP服务搭建NTP服务器(基于CentOS 7系统)
1410 0
使用阿里云镜像站NTP服务搭建NTP服务器(基于CentOS 7系统)
|
安全 Linux 网络安全
手把手教你在centos 7.4上搭建NTP服务器
手把手教你在centos 7.4上搭建NTP服务器
734 0
手把手教你在centos 7.4上搭建NTP服务器
|
测试技术 Windows
Windows下安装NTP服务器
原文:Windows下安装NTP服务器 NTP服务器介绍 NTP服务器【Network Time Protocol(NTP)】是用来使计算机时间同步化的一种协议,它可以使计算机对其服务器或时钟源(如石英钟,GPS等等)做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒,WAN上几十毫秒)。
2954 0
|
5月前
|
Linux
CentOS7搭建ntp时钟服务器
CentOS7搭建ntp时钟服务器
673 0
|
7月前
NTP服务器时间配置
NTP服务器时间配置
158 0
|
11月前
|
安全 Linux 网络安全
Linux 时间同步 -NTP 服务器
本文主要介绍如何配置 Linux 服务器集群的时间同步,技术实现上使用 NTP 服务器和客户端同步时间。
430 0
|
Linux 网络安全
linux篇-CentOS7搭建NTP服务器
linux篇-CentOS7搭建NTP服务器
866 0
linux篇-CentOS7搭建NTP服务器