一、使用 NTP 服務(wù)時(shí)間同步
安裝 ntp
[root@node~]#yum-yinstallntp
啟動(dòng) ntp 服務(wù)
[root@node~]#systemctlstartntpd [root@node~]#systemctlenablentpd Createdsymlinkfrom/etc/systemd/system/multi-user.target.wants/ntpd.serviceto/usr/lib/systemd/system/ntpd.service.
查看 ntp 服務(wù)
[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
重啟服務(wù)
[root@node~]#systemctlrestartntpd
檢查同步狀態(tài)
[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
查看時(shí)間
[root@node~]#date ThuAug40046CST2022
三、處理 ntpdate 同步失敗報(bào)錯(cuò)方法
報(bào)錯(cuò)信息
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
查看時(shí)間是否正確
cna02:~#date WedAug32341CST2022
四、使用 chrony 服務(wù)時(shí)間同步
安裝 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!
啟動(dòng) chrony 服務(wù)
[root@node~]#systemctlenable--nowchronyd Createdsymlinkfrom/etc/systemd/system/multi-user.target.wants/chronyd.serviceto/usr/lib/systemd/system/chronyd.service.
查看 chrony 狀態(tài)
[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
重啟服務(wù)
[root@node~]#systemctlrestartchronyd
檢查時(shí)間同步狀態(tài)
[root@node~]#chronycsources 210Numberofsources=1 MSName/IPaddressStratumPollReachLastRxLastsample =============================================================================== ^*120.25.115.20267126+751us[+1549us]+/-19ms
五、手動(dòng)修改時(shí)間
修改時(shí)間方法 1
[root@node~]#date-s"2012-05-230101" WedMay230101CST2012 [root@node~]#date WedMay230105CST2012
修改時(shí)間方法 2
修改時(shí)間順序?yàn)樵氯諘r(shí)分年. 秒
[root@tianyi~]#date090621282021.28 MonSep62128CST2021
硬件時(shí)間向系統(tǒng)時(shí)間同步
[root@node~]#hwclock-w
按格式輸出時(shí)間
[root@node~]#date"+%Y-%m-%d%H:%M:%S" 2012-05-230110
設(shè)置時(shí)區(qū)
[root@tianyibackups]#timedatectllist-timezones|grepShanghai Asia/Shanghai [root@tianyibackups]#timedatectlset-timezoneAsia/Shanghai
-
Linux系統(tǒng)
+關(guān)注
關(guān)注
4文章
593瀏覽量
27403 -
格式
+關(guān)注
關(guān)注
0文章
23瀏覽量
16886 -
NTP
+關(guān)注
關(guān)注
1文章
170瀏覽量
13901
原文標(biāo)題:Linux 系統(tǒng)時(shí)間老是不準(zhǔn)怎么辦?
文章出處:【微信號(hào):良許Linux,微信公眾號(hào):良許Linux】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論