0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

为什么Linux系统时间老是不准

dyquk4xk2p3d 来源:良许Linux 作者:良许Linux 2022-11-06 14:27 次阅读

一、使用 NTP 服务时间同步

安装 ntp

[root@node~]#yum-yinstallntp

启动 ntp 服务

[root@node~]#systemctlstartntpd
[root@node~]#systemctlenablentpd
Createdsymlinkfrom/etc/systemd/system/multi-user.target.wants/ntpd.serviceto/usr/lib/systemd/system/ntpd.service.

查看 ntp 服务

[root@node~]#systemctlstatusntpd
●ntpd.service-NetworkTimeService
Loaded:loaded(/usr/lib/systemd/system/ntpd.service;enabled;vendorpreset:disabled)
Active:active(running)sinceThu2022-08-0408:00:47CST;7hleft
MainPID:20746(ntpd)
Tasks:1
Memory:768.0K
CGroup:/system.slice/ntpd.service
└─20746/usr/sbin/ntpd-untp:ntp-g

Aug0408:00:47nodentpd[20746]:Listennormallyon6lo::1UDP123
Aug0408:00:47nodentpd[20746]:Listennormallyon7ens33fe80::8a83:7297:7cb8:9934UDP123
Aug0408:00:47nodentpd[20746]:Listeningonroutingsocketonfd#24forinterfaceupdates
Aug0408:00:47nodesystemd[1]:StartedNetworkTimeService.
Aug0408:00:47nodentpd[20746]:0.0.0.0c01606restart
Aug0408:00:47nodentpd[20746]:0.0.0.0c01202freq_setkernel0.000PPM
Aug0408:00:47nodentpd[20746]:0.0.0.0c01101freq_not_set
Aug0408:00:56nodentpd[20746]:0.0.0.0c61c0cclock_step-28798.353463s
Aug0400:00:57nodentpd[20746]:0.0.0.0c61404freq_mode
Aug0400:00:58nodentpd[20746]:0.0.0.0c61808no_sys_peer

修改 ntp.conf 文件

[root@node~]#vim/etc/ntp.conf
[root@node~]#grepserver/etc/ntp.conf
#Usepublicserversfromthepool.ntp.orgproject.
#server0.centos.pool.ntp.orgiburst
serverntp.aliyun.comiburst
#broadcast192.168.1.255autokey#broadcastserver
#broadcast224.0.1.1autokey#multicastserver
#manycastserver239.255.254.254#manycastserver

重启服务

[root@node~]#systemctlrestartntpd

检查同步状态

[root@node~]#ntpq-p
remoterefidsttwhenpollreachdelayoffsetjitter
==============================================================================
203.107.6.88100.107.25.1142u264130.975149.4990.393

二、使用 ntpdate 同步

使用 ntpd 命令同步

[root@node~]#ntpdatentp.aliyun.com
4Aug0017ntpdate[20924]:adjusttimeserver203.107.6.88offset-0.001543sec

查看时间

[root@node~]#date
ThuAug40046CST2022

三、处理 ntpdate 同步失败报错方法

报错信息

cna02:~#ntpdatentp1.aliyun.com
4Aug0741ntpdate[18694]:theNTPsocketisinuse,exiting

处理方法

cna02:~#servicentpdstop
Redirectingto/bin/systemctlstopntpd.service

重新同步

cna02:~#ntpdatentp1.aliyun.com
3Aug2336ntpdate[28980]:steptimeserver120.25.115.20offset-28911.609110sec

查看时间是否正确

cna02:~#date
WedAug32341CST2022

四、使用 chrony 服务时间同步

安装 chrony

[root@node~]#yum-yinstallchrony
Loadedplugins:fastestmirror,langpacks
Loadingmirrorspeedsfromcachedhostfile
*base:mirrors.bfsu.edu.cn
*extras:mirrors.bfsu.edu.cn
*updates:mirrors.bfsu.edu.cn
ResolvingDependencies
-->Runningtransactioncheck
--->Packagechrony.x86_640:3.2-2.el7willbeupdated
--->Packagechrony.x86_640:3.4-1.el7willbeanupdate
-->FinishedDependencyResolution

DependenciesResolved

===============================================================================================================================================================================
PackageArchVersionRepositorySize
===============================================================================================================================================================================
Updating:
chronyx86_643.4-1.el7base251k

