Chrony
Chrony是一個開源自由的網(wǎng)絡(luò)時間協(xié)議 NTP 的客戶端和服務(wù)器軟軟件。它能讓計算機(jī)保持系統(tǒng)時鐘與時鐘服務(wù)器(NTP)同步,因此讓你的計算機(jī)保持精確的時間,Chrony也可以作為服務(wù)端軟件為其他計算機(jī)提供時間同步服務(wù)。
對比ntpd
NTP(Network Time Protocol)和Chrony都是用于同步計算機(jī)時鐘的協(xié)議,它們都可以在計算機(jī)集群中實現(xiàn)時間同步。但是,它們有一些不同之處:
算法:NTP使用一種復(fù)雜的算法來同步時鐘,而Chrony使用一種叫做"temporal median"的算法,該算法可以在更短的時間內(nèi)同步時鐘。
精度:Chrony通常比NTP更準(zhǔn)確,尤其是在網(wǎng)絡(luò)延遲較高的情況下。Chrony可以在網(wǎng)絡(luò)延遲較高的情況下保持更好的同步精度。
配置:Chrony的配置比NTP簡單,而且可以自動適應(yīng)網(wǎng)絡(luò)環(huán)境。另外,Chrony可以在沒有網(wǎng)絡(luò)連接的情況下使用本地時鐘源進(jìn)行同步。
安全性:NTP在安全性方面存在一些問題,因為它沒有內(nèi)置的身份驗證機(jī)制。而Chrony支持加密和身份驗證機(jī)制,可以提供更好的安全性。
安裝chrony,直接yum安裝即可
# yum -y install chrony
# systemctl start chrony
# systemctl enable chrony
修改配置,/etc/chrony.conf 主要配置內(nèi)容如下:
# 使用 pool.ntp.org 項目中的公共服務(wù)器。以server開,理論上想添加多少時間服務(wù)器都可以。
# Use public servers from the pool.ntp.org project.
# 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
# 根據(jù)實際時間計算出服務(wù)器增減時間的比率,然后記錄到一個文件中,在系統(tǒng)重啟后為系統(tǒng)做出最佳時間補償調(diào)整。
# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift
# 如果系統(tǒng)時鐘的偏移量大于1秒,則允許系統(tǒng)時鐘在前三次更新中步進(jìn)。
# Allow the system clock to be stepped in the first three updates if its offset is larger than 1 second.
makestep 1.0 3
# 啟用實時時鐘(RTC)的內(nèi)核同步。
# Enable kernel synchronization of the real-time clock (RTC).
rtcsync
# 通過使用 hardwaretimestamp 指令啟用硬件時間戳
# 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
# 指定 NTP 客戶端地址,以允許或拒絕連接到扮演時鐘服務(wù)器的機(jī)器
# 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
# 指定包含 NTP 身份驗證密鑰的文件。
# 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
主要修改以下兩處:
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
需要同步的時間服務(wù)器地址,如:
server ntp.aliyun.com iburst
# Allow NTP client access from local network.
允許客戶端連接地址或網(wǎng)段,如:
allow 192.168.0.0/16
修改完配置,重啟服務(wù)
# systemctl restart chrony
chronyc命令
# chronyc sources -v 查看ntp_server
# chronyc sourcestats -v 查看ntp_server狀態(tài)
# chronyc activity -v 查看在線情況
# chronyc tracking -v 查看詳細(xì)信息
# chronyc -a makestep 強(qiáng)制同步系統(tǒng)時鐘
授時中心地址
210.72.145.44 國家授時中心
ntp.aliyun.com 阿里云
s1a.time.edu.cn 北京郵電大學(xué)
s1b.time.edu.cn 清華大學(xué)
s1c.time.edu.cn 北京大學(xué)
s1d.time.edu.cn 東南大學(xué)
s1e.time.edu.cn 清華大學(xué)
s2a.time.edu.cn 清華大學(xué)
s2b.time.edu.cn 清華大學(xué)
s2c.time.edu.cn 北京郵電大學(xué)
s2d.time.edu.cn 西南地區(qū)網(wǎng)絡(luò)中心
s2e.time.edu.cn 西北地區(qū)網(wǎng)絡(luò)中心
s2f.time.edu.cn 東北地區(qū)網(wǎng)絡(luò)中心
s2g.time.edu.cn 華東南地區(qū)網(wǎng)絡(luò)中心
s2h.time.edu.cn 四川大學(xué)網(wǎng)絡(luò)管理中心
s2j.time.edu.cn 大連理工大學(xué)網(wǎng)絡(luò)中心
s2k.time.edu.cn CERNET桂林主節(jié)點
s2m.time.edu.cn 北京大學(xué)
ntp.sjtu.edu.cn 202.120.2.101 上海交通大學(xué)