一、使用 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文章
593浏览量
27393 -
格式
+关注
关注
0文章
23浏览量
16886 -
NTP
+关注
关注
1文章
169浏览量
13892
原文标题:Linux 系统时间老是不准怎么办?
文章出处:【微信号:良许Linux,微信公众号:良许Linux】欢迎添加关注!文章转载请注明出处。
发布评论请先 登录
相关推荐
评论