chrony 是什麼?html
Chrony是一個開源的自由軟件,像CentOS 7或基於RHEL 7操做系統,已是默認服務,默認配置文件在 /etc/chrony.conf 它能保持系統時間與時間服務器(NTP)同步,讓時間始終保持同步。相對於NTP時間同步軟件,佔據很大優點。其用法也很簡單。centos
Chrony有兩個核心組件,分別是:chronyd:是守護進程,主要用於調整內核中運行的系統時間和時間服務器同步。它肯定計算機增減時間的比率,並對此進行調整補償。chronyc:提供一個用戶界面,用於監控性能並進行多樣化的配置。它能夠在chronyd實例控制的計算機上工做,也能夠在一臺不一樣的遠程計算機上工做。服務器
ntp 時間同步的缺點網絡
chrony 的優點ide
chrony 的使用工具
安裝性能
系統默認已經安裝,如過沒有安裝ui
yum install chrony -y操作系統
啓動與中止code
systemctl start chronyd.service
systemctl stop chronyd.service
開機自啓動
systemctl enable chronyd.service
防火牆設置
firewall-cmd --add-service=ntp --permanent
firewall-cmd --reload
配置文件說明
cat /etc/chrony.conf # Use public servers from the pool.ntp.org project. pool.ntp.org項目中的公共服務器。以server開,理論上你想添加多少時間服務器均可以。 # Please consider joining the pool (http://www.pool.ntp.org/join.html). #server 0.centos.pool.ntp.org iburst #server 1.centos.pool.ntp.org iburst #server 2.centos.pool.ntp.org iburst #server 3.centos.pool.ntp.org 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 // 將啓用一個內核模式,在該模式中,系統時間每11分鐘會拷貝到實時時鐘(RTC) # Enable hardware timestamping on all interfaces that support it. #hwtimestamp * # Increase the minimum number of selectable sources required to adjust # the system clock. #minsources 2 # Allow NTP client access from local network. #allow 192.168.0.0/16 # Serve time even if not synchronized to a time source. #local stratum 10 # Specify file containing keys for NTP authentication. #keyfile /etc/chrony.keys # Specify directory for log files. logdir /var/log/chrony # Select which information is logged. #log measurements statistics tracking local stratum 10 // 指定一臺主機、子網,或者網絡以容許或拒絕NTP鏈接到扮演時鐘服務器的機器 allow 0.0.0.0/0 allow ::/0
配置內網 chrony 時間服務器
在server 端配置文件 etc/chrony.conf 修改以下,
server 10.15.10.66 iburst
其餘客戶端配置文件指明以下,刪除或註釋公用的ntp 服務器
server 10.15.10.66 iburst # 指明
重啓服務chronyd
查看同步狀態
chronyc sources -v
查看時間同步源狀態:
chronyc sourcestats -v
檢查 同步狀態
timedatectl
當 NTP synchronized: yes
設置硬件時間
硬件時間默認爲UTC:
timedatectl set-local-rtc 1
啓用NTP時間同步:
timedatectl set-ntp yes
校準時間服務器:
chronyc tracking