How To Install and Setup NTP Server On CentOS Stream 9

install and setting NTP server on CentOS Stream 9

In this short article we are going to learn how to install and configure NTP server on CentOS Stream 9. An NTP (Network Time Protocol) server is a computer system that provides accurate time to client computers or devices over a network. NTP servers synchronize the time of devices on a network to a reference time source, such as an atomic clock or a GPS receiver, to ensure consistency and accuracy across the network.

Installing NTP Server

In this time, we will install and configure NTP server using chrony. Chrony is a versatile implementation of the Network Time Protocol (NTP) used for synchronizing the system clock with remote NTP servers or local reference clocks. It aims to provide accurate timekeeping and high stability even in situations where the network connection is intermittent or the time sources are unreliable.

NTP Server Installation Steps

This tutorial will cover how to install and configure Chrony (NTP server) on CentOS Stream 9 to automatically synchronize time with the closest geographical peers available for your server location by using the NTP Public Pool Time Servers list. We will be using NTP Public Pool Time Servers for our reference where the server physically is located.

  1. Updating System Repository
  2. Installing Chrony.
  3. Configuring Chrony.

Updating System Repository

It’s recommended to update our package repository to ensure we’re getting the latest version of packages in our system. For this purpose we will submite command line :

$ sudo dnf update -y

Installing Chrony

To instal Chrony we wil submit following command line :

$ sudo dnf -y install chrony

Output :

[ramansah@bckinfo ~]$ sudo dnf -y install chrony 
[sudo] password for ramansah:
Last metadata expiration check: 0:16:14 ago on Fri 10 May 2024 10:13:50 PM WIB.
Package chrony-4.5-1.el9.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!

We will start and enable Chrony service by submitting command line :

$ sudo systemctl enable chronyd 
$ sudo systemctl start chronyd

Configuring Chrony

After Chrony is completed, then we will adjust the reference country which is located at NTP daemon main configuration file (/etc/chrony.conf). We will edit this file by add comment on the default list of Public Servers from the pool.ntp.org project and replace it with the list provided for your country which is provided on the default list of Public Servers list.

$ sudo vi /etc/chrony.conf

the outpus is as shown below, we will use pool server 0.asia.pool.ntp.org which is suitable with our region.

[ramansah@bckinfo ~]$ sudo vi /etc/chrony.conf 

Use public servers from the pool.ntp.org project.
# Please consider joining the pool (https://www.pool.ntp.org/join.html).
#pool 2.centos.pool.ntp.org iburst
server 0.asia.pool.ntp.org
server 1.asia.pool.ntp.org
server 2.asia.pool.ntp.org
server 3.asia.pool.ntp.org

# Use NTP servers from DHCP.
sourcedir /run/chrony-dhc

Restarting Service

After all are set, the we will restart Chrony service and checking its status, by submitting command line :

[ramansah@bckinfo ~]$ sudo systemctl restart chronyd
[ramansah@bckinfo ~]$ sudo systemctl status chronyd
● chronyd.service - NTP client/server
Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; preset: enabled)
Active: active (running) since Mon 2024-05-13 13:32:48 WIB; 12s ago
Docs: man:chronyd(8)
man:chrony.conf(5)
Process: 4213 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 4215 (chronyd)
Tasks: 2 (limit: 22828)
Memory: 1.1M
CPU: 52ms
CGroup: /system.slice/chronyd.service
└─4215 /usr/sbin/chronyd -F 2

May 13 13:32:48 bckinfo systemd[1]: Starting NTP client/server...
May 13 13:32:48 bckinfo chronyd[4215]: chronyd version 4.5 starting (+CMDMON +NTP +REFCLOCK +RTC>
May 13 13:32:48 bckinfo chronyd[4215]: Loaded 0 symmetric keys
May 13 13:32:48 bckinfo chronyd[4215]: Frequency -3.110 +/- 0.779 ppm read from /var/lib/chrony/>
May 13 13:32:48 bckinfo chronyd[4215]: Using right/UTC timezone to obtain leap second data
May 13 13:32:48 bckinfo chronyd[4215]: Loaded seccomp filter (level 2)

Once the NTP daemon has been restarted, we will verify the NTP peers’ synchronization status and your system time. Wait a few minutes then submit the following command line :

$ sudo chronyc sources
[ramansah@bckinfo ~]$ sudo chronyc sources
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^- 103.17.182.30 2 8 377 258 +6327us[+6327us] +/- 210ms
^+ 202.4.186.250 2 9 377 74 +5701us[+5701us] +/- 85ms
^* time.citra.net.id 2 10 337 587 -4403us[-5727us] +/- 55ms
^+ ns1.ads.net.id 2 8 377 1104 -986us[-2253us] +/- 105ms

Allow Chrony in the Firewall

If the firewall service is our server is enabled, then we have allow Chrony to communicate through it, by submitting command line :

ramansah@bckinfo ~]$ sudo firewall-cmd --add-service=ntp 
success
[ramansah@bckinfo ~]$ sudo firewall-cmd --runtime-to-permanent
success

The NTP Server installation and configuration has been completed on the system.

Conclusion

NTP server is an important matter for building reliable system. Overall, Chrony is a reliable and flexible solution for maintaining accurate time synchronization in computer systems, making it suitable for a wide range of applications, including servers, desktops, and embedded devices.

(Visited 18 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *