Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Chrony for time synchronization in Linux

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to use Chrony in Linux for time synchronization related knowledge, detailed and easy to understand, simple and fast operation, has a certain reference value, I believe everyone read this Linux how to use Chrony for time synchronization articles will have some gains, let's take a look at it.

Chrony: Chrony is an alternative implementation of NTP (Network Time Protocol), which, unlike ntpd, synchronizes the system clock faster and more accurately, minimizing time and frequency errors.

In CentOS6, the default is to use ntpd to synchronize time, but ntpd synchronization time is not ideal, it may take several hours to synchronize time. NTP is also very old. So in Centos7, chrony is replaced to achieve time synchronization. Chrony is compatible with NTPD and listens on UDP port 123, while it listens on UDP port 323.

If the address of the ntp server is specified in the chrony configuration file, chrony is a client that synchronizes the time of the ntp server. If chrony is configured to allow some clients to synchronize time to themselves, chrony also acts as a server. Therefore, chrony can act as a client or a server when installed. Generally, we only need to be a client, and we don't need to provide time synchronization function to the outside world.

1) The system has been installed by default. If it is not installed, please execute the following command to install: yum install chrony -y

2)Start and join boot self startup systemctl enable chronyd.servicesystemctl start chronyd.service

3)View status systemctl status chronyd.service

4)cat /etc/chrony.conf

#Use public servers in the pool.ntp.org project. Start with server, theoretically you can add as much time as you want to the server.# Please consider joining the pool (http://www.pool.ntp.org/join.html).server 0.centos.pool.ntp.org iburstserver 1.centos.pool.ntp.org iburstserver 2.centos.pool.ntp.org iburstserver 3.centos.pool.ntp.org iburst

#Calculate the ratio of server increase and decrease time according to actual time, and then record it in a file to make the best time compensation adjustment for the system after system restart. driftfile /var/lib/chrony/drift

# chronyd slows down or speeds up time adjustment as needed #In some cases the system clock may drift too fast, causing time adjustment to take too long # This command forces chronyd to adjust the period, stepping the system clock above a certain threshold.# Takes effect only if there are no more clock updates due to chronyd startup time exceeding the specified limit (negative values can be used to disable the limit). makestep 1.0 3

#A kernel mode is enabled in which system time is copied to the real-time clock (RTC) every 11 minutes. rtcsync

# Enable hardware timestamping on all interfaces that support it.# Enable hardware timestamp by using hwtimestamp directive #hwtimestamp eth0#hwtimestamp eth2#hwtimestamp *

# Increase the minimum number of selectable sources required to adjust# the system clock.# minsources 2

#Specify a host, subnet, or network to allow or deny NTP connections to machines acting as clock servers #allow 192.168.0.0/16#deny 192.168/16

# Serve time even if not synchronized to a time source.local stratum 10

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

#Specify the directory of log files. logdir /var/log/chrony

# Select which information is logged.# log measurements statistics tracking

5)Set Time Zone View current system time zone $timedatetlLocal time: Fri 2018-2-29 13:31:04 CSTUniversal time: Fri 2018-2-29 05:31:04 UTCRTC time: Fri 2018-2-29 08:17:20Time zone: Asia/Shanghai (CST, +0800)NTP enabled: yesNTP synchronized: yesRTC in local TZ: noactive DST: n/a

If your current time zone is incorrect, follow these steps to set it.

View all available time zones:

$timedatetl list-timezones Filter View Shanghai in Asia Available time zones:

$ timedatectl list-timezones | grep -E "Asia/S.* "Asia/SakhalinAsia/SamarkandAsia/SeoulAsia/ShanghaiAsia/SingaporeAsia/Srednekolymsk

Set the current system to Asia/Shanghai Shanghai Time zone: $timedatetl set-timezone Asia/Shanghai

After setting the time zone, the system clock under forced synchronization: $ chronyc -a makestep200 OK

Server and client modify the/etc/chrony.conf configuration file to add server xxxx. xx.xx iburst

6)Run chronyc sources on the client//Refresh synchronization chronyc sources -v //View status of time synchronization sources netstat -antpul| grep chron //View the service port and open the corresponding port

About "How to use Chrony for time synchronization in Linux" The content of this article is introduced here, thank you for reading! I believe everyone has a certain understanding of "how to use Chrony for time synchronization in Linux." If you want to learn more, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report