首页 电商 正文

linux显示时间命令(Linux 部署时间同步服务Chrony(Centos7)

2024-03-21 20:35
admin

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

https://chrony.tuxfamily.org/comparison.html

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

[root@kmi-dawufiep~]#yuminstallchrony-y

[root@kmi-dawufiep~]#systemctlenablechronyd.service

[root@kmi-dawufiep~]#systemctlrestartchronyd.service

[root@kmi-dawufiep~]#systemctlstatuschronyd.service

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

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

[root@kmi-dawufiep~]#firewall-cmd--reload

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

#时间同步公共服务器地址。以server开头,理论上可以添加多个时间服务器地址

#Theseserversweredefinedintheinstallation:

serverntp.ntsc.ac.cniburst

servercn.ntp.org.cniburst

servertime.pool.aliyun.comiburst

servertime1.aliyun.comiburst

servertime2.aliyun.comiburst

servertime1.cloud.tencent.comiburst

servertime2.cloud.tencent.comiburst

#Usepublicserversfromthepool.ntp.orgproject.

#Pleaseconsiderjoiningthepool(http://www.pool.ntp.org/join.html).

#根据实际时间计算出服务器增减时间的比率,然后记录到一个文件中,在系统重启后为系统做出最佳时间补偿调整。

#Recordtherateatwhichthesystemclockgains/lossestime.

driftfile/var/lib/chrony/drift

#chronyd根据需求减慢或加速时间调整,

#在某些情况下系统时钟可能漂移过快,导致时间调整用时过长。

#该指令强制chronyd调整时期,大于某个阀值时步进调整系统时钟。

#只有在因chronyd启动时间超过指定的限制时(可使用负值来禁用限制)没有更多时钟更新时才生效。

#Allowthesystemclocktobesteppedinthefirstthreeupdates

#ifitsoffsetislargerthan1second.

makestep1.03

#将启用一个内核模式,在该模式中,系统时间每11分钟会拷贝到实时时钟(RTC)。

#Enablekernelsynchronizationofthereal-timeclock(RTC).

rtcsync

#通过使用hwtimestamp指令启用硬件时间戳

#Enablehardwaretimestampingonallinterfacesthatsupportit.

#hwtimestamp*

#Increasetheminimumnumberofselectablesourcesrequiredtoadjust

#thesystemclock.

#minsources2

#指定一台主机、子网,或者网络以允许或拒绝NTP连接到扮演时钟服务器的机器

#AllowNTPclientaccessfromlocalnetwork.

#allow192.168.0.0/16

#Servetimeevenifnotsynchronizedtoatimesource.

#localstratum10

#指定包含NTP验证密钥的文件。

#SpecifyfilecontainingkeysforNTPauthentication.

#keyfile/etc/chrony.keys

#指定日志文件的目录。

#Specifydirectoryforlogfiles.

logdir/var/log/chrony

#Selectwhichinformationislogged.

#logmeasurementsstatisticstracking

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

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

[root@kmi-dawufiep~]#timedatectl

Localtime:四2021-05-0616:16:09CST

Universaltime:四2021-05-0608:16:09UTC

RTCtime:四2021-05-0608:16:09

Timezone:Asia/Shanghai(CST,+0800)

NTPenabled:yes

NTPsynchronized:yes

RTCinlocalTZ:no

DSTactive:n/a

2.查看时区列表

[root@kmi-dawufiep~]#timedatectllist-timezones|grep-E"Asia/S.*"

Asia/Sakhalin

Asia/Samarkand

Asia/Seoul

Asia/Shanghai

Asia/Singapore

Asia/Srednekolymsk

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

[root@kmi-dawufiep~]#timedatectlset-timezoneAsia/Shanghai

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

[root@kmi-dawufiep~]#timedatectlset-local-rtc0

5.启用NTP时间同步

[root@kmi-dawufiep~]#timedatectlset-ntptrue

6.校准时间服务器

[root@kmi-dawufiep~]#chronyctracking

ReferenceID:8BC7D7FB(139.199.215.251)

Stratum:3

Reftime(UTC):ThuMay0608:25:542021

Systemtime:0.000144202secondsfastofNTPtime

Lastoffset:+0.000068143seconds

RMSoffset:0.001500069seconds

Frequency:5.699ppmslow

Residualfreq:+0.007ppm

Skew:1.656ppm

Rootdelay:0.015710194seconds

Rootdispersion:0.006367063seconds

Updateinterval:5.0seconds

Leapstatus:Normal

7.查看时间同步状态

[root@kmi-dawufiep~]#timedatectlstatus

Localtime:四2021-05-0616:28:41CST

Universaltime:四2021-05-0608:28:41UTC

RTCtime:四2021-05-0608:28:40

Timezone:Asia/Shanghai(CST,+0800)

NTPenabled:yes

NTPsynchronized:yes

RTCinlocalTZ:no

DSTactive:n/a

8.常用命令

查看时间同步源状态

[root@kmi-dawufiep~]#chronycsourcestats-v

[root@kmi-dawufiep~]#chronycsources-v

查看ntpserver是否在线

[root@kmi-dawufiep~]#chronycactivity-v

查看ntp详细信息

[root@kmi-dawufiep~]#chronyctracking-v

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

相关文章

  • 华为官网root权限申请(华为手机ROOT权限难吗)

    华为官网root权限申请(华为手机ROOT权限难吗) 注:如果在root中途提醒规定解锁码上,填好上一步得到的16位号就可以。,3、安裝取得成功以后,手机软件会全自动对手机上开展root实际操作。,还有一点提醒各位小伙伴们,刷机跟ROOT不是一个概念,大家不要混淆了。

    2024-03-21 20:58
  • 淘宝用什么root

    淘宝用什么root 用户可以在非root的情况下浏览商品、下单购买、查看订单等操作。,然而,有些用户可能希望通过root权限实现更多功能,如隐藏已购买的商品、屏蔽广告、修改显示界面等。,但需要注意的是,淘宝官方并不支持或推荐用户对其进行root操作。

    2024-03-18 10:17