1、服務(wù)器端Centos Linux 8.1 默認(rèn)安裝了chronyd服務(wù)。我們只需要配置即可。 配置文件配置 紅色部分是需要服務(wù)器配置的,這是基本配置,主要在于實(shí)現(xiàn)基本功能。
# Use public servers from the pool. project. # Please consider joining the pool (http://www.pool./join.html). # pool 2.centos.pool. iburst # 同步哪臺(tái)服務(wù)器上的時(shí)間 server 192.168.94.133 iburst # Record the rate at which the system clock gains/losses time. driftfile /var/lib/chrony/drift # Allow the system clock to be stepped in the first three updates # if its offset is larger than 1 second. makestep 1.0 3 # Enable kernel synchronization of the real-time clock (RTC). rtcsync # Allow NTP client access from local network. # allow 192.168.0.0/16 # 允許哪個(gè)網(wǎng)段的客戶(hù)端同步時(shí)間,133這臺(tái)是服務(wù)器。 allow 192.168.94.0/24 # Serve time even if not synchronized to a time source. # 字面翻譯,提供時(shí)間即使沒(méi)有同步一個(gè)時(shí)間源。 local stratum 10 # Specify file containing keys for NTP authentication. keyfile /etc/chrony.keys # Get TAI-UTC offset and leap seconds from the system tz database. leapsectz right/UTC 啟動(dòng)chronyd,并設(shè)置開(kāi)機(jī)自啟 [root@filesystem ~]# systemctl start chronyd [root@filesystem ~]# systemctl enable chronyd 查看時(shí)間同步情況,本地能夠同步才能夠讓其他節(jié)點(diǎn)進(jìn)行同步 timedatectl是一個(gè)時(shí)間配置工具,用于設(shè)定時(shí)間、與時(shí)間相關(guān)的配置等。 [root@filesystem ~]# timedatectl Local time: 五 2020-05-29 11:17:46 EDT Universal time: 五 2020-05-29 15:17:46 UTC RTC time: 五 2020-05-29 15:17:46 Time zone: America/New_York (EDT, -0400) # 當(dāng)此值為yes代表同步成功,如果為no就代表未同步,或同步失敗。 System clock synchronized: yes NTP service: active RTC in local TZ: no [root@filesystem ~]# 查看當(dāng)前時(shí)間是從哪里同步過(guò)來(lái)的,這里顯示的是主機(jī)名。不影響。 [root@filesystem ~]# chronyc sources 210 Number of sources = 1 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* filesystem 10 7 377 537 +11us[ +25us] +/- 30us [root@filesystem ~]# 防火墻配置
2、客戶(hù)端配置配置文件配置
# Use public servers from the pool. project. # Please consider joining the pool (http://www.pool./join.html). # pool 2.centos.pool. iburst server 192.168.94.133 iburst 配置開(kāi)機(jī)自啟 [root@node1 ~]# systemctl restart chronyd [root@node1 ~]# systemctl enable chronyd [root@node1 ~]# 查看同步狀態(tài)及信息 [root@node1 ~]# timedatectl Local time: 五 2020-05-29 11:28:12 EDT Universal time: 五 2020-05-29 15:28:12 UTC RTC time: 五 2020-05-29 15:28:12 Time zone: America/New_York (EDT, -0400) System clock synchronized: yes NTP service: active RTC in local TZ: no [root@node1 ~]# chronyc sources 210 Number of sources = 1 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* filesystem 11 6 17 34 -520ns[+7955ns] +/- 15ms [root@node1 ~]# 我們看到是yes,但是如何判斷它是原來(lái)的時(shí)間還是同步好了。畢竟很多系統(tǒng)不同步時(shí)間也是近似的。 3、設(shè)置時(shí)間我們對(duì)chronyd服務(wù)器端進(jìn)行時(shí)間修改。 這里說(shuō)明一點(diǎn),時(shí)間的修改只能在時(shí)間不進(jìn)行同步的狀態(tài)下進(jìn)行,也就是說(shuō),如果時(shí)間是同步中的,是不允許修改時(shí)間的。對(duì)時(shí)間進(jìn)行保護(hù)。 [root@filesystem ~]# timedatectl Local time: 五 2020-05-29 11:30:40 EDT Universal time: 五 2020-05-29 15:30:40 UTC RTC time: 五 2020-05-29 15:30:40 Time zone: America/New_York (EDT, -0400) System clock synchronized: yes NTP service: active RTC in local TZ: no [root@filesystem ~]# 我們測(cè)試效果,關(guān)掉ntp,修改時(shí)間
[root@filesystem ~]# timedatectl set-ntp 0 [root@filesystem ~]# timedatectl set-time "2020-06-01 01:01:01" [root@filesystem ~]# timedatectl set-ntp 1 [root@filesystem ~]# systemctl restart chronyd [root@filesystem ~]# timedatectl Local time: 一 2020-06-01 01:01:20 EDT Universal time: 一 2020-06-01 05:01:20 UTC RTC time: 一 2020-06-01 05:01:20 Time zone: America/New_York (EDT, -0400) System clock synchronized: yes NTP service: active RTC in local TZ: no [root@filesystem ~]# 客戶(hù)端查看時(shí)間 [root@node1 ~]# systemctl restart chronyd [root@node1 ~]# [root@node1 ~]# timedatectl Local time: 一 2020-06-01 01:01:55 EDT Universal time: 一 2020-06-01 05:01:55 UTC RTC time: 五 2020-05-29 15:46:52 Time zone: America/New_York (EDT, -0400) System clock synchronized: yes NTP service: active RTC in local TZ: no [root@node1 ~]# 客戶(hù)端不重啟服務(wù)也是能同步的,如果你下去做實(shí)驗(yàn)的話(huà),可以測(cè)試下。 讀書(shū)和健身總有一個(gè)在路上 |
|
來(lái)自: 行者花雕 > 《待分類(lèi)》