时间同步服务

2023-05-16

1. NTP时钟同步方式说明

NTP在linux下有两种时钟同步方式,分别为直接同步和平滑同步: 

  • 直接同步 

使用ntpdate命令进行同步,直接进行时间变更。如果服务器上存在一个12点运行的任务,当前服务器时间是13点,但标准时间时11点,使用此命令可能会造成任务重复执行。因此使用ntpdate同步可能会引发风险,因此该命令也多用于配置时钟同步服务时第一次同步时间时使用。 

  • 平滑同步 

使用ntpd进行时钟同步,可以保证一个时间不经历两次,它每次同步时间的偏移量不会太陡,是慢慢来的,这正因为这样,ntpd平滑同步可能耗费的时间比较长。

2.NTP 配置文件

# vim /etc/ntp.conf
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
 
driftfile /
var
/lib/ntp/drift
 
#新增:日志目录.
logfile /
var
/log/ntpd.log
 
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict 
default 
nomodify notrap nopeer noquery
 
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict ::1
#这一行的含义是授权172.16.128.0网段上的所有机器可以从这台机器上查询和同步时间.
restrict 172.16.128.0 mask 255.255.255.0 nomodify notrap
 
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
 
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
 
#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 0.cn.pool.ntp.org iburst
server 1.cn.pool.ntp.org iburst
server 2.cn.pool.ntp.org iburst
server 3.cn.pool.ntp.org iburst
 
#新增:当外部时间不可用时,使用本地时间.
server 172.16.128.171 iburst
fudge 127.0.0.1 stratum 10
 
#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 autokey # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 autokey # manycast client
 
#新增:允许上层时间服务器主动修改本机时间.
restrict 0.cn.pool.ntp.org nomodify notrap noquery
restrict 1.cn.pool.ntp.org nomodify notrap noquery
restrict 2.cn.pool.ntp.org nomodify notrap noquery
 
# Enable public key cryptography.
#crypto
 
includefile /etc/ntp/crypto/pw
 
# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys
 
# Specify the key identifiers which are trusted.
#trustedkey 4 8 42
 
# Specify the key identifier to use with the ntpdc utility.
#requestkey 8
 
# Specify the key identifier to use with the ntpq utility.
#controlkey 8
 
# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats
 
# Disable the monitoring facility to prevent amplification attacks using ntpdc
# monlist command when default restrict does not include the noquery flag. See
# CVE-2013-5211 for more details.
# Note: Monitoring will not be disabled with the limited restriction flag.
disable monitor

3.设置系统开机自启动:

# systemctl enable ntpd

# systemctl enable ntpdate

# systemctl is-enabled ntpd

在ntpd服务启动时,先使用ntpdate命令同步时间:

# ntpdate -u 1.cn.pool.ntp.org

 

原因之一:当服务端与客户端之间的时间误差过大时,此时修改时间可能对系统或应用带来不可预知问题,NTP会停止时间同步。若检查NTP启动后时间未同步时,应考虑可能是时间误差过大所致,此时需要先手动进行时间同步。

启动NTP服务器:

# systemctl start ntpdate
# systemctl start ntpd
注:ntpdate服务要在ntpd前先开启不然会报错

4.加入防火墙:

# firewall-cmd --permanent --add-service=ntp

# firewall-cmd --reload

5.查看ntp连接状态如果没有问题,将正确时间写入硬件:

# ss -tlunp | grep ntp
# ntpq -p
# hwclock -w

6.客户端

以服务进程方式实时同步(需安装NTP):

# vim /etc/ntp.conf

server 172.16.128.171

重要:修改任意节点服务器的NTP配置文件都需要重起ntpd服务:

# systemctl restart ntpd

以crontab任务计划同步时间(需安装ntpdate,每隔更新同步时间):

# crontab -e

*/10 * * * * /usr/sbin/sntp -P no -r 172.16.128.171;hwclock -w

7.windows 客户端

 

 

 

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

