Recently, I ran into an issue where I discovered a few Linux servers I work with were operating under an assumed time zone. Because of that time drift, certain services wouldn’t function properly. In particular, two servers both served as nodes on a Docker Swarm cluster and were unable to perform their duties and MariaDB database replication failed. After fixing that simple issue, I realized it was time to start paying closer attention to the time on my servers.
With that, I was reminded of a tool that helps make this simple. Said tool is Chrony, which will constantly keep your time in sync on your servers and desktops.
SEE: 40+ open source and Linux terms you need to know (TechRepublic Premium)
Let’s get Chrony installed on Linux. I’ll demonstrate on both Ubuntu Server 22.04 and Rocky Linux 9.
What you’ll need
The only things you’ll need are one or Linux Server installations and a user with sudo privileges. That’s it — let’s get our time in sync.
How to set your time zone
Before we install and use Chrony, we’ll want to make sure the time zones are configured properly. Before you set your time zone, you’ll want to know the exact format. For that, issue the command:
timedatectl list-timezones
Scan through the list of time zones and find the correct one for your area. Once you know your time zone, set it with the command:
sudo timedatectl set-timezone TIMEZONE
Where TIMEZONE is the correct time zone for your area.
How to install Chrony
Next, we can install Chrony. On Ubuntu Server (or any Debian derivative), the command for that installation is:
sudo apt-get install chrony -y
On Rocky Linux or any RHEL derivative, that command is:
sudo dnf install chrony -y
Start and enable Chrony with:
sudo systemctl enable --now chronyd
Enable the Chrony NTP service and check the time
Finally, we can enable the Chrony NTP service and verify the time on the server.
Enable Chrony NTP with the command:
sudo timedatectl set-ntp yes
You can now view the time data on your system with:
timedatectl
You should see, in the output (Figure A), that NTP service is active and the time and time zone are correct.
Figure A
And there you have it, the simplest way to keep your Linux servers’ time in sync. If you ever run into an issue where a service or app fails for no apparent reason, check your time. If you find time incorrectly set or drifts, Chrony and timedatectl
are always there to help you out.
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.