什么是chrony?
A client/server for the Network Time Protocol, this program keeps your computer's clock accurate. It was specially designed to support systems with intermittent internet connections, but it also works well in permanently connected environments. It can use also hardware reference clocks, system real-time clock or manual input as time references.
chrony是一個(gè)ntp協(xié)議的實(shí)現(xiàn)程序,既可以當(dāng)做服務(wù)端,也可以充當(dāng)客戶端;它專為間歇性互聯(lián)網(wǎng)連接的系統(tǒng)而設(shè)計(jì),當(dāng)然也能良好應(yīng)用于持久互聯(lián)網(wǎng)連接的環(huán)境;chrony有三個(gè)時(shí)間參考:硬件時(shí)鐘、實(shí)時(shí)時(shí)鐘以及手動(dòng)同步。
chrony的程序環(huán)境
~]# rpm -ql chrony
...
/etc/chrony.conf
/usr/bin/chronyc
/usr/sbin/chronyd
...
主配置文件:/etc/chrony.conf
客戶端程序:/usr/bin/chronyc
服務(wù)端程序:/usr/sbin/chronyd
可以通過"man chrony.conf"了解主配置文件的配置格式。
為本地服務(wù)器配置一個(gè)時(shí)間服務(wù)器
1. 環(huán)境
時(shí)間服務(wù)器:192.168.43.101
允許本網(wǎng)段192.168.43.0/24同步時(shí)間。
2.配置服務(wù)端
在編輯配置文件之前,我一般習(xí)慣于備份一下,以備重新調(diào)整。
網(wǎng)絡(luò)時(shí)間服務(wù)器可以自行查找,網(wǎng)上很多資料,下邊配置兩個(gè)個(gè)國(guó)內(nèi)常用的時(shí)間服務(wù)器:
]# cd /etc/
etc]# cp chrony.conf{,.bak}
etc]# vim chrony.conf
...
# iburst為固定格式,記住就可以,沒有深究。
server cn.pool.ntp.org iburst
server tw.pool.ntp.org iburst
...
# 允許指定網(wǎng)絡(luò)的主機(jī)同步時(shí)間,不指定就是允許所有,默認(rèn)不開啟。
allow 192.168.43.0/24
...
# 還有一個(gè)默認(rèn)不開啟的選項(xiàng),意思是,即使服務(wù)端沒有同步到精確的網(wǎng)絡(luò)時(shí)間,也允許向客戶端同步不精確的時(shí)間。可以視情況而定。
# Serve time even if not synchronized to any NTP server.
#local stratum 10
~]# systemctl start chronyd.service
~]# systemctl enable chronyd.service
3.客戶端同步
配置192.168.43.101作為時(shí)間服務(wù)器
etc]# vim chrony.conf
...
server 192.168.43.101 iburst
...
~]# systemctl start chronyd.service
~]# systemctl enable chronyd.service
進(jìn)入chronyc客戶端交互式模式:
~]# chronyc
查看現(xiàn)有的時(shí)間服務(wù)器
chronyc> sources
210 Number of sources = 1
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 192.168.43.101 10 6 377 53 -4546ns[-5000ns] +/- 234us
查看時(shí)間服務(wù)器狀態(tài)
chronyc> sourcestats
210 Number of sources = 1
Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev
==============================================================================
192.168.43.101 10 6 584 +0.001 0.828 +35ns 74us
chronyc>exit
也可以直接在命令行使用:
~]# chronyc sources
~]# chronyc sourcestats
chrony兼容ntpdate,客戶端可以使用ntpdate手動(dòng)同步時(shí)間
~]# ntpdate 192.168.43.101
9 Nov 02:54:30 ntpdate[39551]: adjust time server 192.168.43.101 offset -0.000003 sec