chrony time synchronization service

Keywords: Linux Operation & Maintenance TCP/IP

brief introduction

NTP is the network time protocol, which is used to synchronize the time of each computer in the network.
NTP and chrony cannot exist at the same time. You can only use one of them and remove the other mask
Chrony is an open source free software, which can help you keep the system clock synchronized with the clock server (NTP), so keep your time accurate. It consists of two programs, chronyd and chronyc. Chronyd is a daemon running in the background, which is used to adjust the system clock running in the kernel and synchronize with the clock server. It determines the rate at which the computer increases or decreases time and compensates for it. Chronyc provides a user interface for monitoring performance and diversifying configurations. It can work on a computer controlled by a chronyd instance or on a different remote computer.

Installation and application of chrony


apt install chrony   (Or use yum)

Add a time synchronization server: alicloud ntp is used here

 vim /etc/chrony/chrony.conf 

Restart service:

systemctl restart chrony

View time synchronization source:

root@fff-PC:~# chronyc sources –v 
210 Number of sources = 1
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
^?                  2   6     1     6  -1353us[-1353us] +/-   37ms

Common configuration items of configuration file

/Configuration file path of / etc/chrony/chrony.conf

server:  Indicate the time server address;
allow NETADD/NETMASK Allow those clients to synchronize
allow all:  ;Allow all client hosts
deny all:  Reject all clients;
bindcmdaddress:  Address monitored by command management interface;
local stratum 10:  Even if you fail to synchronize to the time through the network time server, you are allowed to give the local time to other clients as the standard time.

Options for chronyc

accheck - checks if NTP access is available to a specific host
activity - this command displays how many NTP sources are online / offline
add server - manually add a new NTP server.
clients - reports on the client that the server has been accessed
delete - manually remove the NTP server or peer server
Set time - manually set the daemon time
tracking - displays system time information

Exercise - setting up a local time synchronization server


apt install chrony		    #Installation services
systemctl restart chronyd
systemctl enable chronyd
vim /etc/chrony/chrony.conf 	    #Modify the following in the configuration file
allow		    #Which clients are allowed to synchronize the time of the host
local stratum 10 		          #Add, the machine does not synchronize any host time, and the machine is used as the time source

systemctl restart chronyd	    #Restart service
netstat -antulp|grep chronyd      #Check whether the time server allows
timedatectl 	                #Displays the current system date and time


apt install chrony
cat /etc/chrony/chrony.conf 
#pool 		#Comment this line
server  iburst	#Point the time server to our self built server. burst means that when the NTP server is unavailable, send a series of concurrent packets to it for detection

systemctl restart chronyd          #Restart service
ss -anptu | grep chronyd    #Query the chrony service port

timedatectl        #Displays the current system date and time
chronyc sources –v	        #View time synchronization sources

Time setting tool timedatectl

View current time / date / time zone: timedatectl or timedatectl status
View all available time zones: timedatectl list timezones
Set time zone: timedatectl set timezone "time zone information"
Set UTC: timedatectl set timezone UTC
Set time: timedatectl set time HH: mm: SS
Set date: timedatectl set time yyyy MM DD
Set date time: timedatectl set time "YYYY-MM-DD HH:MM:SS"
Set the hardware clock to local time: timedatectl set local RTC 1
Set the hardware clock to UTC time: timedatectl set local RTC 0
Start NTP time synchronization (enable NTP service or Chrony service): timedatectl set NTP true
Disable NTP time synchronization: timedatectl set NTP false

Posted by martinco on Sat, 20 Nov 2021 18:53:56 -0800