TransactionSummary
===============================================================================================================================================================================
Upgrade1Package

Totaldownloadsize:251k
Downloadingpackages:
NoPrestometadataavailableforbase
chrony-3.4-1.el7.x86_64.rpm|251kB00:00:00
Runningtransactioncheck
Runningtransactiontest
Transactiontestsucceeded
Runningtransaction
Updating:chrony-3.4-1.el7.x86_641/2
Cleanup:chrony-3.2-2.el7.x86_642/2
Verifying:chrony-3.4-1.el7.x86_641/2
Verifying:chrony-3.2-2.el7.x86_642/2

Updated:
chrony.x86_640:3.4-1.el7

Complete!

启动 chrony 服务

[root@node~]#systemctlenable--nowchronyd
Createdsymlinkfrom/etc/systemd/system/multi-user.target.wants/chronyd.serviceto/usr/lib/systemd/system/chronyd.service.

查看 chrony 状态

[root@node~]#systemctlstatuschronyd
●chronyd.service-NTPclient/server
Loaded:loaded(/usr/lib/systemd/system/chronyd.service;enabled;vendorpreset:enabled)
Active:active(running)sinceThu2022-08-040027CST;29sago
Docs:man:chronyd(8)
man:chrony.conf(5)
Process:21136ExecStartPost=/usr/libexec/chrony-helperupdate-daemon(code=exited,status=0/SUCCESS)
Process:21132ExecStart=/usr/sbin/chronyd$OPTIONS(code=exited,status=0/SUCCESS)
MainPID:21134(chronyd)
Tasks:1
Memory:364.0K
CGroup:/system.slice/chronyd.service
└─21134/usr/sbin/chronyd

Aug0400:12:27nodesystemd[1]:StartingNTPclient/server...
Aug0400:12:27nodechronyd[21134]:chronydversion3.4starting(+CMDMON+NTP+REFCLOCK+RTC+PRIVDROP+SCFILTER+SIGND+ASYNCDNS+SECHASH+IPV6+DEBUG)
Aug0400:12:27nodesystemd[1]:StartedNTPclient/server.
Aug0400:12:35nodechronyd[21134]:Selectedsource193.182.111.141
Aug0400:12:35nodechronyd[21134]:Source78.46.102.180replacedwith94.237.64.20

修改配置文件

[root@node~]#grepserver/etc/chrony.conf
#Usepublicserversfromthepool.ntp.orgproject.
#server0.centos.pool.ntp.orgiburst
#server1.centos.pool.ntp.orgiburst
#server3.centos.pool.ntp.orgiburst
serverntp1.aliyun.comiburst

重启服务

[root@node~]#systemctlrestartchronyd

检查时间同步状态

[root@node~]#chronycsources
210Numberofsources=1
MSName/IPaddressStratumPollReachLastRxLastsample
===============================================================================
^*120.25.115.20267126+751us[+1549us]+/-19ms

五、手动修改时间

修改时间方法 1

[root@node~]#date-s"2012-05-230101"
WedMay230101CST2012
[root@node~]#date
WedMay230105CST2012

修改时间方法 2

修改时间顺序为月日时分年. 秒

[root@tianyi~]#date090621282021.28
MonSep62128CST2021

硬件时间向系统时间同步

[root@node~]#hwclock-w

按格式输出时间

[root@node~]#date"+%Y-%m-%d%H:%M:%S"
2012-05-230110

设置时区

[root@tianyibackups]#timedatectllist-timezones|grepShanghai
Asia/Shanghai
[root@tianyibackups]#timedatectlset-timezoneAsia/Shanghai

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • Linux系统
    +关注

    关注

    4

    文章

    567

    浏览量

    26926
  • 格式
    +关注

    关注

    0

    文章

    22

    浏览量

    16810
  • NTP
    NTP
    +关注

    关注

    1

    文章

    95

    浏览量

    13784

原文标题:Linux 系统时间老是不准怎么办?

文章出处:【微信号:良许Linux,微信公众号:良许Linux】欢迎添加关注!文章转载请注明出处。

