Time synchronization is crucial for the proper functioning of servers and network applications. In CentOS 7, you can synchronize time using services like chrony
and ntpd
. This article provides a detailed guide on how to set up and configure time synchronization on CentOS 7.
Time Synchronization Using chrony
-
Install chrony:
First, install the
chrony
package if it is not already installed:Verify accuracy of synchronization: You can also verify how well the time is synchronized with the following command:
-
Enable and start the chronyd service:
After installation, enable the
chronyd
service to start automatically at boot and then start it:sudo systemctl enable chronyd sudo systemctl start chronyd
-
Check the status of the chronyd service:
Ensure that the service is running correctly:
sudo systemctl status chronyd
-
Configure chrony (optional):
The configuration file for
chrony
is located at/etc/chrony.conf
. Here, you can specify NTP servers if you want to use different ones than the defaults.Example configuration file with custom NTP servers:
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
After modifying the configuration file, restart the service to apply the changes:
sudo systemctl restart chronyd
-
Check synchronization status:
Check the synchronization status with the following command:
chronyc tracking
This command displays information about the synchronization status with NTP servers.
-
Verify accuracy of synchronization:
You can also verify how well the time is synchronized with the following command:
chronyc sources
Time Synchronization Using ntpd
If you prefer to use ntpd
, follow these steps:
-
Install the
ntp
package:First, install the
ntp
package if it is not already installed:sudo yum install ntp
-
Enable and start the ntpd service:
After installation, enable the
ntpd
service to start automatically at boot and then start it:sudo systemctl enable ntpd sudo systemctl start ntpd
-
Check the status of the ntpd service:
Ensure that the service is running correctly:
sudo systemctl status ntpd
-
Configure ntp (optional):
The configuration file for
ntpd
is located at/etc/ntp.conf
. Here, you can specify NTP servers if you want to use different ones than the defaults.Example configuration file with custom NTP servers:
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
After modifying the configuration file, restart the service to apply the changes:
sudo systemctl restart ntpd
-
Synchronize time manually:
Manually synchronize the time using the
ntpdate
command before startingntpd
to ensure the time is set correctly:sudo ntpdate pool.ntp.org
Then restart the
ntpd
service:sudo systemctl restart ntpd
-
Verify synchronization:
Check if the time is synchronized correctly:
ntpq -p
This command displays a list of NTP servers your system is synchronized with and the synchronization status with these servers.
Enable NTP Synchronization Using timedatectl
To ensure that the system time is synchronized with NTP servers, you can also use the following command:
sudo timedatectl set-ntp true
This command ensures that NTP synchronization is active.
Time synchronization on CentOS 7 is crucial for the proper functioning of servers and network applications. Using chrony
or ntpd
services ensures that your system maintains accurate time. This article provides a detailed guide on how to set up and configure time synchronization to ensure your systems operate as efficiently as possible.