时间同步服务

CentOS7之前的版本用的是ntpdate服务,之后用的是chrony服务
默认是安装的了

查看版本

[root@centos8 ~]#rpm -qi chrony
Name : chrony
Version : 3.5
Release : 2.el8
Architecture: x86_64
Install Date: Sun 13 Jun 2021 12:40:02 PM CST
Group : System Environment/Daemons
Size : 537759
License : GPLv2
Signature : RSA/SHA256, Wed 03 Mar 2021 12:26:24 AM CST, Key ID 05b555b38483c65d
Source RPM : chrony-3.5-2.el8.src.rpm
Build Date : Tue 02 Mar 2021 03:04:32 PM CST
Build Host : x86-01.mbox.centos.org
Relocations : (not relocatable)
Packager : CentOS Buildsys <bugs@centos.org>
Vendor : CentOS
URL : https://chrony.tuxfamily.org
Summary : An NTP client/server
Description :
chrony is a versatile implementation of the Network Time Protocol (NTP).
It can synchronise the system clock with NTP servers, reference clocks
(e.g. GPS receiver), and manual input using wristwatch and keyboard. It
can also operate as an NTPv4 (RFC 5905) server and peer to provide a time
service to other computers in the network. [root@centos7 ~]#cat /etc/redhat-release

CentOS Linux release 7.2.1511 (Core)

[root@centos7 ~]#uname -r

3.10.0-327.el7.x86_64 [root@centos7 ~]#rpm -qi chrony

Name : chrony

Version : 2.1.1

Release : 1.el7.centos

Architecture: x86_64

Install Date: 2019年11月25日 星期一 20时17分23秒

Group : System Environment/Daemons

Size : 479430

License : GPLv2

Signature : RSA/SHA256, 2015年11月25日 星期三 22时19分35秒, Key ID 24c6a8a7f4a80eb5

Source RPM : chrony-2.1.1-1.el7.centos.src.rpm

Build Date : 2015年11月24日 星期二 05时36分12秒

Build Host : worker1.bsys.centos.org

Relocations : (not relocatable)

Packager : CentOS BuildSystem <http://bugs.centos.org>

Vendor : CentOS

URL : http://chrony.tuxfamily.org

Summary : An NTP client/server

Description :

A client/server for the Network Time Protocol, this program keeps your

computer's clock accurate. It was specially designed to support

systems with intermittent internet connections, but it also works well

in permanently connected environments. It can use also hardware reference

clocks, system real-time clock or manual input as time references.

服务端配置

主配置文件/etc/chrony
重点是:
allow 0.0.0.0/0
local stratum 10

简单解释:
允许NTP客户端从本地网络访问。
即使不能和一个远程服务器时间源同步,也能继续为其他客户端提供时间同步服务.
10 代表当前服务器设置为第10层, 按照 原子钟为第一层,互联网上的若干时间服务器为第N层,第10层足够表示当前主机所在的局域网
iburst:并行同步,加快同步速度

[root@centos8 ~]#vim /etc/chrony.conf

Use public servers from the pool.ntp.org project.

