NTP时间服务器 搭建

简介: 1.1 NTP简介 NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。它的用途是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可达0.1ms,在互联网上绝大多数的地方其精度可以达到1-50ms。

1.1 NTP简介

NTPNetwork Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。它的用途是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可达0.1ms,在互联网上绝大多数的地方其精度可以达到1-50ms

NTP服务器就是利用NTP协议提供时间同步服务的。

系统版本

1 [root@test ~]# cat /etc/redhat-release 
2 CentOS release 6.9 (Final)

 

1.2 NTP服务器安装

 

1 [root@test ~]# rpm -qa ntp
2 ntp-4.2.6p5-10.el6.centos.2.x86_64

   如果没有安装就yum install ntp -y进行安装

1.3 配置NTP服务

备份配置文件

1 [root@test ~]# cp /etc/ntp.conf{,.bak}
2 
3 [root@test ~]# ll /etc/ntp.conf*
4 
5 -rw-r--r--. 1 root root 1778 Jan 11  2017 /etc/ntp.conf
6 
7 -rw-r--r--  1 root root 1778 Oct 23 23:10 /etc/ntp.conf.bak

精简化配置文件

1 [root@test ~]# egrep -v "^$|#" /etc/ntp.conf.bak  >/etc/ntp.conf

修改配置文件

 1 # For more information about this file, see the man pages
 2 # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
 3 
 4 driftfile /var/lib/ntp/drift
 5 
 6 # Permit time synchronization with our time source, but do not
 7 # permit the source to query or modify the service on this system.
 8 restrict default kod nomodify notrap nopeer noquery
 9 restrict -6 default kod nomodify notrap nopeer noquery
10 
11 # Permit all access over the loopback interface.  This could
12 # be tightened as well, but to do so would effect some of
13 # the administrative functions.
14 restrict 127.0.0.1 
15 restrict -6 ::1
16 
17 # Hosts on local network are less restricted.
18 #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
19 # 允许内网其他机器同步时间
20 restrict 172.16.1.0 mask 255.255.255.0 nomodify notrap
21 
22 # Use public servers from the pool.ntp.org project.
23 # Please consider joining the pool (http://www.pool.ntp.org/join.html).
24 #server 0.centos.pool.ntp.org iburst
25 #server 1.centos.pool.ntp.org iburst
26 #server 2.centos.pool.ntp.org iburst
27 #server 3.centos.pool.ntp.org iburst
28 
29 # 定义使用的上游 ntp服务器,将原来的注释
30 server time1.aliyun.com
31 server ntp1.aliyun.com
32     
33 #broadcast 192.168.1.255 autokey    # broadcast server
34 #broadcastclient            # broadcast client
35 #broadcast 224.0.1.1 autokey        # multicast server
36 #multicastclient 224.0.1.1        # multicast client
37 #manycastserver 239.255.254.254        # manycast server
38 #manycastclient 239.255.254.254 autokey # manycast client
39 
40 # 允许上层时间服务器主动修改本机时间
41 restrict time1.aliyun.com  nomodify notrap noquery
42 restrict ntp1.aliyun.com  nomodify notrap noquery
43 
44 # 外部时间服务器不可用时,以本地时间作为时间服务
45 server  127.127.1.0    
46 fudge   127.127.1.0 stratum 10
47 
48 # Enable public key cryptography.
49 #crypto
50 
51 includefile /etc/ntp/crypto/pw
52 
53 # Key file containing the keys and key identifiers used when operating
54 # with symmetric key cryptography. 
55 keys /etc/ntp/keys
56 
57 # Specify the key identifiers which are trusted.
58 #trustedkey 4 8 42
59 
60 # Specify the key identifier to use with the ntpdc utility.
61 #requestkey 8
62 
63 # Specify the key identifier to use with the ntpq utility.
64 #controlkey 8
65 
66 # Enable writing of statistics records.
67 #statistics clockstats cryptostats loopstats peerstats

1.4 启动NTP服务器

注意:如果有同步时间的定时任务要将其注销,否则会冲突

1 [root@test ~]# /etc/init.d/ntpd start
2 Starting ntpd:                                             [  OK  ]

显示节点列表

1 [root@test ~]# ntpq -p
2      remote           refid      st t when poll reach   delay   offset  jitter
3 ==============================================================================
4  time5.aliyun.co 10.137.38.86     2 u   28   64    3    5.092  6241215 185.623
5 
6  132.163.96.4    .INIT.          16 u    -   64    0    0.000    0.000   0.000

1.5 客户机时间同步

客户机要等几分钟再与新启动的ntp服务器进行时间同步,否则会提示

no server suitable for synchronization found错误

1 [root@client ~]# ntpdate 10.0.0.250
2 24 Oct 16:46:58 ntpdate[26694]: adjust time server 10.0.0.250 offset 0.320652 sec

 

目录
相关文章
|
2月前
|
网络协议 算法 定位技术
利用GPS北斗卫星系统开发NTP网络时间服务器
利用GPS北斗卫星系统开发NTP网络时间服务器
|
2月前
|
监控 Linux 定位技术
Linux【环境部署 01】NTP时间服务器搭建及Linux+Windows客户端使用(一篇学会使用NTP服务)
Linux【环境部署 01】NTP时间服务器搭建及Linux+Windows客户端使用(一篇学会使用NTP服务)
1209 0
|
数据采集 定位技术 数据安全/隐私保护
ESP8266调用NTP服务器进行时间校准
NTP服务器通常连接到具有高度精确时间源的设备,例如:GPS接收器或原子钟,以确保提供准确如一的时间。网络上的计算机可以通过连接到NTP服务器来同步其时间,并确保它们在同一时刻进行操作。
825 0
|
Ubuntu 安全 机器人
把Windows打造成一个NTP时间同步服务器
把Windows打造成一个NTP时间同步服务器
把Windows打造成一个NTP时间同步服务器
|
弹性计算 Windows
同步服务器时间NTP
在秒杀、抢券等高并发的活动中,一点点的时间延迟,也会让自己后悔莫及……
1626 0
同步服务器时间NTP
|
安全 Linux 网络安全
手把手教你在centos 7.4上搭建NTP服务器
手把手教你在centos 7.4上搭建NTP服务器
968 0
手把手教你在centos 7.4上搭建NTP服务器
|
Ubuntu Linux 虚拟化
使用阿里云镜像站NTP服务搭建NTP服务器(基于CentOS 7系统)
使用阿里云镜像站NTP服务搭建NTP服务器(基于CentOS 7系统)
1895 0
使用阿里云镜像站NTP服务搭建NTP服务器(基于CentOS 7系统)
|
测试技术 Windows
Windows下安装NTP服务器
原文:Windows下安装NTP服务器 NTP服务器介绍 NTP服务器【Network Time Protocol(NTP)】是用来使计算机时间同步化的一种协议,它可以使计算机对其服务器或时钟源(如石英钟,GPS等等)做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒,WAN上几十毫秒)。
3079 0
|
23天前
|
缓存 Linux 开发工具
centos设置ntp服务同步目标服务器时间
【7 月更文挑战第 1天】linux+centos设置ntp服务同步目标服务器时间
|
2月前
|
Linux 数据库
ntp如何配置同步服务器
【5月更文挑战第19天】ntp如何配置同步服务器
90 2

热门文章

最新文章