linux显示时间命令(linux两条命令一起执行)

Linux 部署时间同步服务Chrony(Centos7)

一、概述

常见的时间同步工具有:chrony、ntp、openntpd;RHEL7版本以后默认支持chrony;

三种工具的详细区别参考
https://chrony.tuxfamily.org/comparison.html

chrony包含两个程序:chronyd和chronyc,其中chronyd是守护进程,用于调整内核运行时间和时钟服务器同步;用于监视 chronyd 的性能并在运行时更改各种操作参数;

二、安装Chrony服务

[root@kmi-dawufiep ~]# yum install chrony -y
[root@kmi-dawufiep ~]# systemctl enable chronyd.service
[root@kmi-dawufiep ~]# systemctl restart chronyd.service
[root@kmi-dawufiep ~]# systemctl status chronyd.service

在防火墙开启的情况下,需要开发ntp服务通过(ntp使用UDP端口123)

[root@kmi-dawufiep ~]# firewall-cmd --add-service=ntp --permanent
[root@kmi-dawufiep ~]# firewall-cmd --reload

三、配置Chrony服务

chrony配置文件:/etc/chrony.conf

#时间同步公共服务器地址。以server开头,理论上可以添加多个时间服务器地址
# These servers were defined in the installation:
serverntp.ntsc.ac.cniburst
servercn.ntp.org.cniburst
servertime.pool.aliyun.comiburst
servertime1.aliyun.com iburst
servertime2.aliyun.com iburst
servertime1.cloud.tencent.com iburst
servertime2.cloud.tencent.com iburst
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).

# 根据实际时间计算出服务器增减时间的比率,然后记录到一个文件中,在系统重启后为系统做出最佳时间补偿调整。
# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift

# chronyd根据需求减慢或加速时间调整,
# 在某些情况下系统时钟可能漂移过快,导致时间调整用时过长。
# 该指令强制chronyd调整时期,大于某个阀值时步进调整系统时钟。
# 只有在因chronyd启动时间超过指定的限制时(可使用负值来禁用限制)没有更多时钟更新时才生效。
# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3

# 将启用一个内核模式,在该模式中,系统时间每11分钟会拷贝到实时时钟(RTC)。
# Enable kernel synchronization of the real-time clock (RTC).
rtcsync

# 通过使用hwtimestamp指令启用硬件时间戳
# 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

# 指定一台主机、子网,或者网络以允许或拒绝NTP连接到扮演时钟服务器的机器
# Allow NTP client access from local network.
#allow 192.168.0.0/16

# Serve time even if not synchronized to a time source.
#local stratum 10

# 指定包含NTP验证密钥的文件。
# Specify file containing keys for NTP authentication.
#keyfile /etc/chrony.keys

# 指定日志文件的目录。
# Specify directory for log files.
logdir /var/log/chrony

# Select which information is logged.
#log measurements statistics tracking

调整公共服务器地址模块,中国国内时间同步服务器地址可参考:https://dns.icoa.cn/ntp/

四、配置时区

1.查看时间日期、时区、NTP状态

[root@kmi-dawufiep ~]# timedatectl
Local time: 四 2021-05-06 16:16:09 CST
Universal time: 四 2021-05-06 08:16:09 UTC
RTC time: 四 2021-05-06 08:16:09
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a

2.查看时区列表

[root@kmi-dawufiep ~]# timedatectl list-timezones |grep-E "Asia/S.*"
Asia/Sakhalin
Asia/Samarkand
Asia/Seoul
Asia/Shanghai
Asia/Singapore
Asia/Srednekolymsk

3.修改时区为亚洲/上海时区

[root@kmi-dawufiep ~]# timedatectl set-timezone Asia/Shanghai

4.设置硬件时间(默认为UTC:0/1)

[root@kmi-dawufiep ~]# timedatectl set-local-rtc 0

5.启用NTP时间同步

[root@kmi-dawufiep ~]# timedatectl set-ntp true

6.校准时间服务器

[root@kmi-dawufiep ~]# chronyc tracking
Reference ID: 8BC7D7FB (139.199.215.251)
Stratum: 3
Ref time (UTC): Thu May 06 08:25:54 2021
System time: 0.000144202 seconds fast of NTP time
Last offset: +0.000068143 seconds
RMS offset: 0.001500069 seconds
Frequency: 5.699 ppm slow
Residual freq: +0.007 ppm
Skew: 1.656 ppm
Root delay: 0.015710194 seconds
Root dispersion : 0.006367063 seconds
Update interval : 5.0 seconds
Leap status: Normal

7.查看时间同步状态

[root@kmi-dawufiep ~]# timedatectl status
Local time: 四 2021-05-06 16:28:41 CST
Universal time: 四 2021-05-06 08:28:41 UTC
RTC time: 四 2021-05-06 08:28:40
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a

8.常用命令

查看时间同步源状态
[root@kmi-dawufiep ~]# chronyc sourcestats -v
[root@kmi-dawufiep ~]# chronyc sources -v
查看ntp server 是否在线
[root@kmi-dawufiep ~]# chronyc activity -v
查看ntp详细信息
[root@kmi-dawufiep ~]# chronyc tracking -v

调整配置/etc/chrony.conf,需要重启服务生效

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,请发送邮件至624739273@qq.com举报,一经查实,本站将立刻删除。
Like (0)
柳的头像

相关推荐

  • 哪款微单相机比较好,十大微单相机排行最新

    相信经常接触摄影的朋友都知道,最近一两年微单相机市场迅速起飞,无论是从入门机还是高端机。 微单包含两个意思,微,微型小巧,单,可更换式单镜头相机,也就是说这个词是表示了这种相机有小…

    2024年8月25日 投稿
  • 电脑绘图软件下载有哪些(电脑版免费绘画软件推荐)

    古往今来绘画从新石器就出现在陶器图案而至今绘画到处可见,而用来绘画的工具也数不胜数。从最早的毛笔、油画笔、到现在。我们依然在用,他们都是我们生活的一部分。印象最深刻的就是,数位板的…

    2024年9月2日 投稿
  • ps破解版下载安装教程(ps安装破解版教程)

    Adobe Photoshop 简称PS,主要处理以像素所构成的数字图像。使用其众多的编修与绘图工具,可以有效地进行图片编辑工作。 设计、美工等工作时常用到PS软件。由于软件收费,…

    2024年9月1日 投稿
  • 双态it运维(it运维解决方案)

    中国双态运维大会·乌镇峰会是联盟一年一度的官方会议,会议围绕旨在双态IT环境下,为企业IT运维升级转型提供方法指导及最佳实践参考,避免“新技术烟囱”断崖式转型失败,实现IT运维管理…

    2024年9月2日 投稿
  • 新消费中了互联网的毒

    从现在的发展情况来看,新消费是中了互联网和资本的毒的。 与其说,它是一个新物种,不如说,它是一个新概念。 单纯地将新消费看成是一种营销手段,是毫无意义的。 但,人们正走在这条没有意…

    投稿 2024年10月6日
  • 阿里云服务器怎么远程控制(linux开远程命令)

    前言: 最近朋友找我,让我帮他们公司搞一个企业网站。为了友谊长存,我选择拔刀相助。。。 由于需求非常简单、明确,所以推荐他们购买了阿里云ECS的服务器,其实本想选择更加便宜的虚拟机…

    2024年8月28日 投稿

发表回复

Please Login to Comment
微信
微信
SHARE
TOP
要想花得少,就用购宝。话费电费9折起,官方公众号:购宝