How to Sync Server Time in AlmaLinux: A Step-by-Step Guide
Sync Server Time in AlmaLinux – Keeping your server’s time synchronized is crucial for maintaining the accuracy of logs, scheduling tasks, and ensuring that time-based applications function correctly. AlmaLinux, a popular RHEL fork, offers several methods for synchronizing time. In this blog post, we’ll walk you through the steps to sync server time using timedatectl
, chrony
, and ntpd
.
Method 1: Using timedatectl
for Quick Time Sync
timedatectl
is a straightforward command-line utility that manages system time and date settings. If you need a quick sync without installing additional software, follow these steps:
- Check Current Time Configuration Open your terminal and run:
timedatectl status
This command displays the current time settings and whether NTP synchronization is enabled.
- Enable NTP Synchronization If NTP synchronization isn’t active, enable it with:
sudo timedatectl set-ntp true
This command will ensure your system synchronizes with NTP servers automatically.
- Verify Sync Status Confirm that NTP synchronization is enabled and check the status:
timedatectl status
Look for “NTP synchronized: yes” to ensure it’s working.
Method 2: Using chrony
for Reliable Time Sync
chrony
is the recommended time synchronization service for most modern Linux distributions, including AlmaLinux. It provides accurate timekeeping even on systems with intermittent internet connections.
- Install
chrony
Begin by installingchrony
with:sudo dnf install chrony
- Start and Enable
chronyd
Service Activate and ensurechronyd
starts on boot:sudo systemctl start chronyd
sudo systemctl enable chronyd
- Force Immediate Time Sync To immediately synchronize the system clock, use:
sudo chronyc makestep
This forces
chronyd
to correct the system time without waiting for the next synchronization cycle. - Check Synchronization Status Verify the synchronization status with:
chronyc tracking
This command provides detailed information about the current time synchronization.
Method 3: Using ntpd
for Time Sync
For those who prefer the older ntpd
service, follow these steps:
- Install
ntp
Install thentp
package:sudo dnf install ntp
- Start and Enable
ntpd
Service Enable and start thentpd
service:sudo systemctl start ntpd
sudo systemctl enable ntpd
- Sync Time Immediately Force an immediate synchronization with:
sudo ntpdate -u pool.ntp.org
Replace
pool.ntp.org
with your preferred NTP server if needed. - Verify Synchronization Check the status of
ntpd
with:ntpq -p
Sync Server Time in AlmaLinux This command shows the list of NTP servers and their synchronization status.
Troubleshooting Tips
- Firewall Settings: Ensure that your firewall allows NTP traffic (UDP port 123).
- Network Connectivity: Verify that your server has internet access to reach NTP servers.
- Manual Time Settings: Avoid manually setting the system time as it might interfere with synchronization.