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 Linux Chrony

2025-02-25 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 Linux Chrony related knowledge, detailed and easy to understand, simple and fast operation, has a certain reference value, I believe everyone will have a harvest after reading this article on how to use Linux Chrony, let's take a look at it.

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

Chrony has two core components: chronyd: is a daemon that is primarily used to adjust system time and time server synchronization running in the kernel. It determines the rate at which the computer increases or decreases time and adjusts to compensate for it. Chronyc: Provides a user interface for monitoring performance and making various configurations. It can work on a computer controlled by chronyd instances, or it can work on a different remote computer.

OS environment:

10.28.204.65 Client

10.28.204.66 Server

CentOS Linux release 7.4.1708 (Core)

Description: The two machines are intranet, 204.66 as NTP time server, 204.65 synchronization time on this machine.

1. Install Chrony

The system has been installed by default. If it is not installed, please execute the following command to install it:

$ yum install chrony -y2. start and join boot autostart $ systemctl enable chronyd. service $ systemctl restart chronyd.service$ systemctl status chronyd.service3.Firewalld setup $ firewall-cmd --add-service=ntp --permanent$ firewall-cmd --reload

Because NTP uses port 123/UDP protocol, it is sufficient to allow NTP service.

4. Configure Chrony

The following is the default configuration file for the system, which I will explain:

$ cat /etc/chrony.conf#Use public servers from the pool.ntp.org project. Open 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 3.centos.pool.ntp.org iburst#Calculate the ratio of server increase/decrease time based on actual time and record it in a file to make the best time compensation adjustment for the system after system restart. 2.centos.pool.ntp.org driftfile /var/lib/chrony/drift# chronyd Slows or speeds up time adjustment as required #In some cases the system clock may drift too fast, resulting in time adjustment taking 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#will enable a kernel mode 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.# #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 a file containing NTP authentication keys.# keyfile /etc/chrony.keys#Specifies the directory of log files. logdir /var/log/chrony# Select which information is logged.# log measurements statistics tracking5. Set time zone

View current system time zone:

$ timedatectl Local time: Fri 2018-2-29 13:31:04 CST Universal time: Fri 2018-2-29 05:31:04 UTC RTC time: Fri 2018-2-29 08:17:20 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: yesNTP synchronized: yesRTC in local TZ: no DST active: n/a If your current time zone is incorrect, set it as follows. View all available time zones: $timedatetl list-timezones Filter View Shanghai in Asia Available time zones: $timedatetl list-timezones| grep -E "Asia/S.* "Asia/SakhalinAsia/SamarkandAsia/SeoulAsia/ShanghaiAsia/SingaporeAsia/Srednekolymsk Set the current system to Asia/Shanghai time zone: $timedatetl set-timezone Asia/Shanghai After setting the time zone, the system clock under forced synchronization: $ chronyc -a makestep200 OK6. System time synchronization between server clusters

In a production environment, the network is an intranet structure, so how does the intranet ensure time synchronization between servers? In fact, this problem is very simple, just need to set up an intranet time server, and then let all computers to the server (10.28.204.66) to synchronize the time.

Specific operation: Note the following contents on the server side:

#server 0.centos.pool.ntp.org iburst#server 1.centos.pool.ntp.org iburst#server 2.centos.pool.ntp.org iburst#server 3.centos.pool.ntp.org iburst and add the following content: (indicates synchronization time with this machine) server 10.28.204.66 iburst Such an intranet time server we need has been configured. Also comment out other servers on the client side and add the following on the client side (10.28.204.65): server 10.28.204.66 iburst

The synchronization of system time has been completed. If there are multiple machines, the operation is the same.

7. frequently used commands

View Time Sync Source:

$ chronyc sources -v View time synchronization source status: $ chronyc sourcestats -v Set hardware time Hardware time defaults to UTC: $timedatetl set-local-rtc 1 Enable NTP time synchronization: $timedatetl set-ntp yes Calibrate time server: $ chronyc tracking

Finally, after configuring/etc/chrony.conf, restart chrony service, otherwise it may not take effect.

The content of this article on "How to use Linux Chrony" is introduced here. Thank you for reading it! I believe everyone has a certain understanding of "how to use Linux Chrony" knowledge. If you still want to learn more knowledge, 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