Chrony - NTP time synchronization

Catalog

Tips

chrony overview

chrony's program configuration

Basic operation command

Tips

Packages of yum install ntpdate are no longer supported by Linux Centos8

chrony overview

chrony is a free and open-source time synchronization software on CentOS 7. X. it can keep the system clock and the clock server (NTP) in synchronization and keep the time accurate. It is an implementation program of NTP protocol, which can be used as both the server and the client. It is designed for the intermittent Internet connection system, and of course, it can also be well applied to the environment of persistent Internet connection. There are three time references: hardware clock, real-time clock and manual synchronization.

It consists of two programs: chronyd and chronyc.

Acronyd is a daemons running in the background, which is used to adjust the synchronization between the system clock running in the kernel and the clock server. It determines the rate at which the computer increases or decreases time and compensates for this.

The chronyc client program.

chrony's program configuration

#Query package installation profile information
rpm -ql chrony

Main configuration file: / etc/chrony.conf
Client program: / usr/bin/chronyc
Server program / usr/sbin/chronyd

  • 1. Modify the configuration file

Configuration parameter description

parameter Parameter description
server Configure the synchronization NTP server time address. It is recommended to configure more than two. For example: server cn.pool.ntp.org iburst
driftfile One of the main behaviors of the cronyd program is to calculate the ratio of the increase and decrease of the computer time according to the actual time. It is the most reasonable to record it in a file. It will make compensation for the system clock after restart, and even get a better estimate from the clock server if possible. System default
makestep Generally, chronyd will make the system gradually correct all time deviations by slowing down or accelerating the clock as required. In some specific cases, the system clock may drift too fast, causing the adjustment process to take a long time to correct the system clock. This instruction forces cronyd to step adjust the system clock when the adjustment period is greater than a certain threshold, but it only takes effect when there are no more clock updates because the startup time of cronyd exceeds the specified limit (negative value can be used to disable the limit). System default
rtcsync The rtcsync instruction enables a kernel mode in which system time is copied to the real-time clock (RTC) every 11 minutes
hwtimestamp Enable hardware time stamping on all hardware enabled interfaces. System default
minsources Increase the system clock with the minimum number of optional sources to be adjusted. System default
allow Allow to specify the host synchronization time of the network. If you don't specify it, you are allowed to allow all. The default is not enabled. For example: 192.168.0.0/16
local stratum The default option is not enabled, which means that even if the server does not synchronize to the exact network time, it is allowed to synchronize the imprecise time to the client. It depends. System default
keyfile

Specifies the file that contains the NTP authentication key. System default

leapsectz Get the TAI-UTC offset and leap seconds from the system tz database. System default
logdir Specifies the directory for the log files. System default
log Select the information to record. System default

Common NTP public time synchronization servers at home and abroad can refer to: https://blog.csdn.net/weixin_42588262/article/details/82501488

The following is the recommended NTP public time synchronization server in China

China Central: cn.pool.ntp.org

China: cn.ntp.org.cn

Alicloud: ntp.aliyun.com

Tencent cloud: time1.cloud.tencent.com

#Profile modification
vi /etc/chrony.conf

You can directly overwrite the content of the configuration file with the following text, and then modify it according to your actual situation

#Configure the synchronization NTP server time address. It is recommended to configure more than two
server ntp.aliyun.com iburst
server cn.pool.ntp.org iburst
server time1.cloud.tencent.com iburst

# According to the actual time, calculate the ratio of the increase and decrease time of the computer, and record it in a file.
driftfile /var/lib/chrony/drift

# Time correction
makestep 1.0 3

#The rtcsync instruction enables a kernel mode in which system time is copied to the real-time clock (RTC) every 11 minutes
rtcsync

#Enable hardware time stamping on all hardware enabled interfaces.
#hwtimestamp *

# Increase the minimum number of optional sources to be adjusted system clock
#minsources 2

# Allow to specify the host synchronization time of the network. If not specified, all are allowed. It is not enabled by default
#allow 192.168.0.0/16
 
# Service time, allowing imprecise time synchronization to clients even if it is not synchronized to any NTP server. 
#local stratum 10

# Specifies the file that contains the NTP authentication key.
keyfile /etc/chrony.keys

#Get the TAI-UTC offset and leap seconds from the system tz database.
leapsectz right/UTC

#Specifies the directory for the log files.
logdir /var/log/chrony

#Select the information to record.
#log measurements statistics tracking
  • 2. Restart service
#Restart service
systemctl start chronyd.service
#Set up startup service
systemctl enable chronyd.service

#View time synchronization source and progress
chronyc sources –v 

chronyc sources – v ා result explanation: * indicates that the time synchronization is completed. If it is "time synchronization", it is "time synchronization"? It indicates that it is not successful. Check the firewall to see if it is restarted. Turn on firewall to allow NTP service permanently

#Permanently allow external NTP time service
firewall-cmd --add-service=ntp --permanent
firewall-cmd --reload

 

  • 3. Adjust time zone

Use the timedatectl command to query the current time zone and date information. If the date and time are not correct, it should be the time zone problem to reset the time zone.

#View date time, time zone and NTP status:
timedatectl

#To view a list of time zones: 
timedatectl list-timezones

#Modify time zone 
timedatectl set-timezone Asia/Shanghai

 

After adjusting the time, the NTP server and server time are set.  

Basic operation command

chrony operation

#Stop the acronyd service
systemctl stop chronyd
#Start the service of cronyd
systemctl start chronyd
#Restart the cronyd service    
systemctl restart chronyd
#View the status of the cronyd service
systemctl status chronyd
#Turn on and start the cronyd service
systemctl enable chronyd
#Disable startup of the cronyd service
systemctl disable chronyd

#View time synchronization source and progress
chronyc sources –v      

#View time synchronization source status
chronyc sourcestats -v

#Calibration time server:
chronyc tracking           

timedatectl time zone / time operation command

#The hardware time defaults to UTC:     
timedatectl set-local-rtc 0


#View date time, time zone and NTP status:
timedatectl

#To view a list of time zones: 
timedatectl list-timezones

#Modify time zone 
timedatectl set-timezone Asia/Shanghai

#Modification date time
timedatectl set-time "2020-03-05 12:20:00"

#Open NTP 
timedatectl set-ntp true/flase

 

 

 

 

Published 7 original articles, won praise 4, 771 visitors
Private letter follow

Tags: firewall network Database yum

Posted on Thu, 05 Mar 2020 00:40:46 -0800 by FrancoPaddy