收藏 人收藏

    评论

    相关推荐

    时间总是不准该怎么办?

    仪表时间
    风雷仪表
    发布于 :2023年08月17日 13:02:01

    ds1302 时间不准 电容怎么添加?

    1.接上晶振后,时间不准 然后利用单片机起振电路那样,并联电容6pf 但是时钟每分钟变快6秒,电容增加到10pf 时钟又变慢?请问ds1302的电容是怎么接的?
    发表于 12-03 21:58

    stm8采集Ads1230数据不准

    用stm8采集ads1230数据老是不准,波动很大,但是网上说这个可以精确到0.01g。
    发表于 07-11 06:48

    如何设置linux时间为网络时间

    Linux时间分为System Clock(系统时间)和Real Time Clock (硬件时间,简称RTC)。
    发表于 07-23 08:00

    Linux系统时间分为哪几种

    Linux系统时间分为两种:系统时间和硬件时间系统
    发表于 11-04 08:14

    投屏老是中断是什么原因?

    最近小编发现有诸多的小伙伴们对于投屏老是中断是什么原因都颇为感兴趣的,大家也都想要及时了解到投屏老是中断是什么原因相关信息,那么小编今天就来为大家梳理下具体的关于这个问题的一些消息吧。
    的头像 发表于 04-22 10:55 7w次阅读

    时控开关为什么时间不准确,其原因是为何

    时控开关上显示的时间不准确(就是时钟显示的时间和实际的时间不一样)?而且设置好的定时到时间也没有相应的开、关操作,确定设置的开关
    发表于 03-08 16:07 1.1w次阅读

    嵌入式Linux 硬件时间-系统时间-时区设置

    Linux系统时间分为两种:系统时间和硬件时间系统
    发表于 11-01 16:58 11次下载
    嵌入式<b class='flag-5'>Linux</b> 硬件<b class='flag-5'>时间</b>-<b class='flag-5'>系统</b><b class='flag-5'>时间</b>-时区设置

    嵌入式Linux系统时间设置

    Linux系统的很多功能都需要读取时间为基础。比如:日志系统需要时间戳以记录log,为后期的问题排查提供支撑;cron服...
    发表于 11-01 16:58 1次下载
    嵌入式<b class='flag-5'>Linux</b><b class='flag-5'>系统</b><b class='flag-5'>时间</b>设置

    嵌入式linux通过程序设置系统时间,嵌入式Linux系统时间的实现

    看了这篇文章,我决定今天去玩玩板子上的RTC模块首先,明确一个问题:1、嵌入式系统板子上的时间是用date标准系统命令查看的,date是SHELL命令,例如busybox或者uClinux
    发表于 11-01 17:21 10次下载
    嵌入式<b class='flag-5'>linux</b>通过程序设置<b class='flag-5'>系统</b><b class='flag-5'>时间</b>,嵌入式<b class='flag-5'>Linux</b><b class='flag-5'>系统</b>下<b class='flag-5'>时间</b>的实现

    优化嵌入式Linux的启动时间之文件系统

    导读:嵌入式Linux在应用中往往希望系统能在尽量短的时间内启动,以提高用户体验。而且在有的应用场合,对启动时间具有严格的时间要求,尤其在工
    发表于 11-02 14:36 8次下载
    优化嵌入式<b class='flag-5'>Linux</b>的启动<b class='flag-5'>时间</b>之文件<b class='flag-5'>系统</b>

    51单片机怎么显示当前时间_导航显示的剩余时间是怎么来的,准不准

    51单片机怎么显示当前时间_导航显示的剩余时间是怎么来的,准不准
    发表于 11-23 16:51 11次下载
    51单片机怎么显示当前<b class='flag-5'>时间</b>_导航显示的剩余<b class='flag-5'>时间</b>是怎么来的,准<b class='flag-5'>不准</b>

    Linux系统时间不准怎么解决?

    报错信息 cna02:~ # ntpdate ntp1.aliyun.com 4 Aug 0741 ntpdate[18694]: the NTP socket is in use, exiting
    发表于 10-27 12:37 9651次阅读

    32.768khz晶振时间不准有偏差的原因

    32.768kHz晶振是一种常见的晶振频率,广泛应用于实时钟电路、计时电路和低功耗设备中。然而,有时候会发现32.768kHz晶振的时间不准,存在一定的偏差。JSK晶鸿兴将介绍几个可能导致32.768kHz晶振时间
    的头像 发表于 07-26 14:51 1358次阅读

    Linux上怎么配置NTP时间同步呢?

    Linux上怎么配置NTP时间同步呢? NTP是一种用于同步计算机系统时钟的网络协议。在Linux系统中,配置NTP
    的头像 发表于 01-16 16:03 497次阅读