时间同步服务 的相关文章

  • 视频教程-C++多线程编程视频教程(C++11多线程并发)-C/C++

    C 43 43 多线程编程视频教程 xff08 C 43 43 11多线程并发 xff09 黄强老师 xff0c 国家软件设计师 xff0c 软件开发工程师 xff0c 项目经理 产品经理 培训讲师 创业合伙人 xff0c 多年C C 43
  • 【Luogu P1661】扩散

    题目 xff1a 一个点每过一个单位时间就会向四个方向扩散一个距离 xff0c 如图 两个点 a b 连通 xff0c 记作 e a b 当且仅当 a b 的扩散区域有公共部分 连通块的定义是块内的任意两个点 u v 都必定存在路径 e u
  • Linux让Apache支持中文URL图片/文件名

    需要用到iconv hook和mod encoding Apache xff08 32位 xff09 xff1a 安装环境 xff1a CentOS 5 6 43 Apache 2 2 15 xff08 Apache2 4同样适用 xff0
  • 解决VS2015安装后stdio.h ucrtd.lib等文件无法识别问题,即include+lib环境变量配置

    转载自 xff1a http blog csdn net carl qi article details 51171280 今天突然想在windows上装个 VS2015 玩玩 xff0c 结果遇到了如下bug xff1a 安装完 VS20
  • 算法基础复习-动态规划

    1 动态规划 xff08 Dynamic Programming xff0c DP xff09 动态规划通常用来求解复杂问题的某个最优解 xff0c 与分治法相似 xff0c 区别在于 分治法应用于子问题互不相交的情况 xff0c 即递归的
  • 数据结构|-常见数据结构整理

    归纳总结了一下数据机构的常用类型 xff0c 个人理解常用的数据机构可以分为线性表 栈 队列 树 xff0c 线性表包括顺序表和链表 xff0c 栈和队列应当属于特殊的线性表 xff0c 有几个概念和误区需要先说一下 顺序表和线性表的关系
  • Xcode5 创建模板和UIView 关联XIB

    来源 xff1a http www cnblogs com china ldw p 3533896 html 在做ios应用开发的过程 xff0c 难免遇到要创建 子view 和 自定义view的时候 xff0c 归根到底 xff0c 我们
  • opencv中矩阵计算的一些函数

    转自 xff1a http blog sina com cn s blog 7908e1290101i97z html 综述 OpenCV有针对矩阵操作的C语言函数 许多其他方法提供了更加方便的C 43 43 接口 xff0c 其效率与Op
  • mysql中对比 JSON_VALUE 与 JSON_QUERY

    1 JSON概述 MySQL里的json分为json array和json object 表示整个json对象 xff0c 在索引数据时用下标 对于json array xff0c 从0开始 或键值 对于json object xff0c
  • Win10系统的Microsoft Edge浏览器打开任一网页均未响应卡死的问题

    Edge浏览器在刚装上WIN10的时候就使用了 xff0c 的确给人耳目一新 xff0c 使用起来也非常顺心的感觉 xff0c 总体上还是很感人的 xff0c 可是今天使用突然出现随便打开一个网页都会卡死 xff0c 未响应的问题 xff0
  • 用二进制方法求两个整数的最大公约数(GCD)

    二进制GCD算法基本原理是 先用移位的方式对两个数除2 xff0c 直到两个数不同时为偶数 然后将剩下的偶数 xff08 如果有的话 xff09 做同样的操作 xff0c 这样做的原因是如果u和v中u为偶数 v为奇数 xff0c 则有gcd
  • SQL SERVER解析Json

    外包的项目 xff0c 有很多信息存储在JSON中 xff0c 无论是查询还是修改信息都十分麻烦 找了一些实用的SQL Function去解析 xff0c 并附修改例子 使用过程 xff1a 1 需要在SQL新建自定义类型 table Hi
  • c++ 头文件循环引用解法

    A h include 34 B h 34 class A public B m b B h include 34 A h 34 class B public A m a 上面这样是编译不过的 xff0c 把A h中的 include 34
  • 搭建ceph集群(单节点)

    https blog csdn net Greenchess article details 77525786 软件环境 xff1a Centos7 x64 CEPH版本 xff1a ceph deploy v1 5 37 ceph ver
  • Java-SpringCloud-基础

    一 服务注册与发现 服务注册 xff1a 服务提供者将服务的信息 xff08 IP 端口 协议等 xff09 登记到注册中心服务发现 xff1a 服务消费者根据一定策略从注册中心的服务列表选取一个服务 1 eureka span class
  • Ubuntu休眠不能唤醒问题之分区惹的祸

    问题描述 xff1a 休眠后进行唤醒时一直黑屏或内核错误 经历如下 xff1a 在笔记本上添加了固态硬盘后直接将机械硬盘上的系统拷贝到固态盘中使用 xff0c 设置了swap分区 xff0c 在唤醒时内核报告ext4文件系统错误 在lily
  • 用Keil-MDK开发TQ2440裸机程序入门教程——LED流水灯实现

    觉得此编文章很详实 xff0c 故转载之 xff0c 来自http www amobbs com thread 5281512 1 1 html 开发板也差不多买了半年了 以前照着教程用的是软件是ADS 在win7下老是崩溃 后来才知道AD
  • 【洛谷 3366】最小生成树_Prim

    题目描述 如题 xff0c 给出一个无向图 xff0c 求出最小生成树 xff0c 如果该图不连通 xff0c 则输出orz 输入格式 第一行包含两个整数N M xff0c 表示该图共有N个结点和M条无向边 xff08 N lt 61 50
  • 远程rdp vnc连接 UBuntu 10.10

    我打算用ubuntu编译Android源码 xff0c 因为编译时间较长需要远程控制一下自己的电脑 xff0c 所以想到了安装远程桌面软件 xff0c 具体方法 xff1a Ubuntu下的操作 1 Win7远程连接上Ubuntu xff0

