How to Set the Timezone in CentOS 7

Содержание

How to Set the Timezone in CentOS 7

While you are setting up a new server, very often you might have to set the timezone. In certain cases, you might want to change your timezone.

Setting the appropriate timezone on servers is something many of us forget. Setting an inappropriate timezone will impact your server reporting and logs. That’s why in this tutorial, we’ll show you how to set a timezone in CentOS 7.

Setting the correct time zone for your CentOS based VPS is important for accurately logging timestamps, else you may end up noting a wrong date and timestamp for the incident or error log.

Apart from logging and reporting, another very important factor is the time set for crontabs and automated jobs. Setting an inappropriate time zone may end up running the processes at a different than actually intended time. Luckily if you want to set the timezone in CentOS 7, you’ll only need to use a few simple commands!

Overall, not setting the proper time zone won’t break your operation, but will definitely improve your workflow and will easily prevent a lack of clarity in your logs.

Let’s learn how to set the timezone in CentOS 7.

How to Check the Set Timezone in CentOS 7

First of all, we need to access our VPS server using SSH. If you’re having trouble, reference the PuTTY tutorial!

You can check your current time zone by using the date command as shown below:

This will output the time in the following format:

Alternatively, you can use the timedatectl command. This command can:

  • Review the dates and timestamps
  • Change the date and time
  • Setup a timezone for the system
  • Enable automatic synchronization of the clock based on a remote server

The basic command looks like this:

The output will be as shown below:

This contains information such as local time, universal time, and timezone.

How to List Timezones in CentOS 7

Once you have viewed your current timezone, you might want to list all the available timezone options. The below command can be used to list all the timezone options:

You’ll get a long list showing all the timezones in alphabetical order. You can refine your search by adding filters using grep patterns. One such example is as shown below:

How to Set Timezone in CentOS 7

Once you have the list of timezones, you can set the one you prefer. To set the timezone in CentOS 7, you can use:

You can replace the time zone accordingly in the command above. Over here we can also set a specific time and date. This can be done using the below format:

For instance, if you want this to be set the time as Mar-16-2019 and the current time as 09:20:00, then you can use:

After making these changes, you can again check the time zone details using timedatectl.

How to Set the Hardware Clock in CentOS 7

A hardware clock is different from the system clock which is managed by the Linux kernel. This is also referred to as the BIOS clock. The hardware clock is enabled once the system is shut down. Using Linux commands, you can set the hardware clock.

To check if the hardware clock is set to local time zone use the below command:

This will give output as shown below, which means the hardware clock does not have a timezone specified:

Next, you can set your hardware clock to local time zone using the below command:

To revert the changes, you can use:

How to Perform Clock Synchronization on CentOS 7

Network Time Protocol (NTP) is an internet protocol which is commonly used to synchronize system clocks on different computers. The timedatectl command can configure a system’s time zone to automatically sync with a remote server using NTP.

To enable this, first, we should have NTP installed on the system. In order to start synchronization with a remote NTP server use the below command:

In case you want to revert these changes, use the below command. This will disable time synchronization:

Conclusion

Here we have seen how to set timezone on CentOS 7 as well as how to set system time, date, hardware clock time and synchronize systems using NTP. Setting the right timezone is important for correct logging, automated processes and more!

It’s easy to set the timezone on CentOS 7. And yes, to learn about more options, you can always check the manual pages for the timedatectl command.

Edward is an expert communicator with years of experience in IT as a writer, marketer, and Linux enthusiast. IT is a core pillar of his life, personal and professional. Edward’s goal is to encourage millions to achieve an impactful online presence. He also really loves dogs, guitars, and everything related to space.


Источник: www.hostinger.com