How To Change Server & Hardware Time in CentOS

When using a CentOS 7 server in a production environment, it is ideal and necessary to configure specific parameters correctly so that all associated processes work correctly.

One of these parameters is the time of the server since a lousy synchronization and configuration of this will incur a malfunction of applications that depend on hourly resource factors and this always affects synchronization tasks, such as updates and files, if the server time and the client computers are incorrect.

Today, we will see how in a few steps we will adjust the time of our CentOS 7 Server.

Install NTP on CentOS Linux

1. To set the time in CentOS 7 correctly, we will use the ntp and ntpdate commands, and for its installation, we will execute the following command:

yum install ntp ntpdate

2. Once the packages are loaded, we will see the following. There we confirm the download and installation of ntp and ntpdate.

Configure NTP To Set Server Time on CentOS Linux

1. Once installed, we will execute the following commands:

systemctl start ntpd ( Start the ntp service )

systemctl enable ntpd ( Enables the ntp service )

systemctl status ntpd ( Displays the status of the ntp service )

2. With this validated, we will run the ntpdate command to add the defined CentOS NTP servers. In this case, the -u wich tells ntpdate to use a non-privileged port for the outgoing packets, and the -s parameter enables the output log from a standard output (by default) to the system syslog function, execute the following :

ntpdate - u - s 0.centos . pool . ntp . 1.centos org . pool . ntp . 2.centos org . pool . ntp . org

3. Now, we restart the ntp service to synchronize the date and time of the CentOS NTP server with our local date and time:

systemctl restart ntpd

4. We proceed to verify using the “timedatectl” command that the NTP synchronization is enabled and if it is correct:

5. There, we have used the “hwclock” utility, which configures the hardware clock with the current system time using the “-w” indicator like this:

hwclock -w

6. If you need help on the “ntp” command, we can execute any of the following options:

man ntpdate
man hwclock

We can see how easy it is to set the CentOS 7 time and thus allow all associated services and processes to be unaffected.

Similar Posts

Leave a Reply

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