您好,登錄后才能下訂單哦!
立即同步時(shí)間的壞處,影響某些計(jì)劃任務(wù)執(zhí)行
一、立即同步時(shí)間
方法一:
ntpdate ntp.aliyun.com
方法二:重啟ntp服務(wù)
方法三:重啟chrony服務(wù)
二、查看ntp和chrony狀態(tài)
[root@textbox ~]# chronyc sources -v
210 Number of sources = 1
.-- Source mode '^' = server, '=' = peer, '#' = local clock.
/ .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| / '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
|| .- xxxx [ yyyy ] +/- zzzz
|| Reachability register (octal) -. | xxxx = adjusted offset,
|| Log2(Polling interval) --. | | yyyy = measured offset,
|| \ | | zzzz = estimated error.
|| | | \
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* localhost 3 6 17 2 +62us[ +661us] +/- 88ms
[root@textbox ~]#
[root@textbox ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*localhost 119.28.206.193 3 u 41 64 177 0.784 1.195 3656236
三、ntp做服務(wù)端的設(shè)置
#注釋原來(lái)的ntp服務(wù)器,原來(lái)的ntp服務(wù)器都是centos.org美國(guó)的
[root@textbox ~]# sed '/^server/s/^/#/' /etc/ntp.conf -i
#添加兩個(gè)aliyun的
[root@textbox ~]# sed '1a server ntp.aliyun.com iburst' /etc/ntp.conf -i
[root@textbox ~]# sed '1a server ntp1.aliyun.com iburst' /etc/ntp.conf -i
#重啟服務(wù)
[root@textbox ~]# systemctl restart ntpd
#ntp就這么簡(jiǎn)單,就可以當(dāng)服務(wù)器使用了
[root@textbox ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
+120.25.115.20 10.137.53.7 2 u 4 64 17 42.560 -8.795 6.944
*203.107.6.88 100.107.25.114 2 u 4 64 17 15.542 -7.021 6.460
#123端口,udp
[root@textbox ~]# ss -lutnp | grep ntp
udp UNCONN 0 0 192.168.38.140:123 *:* users:(("ntpd",pid=61668,fd=19))
udp UNCONN 0 0 127.0.0.1:123 *:* users:(("ntpd",pid=61668,fd=18))
udp UNCONN 0 0 *:123 *:* users:(("ntpd",pid=61668,fd=16))
udp UNCONN 0 0 fe80::69d0:5288:fda9:93ae%ens33:123 :::* users:(("ntpd",pid=61668,fd=21))
udp UNCONN 0 0 ::1:123 :::* users:(("ntpd",pid=61668,fd=20))
udp UNCONN 0 0 :::123 :::* users:(("ntpd",pid=61668,fd=17))
#用另一臺(tái)服務(wù)器測(cè)試
[root@linux5 ~]# ntpdate 192.168.38.140
5 Sep 09:17:25 ntpdate[28423]: adjust time server 192.168.38.140 offset -0.007790 sec
四、chrony服務(wù)端配置
設(shè)置項(xiàng)比ntp多
[root@imooc-nginx ~]# sed '/^server/s/^/#/' /etc/chrony.conf -i
[root@imooc-nginx ~]# sed '1a server ntp.aliyun.com iburst' /etc/chrony.conf -i
[root@imooc-nginx ~]# sed '1a server 0.cn.pool.ntp.org iburst' /etc/chrony.conf -i
[root@imooc-nginx ~]# sed '1a server ntp1.aliyun.com iburst' /etc/chrony.conf -i
#即使當(dāng)前時(shí)服務(wù)器未與指定ntp完成時(shí)間同步,照樣提供服務(wù)
[root@imooc-nginx ~]# sed '1a local stratum 10' /etc/chrony.conf -i
#允許哪些服務(wù)器同步
[root@imooc-nginx ~]# sed '1a allow 192.168.0.0/16' /etc/chrony.conf -i
[root@imooc-nginx ~]# systemctl restart chronyd
[root@imooc-nginx ~]# systemctl enable chronyd
#查看chronyd狀態(tài)
[root@imooc-nginx ~]# chronyc sources -v
210 Number of sources = 3
.-- Source mode '^' = server, '=' = peer, '#' = local clock.
/ .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| / '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
|| .- xxxx [ yyyy ] +/- zzzz
|| Reachability register (octal) -. | xxxx = adjusted offset,
|| Log2(Polling interval) --. | | yyyy = measured offset,
|| \ | | zzzz = estimated error.
|| | | \
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^+ 120.25.115.20 2 6 17 4 +766us[ +591us] +/- 21ms
^- 111.230.189.174 2 6 17 4 +98us[ +98us] +/- 49ms
^* 203.107.6.88 2 6 17 4 -187us[ -361us] +/- 16ms
#測(cè)試
[root@textbox ~]# ntpdate 192.168.38.154
5 Sep 09:33:25 ntpdate[61810]: adjust time server 192.168.38.154 offset -0.010546 sec
五、自動(dòng)同步時(shí)間兩種方式
1、ntpdate ntp.aliyun.com寫入計(jì)劃任務(wù),每小時(shí)同步一次
2、所有服務(wù)器chrony都開啟,其中一臺(tái)做時(shí)間服務(wù)器,其他服務(wù)器的server都指向它
六、設(shè)置時(shí)區(qū)
[root@textbox ~]# timedatectl set-timezone Asia/Shanghai
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。