Please consider joining the pool (http://www.pool.ntp.org/join.html).

pool 2.centos.pool.ntp.org iburst

server ntp.aliyun.com iburst iburst

server ntp.ecslb.sjtu.edu.cn iburst

server time1.cloud.tencent.com iburst

Record the rate at which the system clock gains/losses time.

driftfile /var/lib/chrony/drift

Allow the system clock to be stepped in the first three updates

if its offset is larger than 1 second.

makestep 1.0 3

Enable kernel synchronization of the real-time clock (RTC).

rtcsync

Enable hardware timestamping on all interfaces that support it.

hwtimestamp *

Increase the minimum number of selectable sources required to adjust

the system clock.

minsources 2

Allow NTP client access from local network.

allow 192.168.0.0/16

allow 0.0.0.0/0

Serve time even if not synchronized to a time source.

local stratum 10

local stratum 10

Specify file containing keys for NTP authentication.

keyfile /etc/chrony.keys

Get TAI-UTC offset and leap seconds from the system tz database.

leapsectz right/UTC

Specify directory for log files.

logdir /var/log/chrony

Select which information is logged.

log measurements statistics tracking

重启服务

systemctl restart chronyd
  • 1

查看chrony服务默认监听的UDP端口123是否打开

[root@centos8 ~]#ss -ntlu
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
udp UNCONN 0 0 0.0.0.0:111 0.0.0.0:*
udp UNCONN 0 0 0.0.0.0:123 0.0.0.0:*
udp UNCONN 0 0 0.0.0.0:39087 0.0.0.0:*
udp UNCONN 0 0 0.0.0.0:5353 0.0.0.0:*
udp UNCONN 0 0 127.0.0.1:323 0.0.0.0:*
udp UNCONN 0 0 [::]:111 [::]:*
udp UNCONN 0 0 [::]:50298 [::]:*
udp UNCONN 0 0 [::]:5353 [::]:*
udp UNCONN 0 0 [::1]:323 [::]:*
tcp LISTEN 0 128 127.0.0.1:6010 0.0.0.0:*
tcp LISTEN 0 128 127.0.0.1:6011 0.0.0.0:*
tcp LISTEN 0 128 127.0.0.1:6012 0.0.0.0:*
tcp LISTEN 0 128 127.0.0.1:6013 0.0.0.0:*
tcp LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
tcp LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
tcp LISTEN 0 128 [::1]:6010 [::]:*
tcp LISTEN 0 128 [::1]:6011 [::]:*
tcp LISTEN 0 128 [::1]:6012 [::]:*
tcp LISTEN 0 128 [::1]:6013 [::]:*
tcp LISTEN 0 128 [::]:111 [::]:*
tcp LISTEN 0 128 *:80 *:*
tcp LISTEN 0 128 [::]:22 [::]:*
tcp LISTEN 0 5 [::1]:631 [::]:*

客户端测试

[root@centos7 ~]#date -s "-1 year"
2020年 08月 27日 星期四 20:09:11 CST
[root@centos7 ~]#date
2020年 08月 27日 星期四 20:09:17 CST
[root@centos7 ~]#ntpdate 10.0.0.5
27 Aug 16:09:37 ntpdate[4935]: step time server 10.0.0.5 offset 31521600.000748 sec
[root@centos7 ~]#date
2021年 08月 27日 星期五 16:09:40 CST

更改配置文件使客户端时间服务默认指向10.0.0.5

[root@centos7 ~]#vim /etc/chrony.conf

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 10.0.0.5 iburst

重启服务

systemctl restart chronyd
  • 1

测试

[root@centos7 ~]#date -s "-1 year"
2020年 08月 27日 星期四 16:17:28 CST

查看同步详细信息

[root@centos7 ~]#chronyc sources -v

210 Number of sources = 1

.-- Source mode '^' = server, '=' = peer, '#' = local clock.

/ .- Source state '*' = current synced, '+' = combined , '-' = not combined,

| / '?' = unreachable, 'x' = time may be in error, '~' = time too variable.

|| .- xxxx [ yyyy ] +/- zzzz

|| Reachability register (octal) -. | xxxx = adjusted offset,

|| Log2(Polling interval) --. | | yyyy = measured offset,

|| \ | | zzzz = estimated error.

|| | |

MS Name/IP address Stratum Poll Reach LastRx Last sample

^? 10.0.0.5 3 6 377 17 -8760h[ -8760h] +/- 17ms

同步成功

[root@centos7 ~]#chronyc sources -v

210 Number of sources = 1

.-- Source mode '^' = server, '=' = peer, '#' = local clock.

/ .- Source state '*' = current synced, '+' = combined , '-' = not combined,

| / '?' = unreachable, 'x' = time may be in error, '~' = time too variable.

|| .- xxxx [ yyyy ] +/- zzzz

|| Reachability register (octal) -. | xxxx = adjusted offset,

|| Log2(Polling interval) --. | | yyyy = measured offset,

|| \ | | zzzz = estimated error.

|| | |

MS Name/IP address Stratum Poll Reach LastRx Last sample

^* 10.0.0.5 3 6 377 1 +76us[ -8760h] +/- 16ms

注:使用默认同步需要稍微等待几分钟,立即同步可以用ntpdate 10.0.0.5 或者重启chrony服务 systemctl restart chronyd

国内常见的NTP时间服务器地址

清华大学
https://tuna.moe/help/ntp/

ntp.tuna.tsinghua.edu.cn

上海交通大学

ntp.sjtu.edu.cn
ntp.ecslb.sjtu.edu.cn

腾讯

time1.cloud.tencent.com
time2.cloud.tencent.com
time3.cloud.tencent.com
time4.cloud.tencent.com
time5.cloud.tencent.com

微软
windows自带

time.windows.com

文章知识点与官方知识档案匹配,可进一步学习相关知识
CS入门技能树Linux入门初识Linux33431 人正在系统学习中

[转帖]CentOS8时间同步服务的更多相关文章

  1. centos 8.x系统配置chrony时间同步服务

    redhat/centos 7.x默认使用的时间同步服务为ntp服务,但是从redhat/centos 8开始在官方的仓库中移除了ntp软件,换成默认的chrony进行时间同步的服务,虽然也可以通过添 ...

  2. RAC集群时间同步服务

    集群时间同步服务在集群中的两个 Oracle RAC 节点上执行以下集群时间同步服务配置.Oracle Clusterware 11g 第 2 版及更高版本要求在部署了 Oracle RAC 的集群的 ...

  3. NTP时间同步 服务端 客户端 自动化安装配置

    NTP时间同步 服务端 客户端 自动化安装配置 原创内容 http://www.cnblogs.com/elvi/p/7657994.html #!/bin/sh #运行环境 centos6.cent ...

  4. chrony时间同步 服务端 客户端 安装配置

    chrony时间同步 服务端 客户端 安装配置 原创内容http://www.cnblogs.com/elvi/p/7658021.html #!/bin/sh #运行环境 centos7 #chro ...

  5. 云计算openstack共享组件(1)——时间同步服务ntp

    一.标准时间讲解 地球分为东西十二个区域,共计 24 个时区 格林威治作为全球标准时间即 (GMT 时间 ),东时区以格林威治时区进行加,而西时区则为减. 地球的轨道并非正圆,在加上自转速度逐年递减, ...

  6. 关于linux下ntp时间同步服务的安装与配置

    1.安装ntp服务,要使用时间同步.那么服务端与客户端都需要使用如下命令安装NTP软件包 [root@ ~]# yum install ntp -y 2.如果只是作为客户端的话,配置则可以非常简单,编 ...

  7. openstack (1)----- NTP 时间同步服务

    一.标准时间 1.地球分为东西十二个区域,共计24个时区 2.格林威治作为全球标准时间即(GMT时间),东时区以格林威治时区进行加,而西时区则进行减 3.地球的轨道并非正圆,在加上自传速度逐年递减,因 ...

  8. 云计算共享组件--时间同步服务NTP(2)

    一.标准时间讲解 地球分为东西十二个区域,共计 24 个时区 格林威治作为全球标准时间即 (GMT 时间 ),东时区以格林威治时区进行加,而西时区则为减. 地球的轨道并非正圆,在加上自转速度逐年递减, ...

  9. openstack (共享组件) 时间同步服务

    云计算openstack共享组件——时间同步服务ntp(2)   一.标准时间讲解 地球分为东西十二个区域,共计 24 个时区 格林威治作为全球标准时间即 (GMT 时间 ),东时区以格林威治时区进行 ...

  10. 云计算openstack共享组件——时间同步服务ntp(2)

    一.标准时间讲解 地球分为东西十二个区域,共计 24 个时区 格林威治作为全球标准时间即 (GMT 时间 ),东时区以格林威治时区进行加,而西时区则为减. 地球的轨道并非正圆,在加上自转速度逐年递减, ...

随机推荐

  1. JavaFx FXML入门(五)

    JavaFx FXML入门(五) JavaFX 从入门入门到入土系列 JavaFx的FXML类似安卓中的视图文件,可以添加样式,添加css,添加id然后在java代码中绑定点击事件.可以使用工具编辑: ...

  2. Tpon 1.0 一键查询网站存在过的路径

    Tpon 1.0 寻找网站存在过的路径 该工具能够让你发现意料之外的路径 工具描述 编写该工具旨在寻找网站存在过的网站路径,这个地址可能是机器爬下来的也可能是某些人访问过的,在表面你可能看不到它的入口 ...

  3. shared_ptr 自定义 deleter 删除器

    一些结论 如果 shared_ptr 管理的资源不是 new 分配的内存,才考虑自定义删除器,这也是为什么 make_shared 不支持自定义删除器的原因,因为 make_shared 就是通过 n ...

  4. Jenkins汉化配置

    登录进入Jenkins首页 输入:本地ip+端口号(localhost:8099) 进入插件管理页面(Manage Jenkins)安装相关插件 搜索:到available栏目搜索:Locale pl ...

  5. 华为云黄瑾:做强坚实数据底座,GaussDB与产业携手共进

    近日,华为全球智慧金融峰会2023在上海顺利举行,华为云副总裁.战略与产业发展部总裁黄瑾发表了<做强坚实数据底座,GaussDB与产业携手共进>的主题演讲. 以下为演讲实录: 尊敬的各位来 ...

  6. 还在手动发早安吗?教你用java实现每日给女友微信发送早安

    摘要:教你如何用java实现每日给女友微信发送早安等微信信息. 本文分享自华为云社区<java实现每日给女友微信发送早安等微信信息>,作者:穆雄雄 . 前言 据说这个功能最近在抖音上很火, ...

  7. 云小课 | 网络知识一箩筐——NAT网关,让IP地址华丽变身,轻松实现内外网互通

    阅识风云是华为云信息大咖,擅长将复杂信息多元化呈现,其出品的一张图(云图说).深入浅出的博文(云小课) 或短视频(云视厅)总有一款能让您快速上手华为云.更多精彩内容请单击此处. 摘要: 网络知识一箩筐 ...

  8. 如何使用参数化查询提高Cypher查询的性能

    摘要:在DBMS中,参数化查询被视为一种有效预防SQL注入攻击的手段. 本文分享自华为云社区<使用参数化查询提高Cypher查询的性能:以华为云图引擎GES为例>,作者: 蜉蝣与海. 在D ...

  9. 开心档之CSS 测验

    ​ 目录 CSS 测验 ​编辑 CSS 测验 CSS测验是一种衡量前端开发人员对CSS的熟练程度的测试.通过CSS测验,可以评估一个人对CSS语言的掌握程度和应用能力,帮助公司或招聘方挑选合适的人才. ...

  10. 当OLAP碰撞Serverless,看ByteHouse如何建设下一代云计算架构

    更多技术交流.求职机会,欢迎关注字节跳动数据平台微信公众号,回复[1]进入官方交流群 作为云计算的下一个迭代,Serverless 可以使开发者更专注于构建产品中的应用,而无需考虑底层堆栈问题.伴随着 ...