随机推荐

  • AtCoder ABC 140E Second Sum

    题目链接 xff1a https atcoder jp contests abc140 tasks abc140 e 题目大意 给定一个 1 N 的排列 P 定义 X L R 的值为 P L P L 43 1 ldots P R 中第二大的
  • Sublime MinGw实现C/C++代码编译运行

    安装配置MinGw 下载安装MinGW 去官网下载MinGw xff1a http www mingw org 或者下载我已经下载好的完整版 xff1a http pan baidu com s 1gfgluin 2017 7 5更新 如图
  • Ajax发送POST请求SpringMVC页面跳转失败

    问题描述 xff1a 因为使用的是SpringMVC框架 xff0c 所以想使用ModelAndView进行页面跳转 思路是发送POST请求 xff0c 然后controller层中直接返回相应ModelAndView xff0c 但是这种
  • Debian命令

    1 dpkg i 安装下载的软件包 2 shutdown h now 关机 3 fdisk l 查看当前盘 4 lspci 用来显示系统中所有PCI总线设备或连接到该总线上的所有设备的工具 如lspci v 参数 xff1a v 使得 ls
  • 堡垒机-teleport的安装以及常见问题解决办法

    teleport是一款简单易用的堡垒机系统 xff0c 运用在企业对windows linux服务器的安全使用管理以及审计 官网网址 xff1a http teleport eomsoft net github地址 xff1a https
  • 【Luogu】P1593因子和(唯一分解定理,约数和公式)

    题目链接 首先介绍两个定理 整数唯一分解定理 xff1a 任意正整数都有且只有一种方式写出素数因子的乘积表达式 A 61 p1k1 p2k2 pnkn 求这些因子的代码如下 for int i 61 2 i i lt 61 a 43 43
  • 通用组件—SvgIcon引入和使用

    Svg Icon 创建一个专门放置图标 icon 的文件夹 xff1a src icons 添加SvgIcon组件到公共components目录下 src components SvgIcon index vue lt template g
  • [HDU3652]B-number

    题面描述 给定一个数 n 求 1 n 中所有满足以下条件的数的个数 xff1a 1 该数中不包含 34 13 34 2 该数能被13整除 输入格式 输入包含多行 xff0c 每行一个整数 n 1 leq n leq 1000000000 输
  • [GYM 101755]Restoring Numbers

    题面描述 已知两个正整数a b的和s与最大公约数g xff0c 求a b 输入格式 一共一行 xff0c 包含两个正整数 s g 输出格式 一共一行 xff0c 若有解输出 a b 否则输出 1 样例数据 样例输入 6 2 样例输出 4 2
  • 数位DP 详解

    序 天堂在左 xff0c 战士向右 引言 数位DP在竞赛中的出现几率极低 xff0c 但是如果不会数位DP xff0c 一旦考到就只能暴力骗分 以下是数位DP详解 xff0c 涉及到的例题有 xff1a HDU2089 不要62 HDU36
  • 关于485通信不稳定问题解决方案[STM32产品问题]

    485通讯不稳定的问题 xff08 具体表现为有时能通讯上 xff0c 有时通讯不上 xff09 RS485在连接设备过多 通讯距离过长 双绞线质量差 xff0c 接线不规范 等 xff0c 都会导致通讯不稳定的问题 解决方案 xff1a
  • Oracle update语句更新值来自另一张表中的数据

    task 任务表 role 角色表 两表之间必须有关联的字段 update task t set t roleName 61 select r name from role r where r id 61 t roleid 转载于 http
  • HTML个人简介

    lt doctype html gt lt html lang 61 34 en 34 gt lt head gt lt meta charset 61 34 UTF 8 34 gt lt meta name 61 34 Generator
  • 如何查看windows某个目录下所有文件/文件夹的大小?

    如何查看windows某个目录下所有文件 文件夹的大小 xff1f TreeSize Free绿色汉化版是一款硬盘空间管理工具 xff0c 用树形描述出来 xff0c 能够显示文件大小和实际占用空间数及浪费的空间等信息 xff0c 让你做出
  • Kafka服务不可用(宕机)问题踩坑记

    背景 某线上日志收集服务报警 xff0c 打开域名报502错误码 收集服务由2台netty HA服务器组成 netty服务器将客户端投递来的protobuf日志解析并发送到kafka xff0c 打开其中一个应用的日志 xff0c 发现如下
  • Sublime Text 的破解方式

    Sublime Text 破解 xff08 Mac和Windows系统 xff09 Posted on 2013 年 11 月 19 日 3 条评论 6 031 次浏览 继 续分享在 Mac OSX 和 Windows 下破解编码神器 xf
  • 洛谷P1233 木棍加工【单调栈】

    题目 xff1a https www luogu org problemnew show P1233 题意 xff1a 有n根木棍 xff0c 每根木棍有长度和宽度 现在要求按某种顺序加工木棍 xff0c 如果前一根木棍的长度和宽度都大于现
  • 高并发核心知识——ZooKeeper

    ZooKeeper 简介 ZooKeeper是一个开源的分布式协调服务 xff0c 重视高性能 高可用 严格有序的访问 Zookeeper中利用被称为znode的节点保存数据 xff0c 数据将保存在内存 ram 中 xff0c 最多存储1
  • https://gns3.com/community/discussion/gns3-doesn-t-work-on-vmware-play

    swered Question GNS3 doesn t work on VMWARE player 15 Hi guys today I try to install GNS3 on new VMWARE player 15 with V
  • 时间同步服务

    1 NTP时钟同步方式说明 NTP在linux下有两种时钟同步方式 xff0c 分别为直接同步和平滑同步 xff1a 直接同步 使用ntpdate命令进行同步 xff0c 直接进行时间变更 如果服务器上存在一个12点运行的任务 xff0c