一. 定义

#01 简介:ntp全名 network time protocol 。NTP服务器可以为其他主机提供时间校对服务

#02 ntp和ntpdate区别
1) 两个服务都是centos自带的(centos7中不自带ntp)。ntp的安装包名是ntp;ntpdate的安装包是ntpdate。他们并非由一个安装包提供。
2) ntp守护进程为ntpd,配置文件是/etc/ntp.conf
3) ntpdate用于客户端的时间矫正,非NTP服务器可以不启动NTP。

二. 项目要求

## 由于容器内时区不对,且无外网环境,需要ntp服务器 进行时间同步

## 准备两台服务器 一台作为NTP服务器,另一台作为client端向服务器同步时间测试。

服务器 IP 备注
NTP服务端 192.168.5.15 Cenost7
客户端 192.168.5.9 ubuntu (docker 容器内)

三. 部署服务端

#01 安装并启动
yum install -y ntp
service ntpd start #02 修改配置文件
[root@kq_mysql ~]# grep -Ev '^$|^#' /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict 192.168.5.0 mask 255.255.255.0 nomodify notrap #允许同步的网段
restrict 127.0.0.1 #设置为时间同步主服务器
restrict ::1
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
server 127.127.1.0 prefer #设置本机为NTP服务器
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor 注意:这里只添加下面两行即可
server 127.127.1.0 prefer #设置本机为NTP服务器
restrict 192.168.5.0 #允许客户端156.0.26.7向本机请求时间同步
restrict 192.168.5.0 mask 255.255.255.0 #允许客户端156.0.26.0网段的所有主机向本机请求时间同步 #03 启动检查
1)检查进程
[root@kq_mysql ~]# service ntpd start
Redirecting to /bin/systemctl start ntpd.service
[root@kq_mysql ~]# netstat -tunlp |grep ntp
udp 0 0 172.17.0.1:123 0.0.0.0:* 16712/ntpd
udp 0 0 172.18.0.1:123 0.0.0.0:* 16712/ntpd
udp 0 0 192.168.5.15:123 0.0.0.0:* 16712/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 16712/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 16712/ntpd
udp6 0 0 :::123 :::* 16712/ntpd 2)检查服务
[root@kq_mysql ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
+stratum2-1.ntp. 194.190.168.1 2 u 56 64 377 102.792 -0.286 6.553
+119.28.206.193 100.122.36.196 2 u 65 64 377 51.545 0.244 10.349
+ntp1.flashdance 194.58.202.20 2 u 65 64 377 289.813 16.525 13.405
+tick.ntp.infoma .GPS. 1 u 55 64 377 147.590 6.641 8.143
*LOCAL(0) .LOCL. 5 l 32 64 377 0.000 0.000 0.000 解释下:ntpq -p:此命令可以列出当前主机的NTP和上层NTP的状态。

四. 部署客户端

#01 安装服务
apt-get install -y ntp #02 修改配置文件
root@centos_4c8g:/# grep -E -v '^$|^#' /etc/ntp.conf
driftfile /var/lib/ntp/ntp.drift
leapfile /usr/share/zoneinfo/leap-seconds.list
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
pool 0.ubuntu.pool.ntp.org iburst
pool 1.ubuntu.pool.ntp.org iburst
pool 2.ubuntu.pool.ntp.org iburst
pool 3.ubuntu.pool.ntp.org iburst
pool ntp.ubuntu.com
server 192.168.5.15 #设置上游的服务器
restrict 192.168.5.15 nomodify notrap noquery #允许上游服务器修改本本机IP
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited
restrict 127.0.0.1
restrict ::1
restrict source notrap nomodify noquery 客户端需要修改/etc/ntp.conf,添加以下内容
  server 192.168.5.15 #指名上层NTP服务器
  restrict 192.168.5.15 #放行156.0.26.6
  restrict 192.168.5.15 nomodify notrap noquery #允许上游服务器修改本本机IP #03 启动 检查
root@centos_4c8g:/# ntpd
root@centos_4c8g:/# ntpq -p

时间同步 ntp服务器的更多相关文章

  1. 部署NTP服务器进行时间同步

    NTP服务端:linl_S    IP:10.0.0.15 NTP客户端:lin_C    IP:10.0.0.16 NTP服务概述 1.原理 NTP(Network TimeProtocol,网络时 ...

  2. Linux配置NTP服务器,时间同步

    当服务器多了,时间准确与否,一致与否是个大问题.虽然这个问题总是被忽略,但是统一一致的时间是很有必要的.下面说一下在局域网内配置Linux时间服务器的方法. 配置的环境及要求: 假设在192.168. ...

  3. Linux时间同步+国内常用的NTP服务器地址

    当Linux服务需要时间戳的时候,时间同步就显得十分重要.这里介绍下,最近我使用的一个同步命令. # ntpdate s1a.time.edu.cn 国内常用的NTP地址 210.72.145.44 ...

  4. C# Winform小程序:局域网设置NTP服务器、实现时间同步

    设置NTP服务器: NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议. 局域网不能连接Internet,可以设置一台计算机为NTP服务器. ...

  5. CentOS 7.2部署NTP服务器实现时间同步

    CentOS 7.2部署NTP服务器实现时间同步 [日期:2017-12-18] 来源:Linux社区  作者:梁明远 [字体:大 中 小]   1. 前言 对于容器编排系统,前段时间主要研究kube ...

  6. Linux集群环境下NTP服务器时间同步

    NTP介绍 NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议.它的用途是把计算机的时钟同步到世界协调时UTC(Universal Time ...

  7. NTP服务器时间同步

    CentOS 配置服务器NTP同步 1 查看是否安装 rpm -aq | grep ntp 2 安装 yum -y install ntp 3 配置 /etc/ntp.conf restrict 访问 ...

  8. centos7.2 配置内网ntp服务器进行时间同步

    (一)修改/etc/ntp.conf 配置文件,注意红色部分,其他部分不需要改  ########################################################### ...

  9. 阿里云内网和公网NTP服务器和其他互联网基础服务时间同步服务器

    阿里云为云服务器ECS提供了内网NTP服务器,对于阿里云以外的设备,阿里云同时提供了 公网NTP服务器,供互联网上的设备使用. 内网和公网NTP服务器 以下为阿里云提供的内网和公网NTP服务器列表. ...

  10. Linux 搭建NTP服务器

    NTP服务器[Network Time Protocol(NTP]是用来使计算机时间同步化的一种协议,NTP服务器可以对其它服务器做时间同步化,从而达到时间统一. 配置环境及要求: A. 假设10.8 ...

随机推荐

  1. 临上线项目使用ILRuntime热更

    前言 我们有一个用Unity引擎开发了二十个月的mmo arpg手游项目,在安卓已经测试三轮了,出于IOS的热的考虑且结合我们的情况:全部代码都是纯C#开发非Lua,所以计划使用ILRuntime热更 ...

  2. 15.1 套接字通过域名取IP地址

    首先我们来实现一个DNS查询功能,该功能的目的是传入一个网站域名自动将该域名解析为对应的IP地址,该功能的实现依赖于gethostbyname函数,该函数将主机名作为参数,并返回一个指向hostent ...

  3. C/C++ 实现常用的线程注入

    各种API远程线程注入的方法,分别是 远程线程注入,普通消息钩子注入,全局消息钩子注入,APC应用层异步注入,ZwCreateThreadEx强力注入,纯汇编实现的线程注入等. 简单编写DLL文件: ...

  4. org.apache.hadoop.security.AccessControlException: Queue root.online already has 0 applications, cannot accept submission of application

    org.apache.hadoop.security.AccessControlException: Queue root.online already has 0 applications, can ...

  5. 史上最大电池!小米智能家庭屏Pro 8图赏

    今天小米智能家庭屏 Pro 8正式开售,集智能家居中控,智能网关以及娱乐教育三大功能为一体,首发749元. 它是一款全新的智能生态产品中控屏,配备了7500mAh大容量电池以及通用性更好的USB Ty ...

  6. GD库常用实例

      GD库常用实例 一.图片水印 1.实现步骤 打开原图(也叫操作的目标图片) 打开水印图(也叫水印来源图片) 使用 imagecopymerge 将小图合并至大图的指定位置 输出图片 销毁资源 2. ...

  7. java代码实现自动生成数据库表er图

    最近有同事看到字节跳动产品设计文档里有数据库表er图.就想问问又没有现成的工具也给直接生成一个er图,经查找验证发现并没有.因为现在表关系都是用的逻辑外键而非物理外键约束的,所以像navicat等工具 ...

  8. 《ASP.ENT Core 与 RESTful API 开发实战》-- (第5章)-- 读书笔记(中)

    第 5 章 使用 Entity Framework Core 5.3 重构仓储类 创建一个通用仓储接口 namespace Library.API.Services { public interfac ...

  9. LLM研究之-NVIDIA的CUDA

    一.什么是NVIDIA的CUDA CUDA(Compute Unified Device Architecture)是由NVIDIA公司开发的一个并行计算平台和应用程序编程接口(API),它允许软件开 ...

  10. NC16697 [NOIP2001]Car的旅行路线

    题目链接 题目 题目描述 又到暑假了,住在城市A的Car想和朋友一起去城市B旅游.她知道每个城市都有四个飞机场,分别位于一个矩形的四个顶点上,同一个城市中两个机场之间有一条笔直的高速铁路,第I个城市中 ...