Chronyd同步時間(Server/Client)配置

来源:https://www.cnblogs.com/Renqy/archive/2020/05/29/12987125.html
-Advertisement-
Play Games

chronyd時間伺服器,和之前NTP的功能一樣,提供時間的。基礎概念我就不說了,不擅長。chronyd是NTP之後誕生的。最近下載了最新的Centos Linux 8.1,發現裡面沒有ntp服務了,百度一搜發現改為了Chronyd,這篇文章就是部署一個伺服器+客戶端測試。1、伺服器端Centos ... ...


chronyd時間伺服器,和之前NTP的功能一樣,提供時間的。

基礎概念我就不說了,不擅長。chronyd是NTP之後誕生的。

最近下載了最新的Centos Linux 8.1,發現裡面沒有ntp服務了,百度一搜發現改為了Chronyd,這篇文章就是部署一個伺服器+客戶端測試。

1、伺服器端

Centos Linux 8.1 預設安裝了chronyd服務。我們只需要配置即可。

配置文件配置

紅色部分是需要伺服器配置的,這是基本配置,主要在於實現基本功能。

vim /etc/chrony.conf

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# pool 2.centos.pool.ntp.org iburst
# 同步哪台伺服器上的時間
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
# 允許哪個網段的客戶端同步時間,133這台是伺服器。
allow 192.168.94.0/24

# Serve time even if not synchronized to a time source.
# 字面翻譯,提供時間即使沒有同步一個時間源。
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

啟動chronyd,並設置開機自啟

[root@filesystem ~]# systemctl start chronyd
[root@filesystem ~]# systemctl enable chronyd

查看時間同步情況,本地能夠同步才能夠讓其他節點進行同步

timedatectl是一個時間配置工具,用於設定時間、與時間相關的配置等。

[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)
# 當此值為yes代表同步成功,如果為no就代表未同步,或同步失敗。
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
[root@filesystem ~]#

查看當前時間是從哪裡同步過來的,這裡顯示的是主機名。不影響。

[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 ~]#

防火牆配置

防火牆要能放行此服務,關閉防火牆或是放行相應的埠及服務。

關閉防火牆,並設置開機不啟動

[root@filesystem ~]# systemctl stop firewalld
[root@filesystem ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@filesystem ~]#

設置防火牆放行規則

[root@filesystem ~]# netstat -antup | grep chrony
udp        0      0 127.0.0.1:323           0.0.0.0:*                           35191/chronyd
udp        0      0 0.0.0.0:123             0.0.0.0:*                           35191/chronyd
udp6       0      0 ::1:323                 :::*                                35191/chronyd
[root@filesystem ~]#
# 只有upd 123埠
[root@filesystem ~]# firewall-cmd --permanent --add-port=123/udp
success
[root@filesystem ~]# firewall-cmd --reload
success
[root@filesystem ~]#

2、客戶端配置

配置文件配置

vim /etc/chrony.conf

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# pool 2.centos.pool.ntp.org iburst
server 192.168.94.133 iburst

配置開機自啟

[root@node1 ~]# systemctl restart chronyd
[root@node1 ~]# systemctl enable chronyd
[root@node1 ~]#

查看同步狀態及信息

[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,但是如何判斷它是原來的時間還是同步好了。畢竟很多系統不同步時間也是近似的。

3、設置時間

我們對chronyd伺服器端進行時間修改。

這裡說明一點,時間的修改只能在時間不進行同步的狀態下進行,也就是說,如果時間是同步中的,是不允許修改時間的。對時間進行保護。

[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 ~]#

我們測試效果,關掉ntp,修改時間

timedatectl set-ntp 0

[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 ~]#

客戶端查看時間

[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 ~]#

客戶端不重啟服務也是能同步的,如果你下去做實驗的話,可以測試下。


讀書和健身總有一個在路上


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 幾種常見的加密方法的實現 1.ACSII碼加密 //ACSII碼加密 private static string ACSIIPWd(string rpwd) { string Ret; byte[] array = System.Text.Encoding.ASCII.GetBytes(rpwd); ...
  • 上一篇文章(https://www.cnblogs.com/meowv/p/12961014.html)集成了定時任務處理框架Hangfire,完成了一個簡單的定時任務處理解決方案。 本篇緊接著來玩一下AutoMapper,AutoMapper可以很方便的搞定我們對象到對象之間的映射關係處理,同時a ...
  • docker容器把資源抽象成對象;作為客戶端,docker這個命令其實就是在對這些抽象出來的資源對象做增刪查改的操作;docker的API是RESTful風格的API,所以它支持類似像http協議里的GET、POST、PUT、DELETE等操作;RESTful風格的API有這樣的特點;1、每一個U... ...
  • 樹莓派版本: Raspberry Pi 4B 操作系統 : Ubuntu Server 20.04_x64 使用 ip a 查看無線網卡名稱: ubuntu@ubuntu:~$ ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue st ...
  • 步驟說明: <步驟1:打開控制面板> <步驟2:設置日期,時間> 操作截圖: ...
  • 一、Ubuntu安裝: 為什麼用Ubuntu,作為伺服器初學者開發,如果真的要買蘋果系統電腦性價比不高,所以在window系統中安裝Linux虛擬機是不二之選。為什麼用Ubuntu不多說了,開始安裝吧。 以window 10 為例: 1)點擊控制面板->搜索"開發者設置"->設置開發者模式 2)點擊 ...
  • Linux 下如果我們進入到了一個比較長的路徑,比如: /home/alvin/projects/blogdemos/linux-system-programming/thread /home/alvin/projects/blogdemos/diff /home/harry/study/亞洲文化/ ...
  • linux命令tr: (Translate/ Text Replacer):可以對來自標準輸入的內容進行字元替換,字元刪除,以及重覆字元壓縮。 ***只從stdin標準輸入接收數據: 格式:tr [options] set1 set2 將輸入按照位置從set1映射到set2,然後將輸出寫到stdou ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...