When you are a webmaster managing online servers, there some things you usually do when setting up a new server.  Things like setting the root password, configuring the hostname of the server and many others.

One area that’s very important is configuring the internal clock on the server, but few webmasters forget to do this. Setting the correct timezone on the server isn’t required but it’s important.

If you don’t configure the internal clock or add the correct timezone to the server, the server won’t stop working.  In fact, all the services and application will continue to work just fine if you forget to setup the correct timezone.

The area you may run into trouble if you don’t set the correct timezone is server reporting. Your server reports may not generate in the time you want them, because the server clock is setup for a different timezone and services like caching may not be caching properly.

This brief tutorial is going to show you how to configure the correct timezone in CentOS 7 if you haven’t already done so.

With CentOS 6 and 6.5 it was simple as copying the correct timezone to the localtime in the /etc/ directory from /usr/share/zoneinfo directory. It may still be possible to do that in CentOS 7.

CentOS 7 introduces a new command to set the correct timezone. With this one command, you can configure the timezone of your choice and have your system updated.

 

  • Setting up the correct timezone in CentOS 7

To configure the correct time zone in CentOS 7 , run the commands below to first list all the available timezone for your system. The list is ordered alphabetically based on content, country and city.

To list the available timezones, run the commands below.

sudo timedatectl list-timezones

 

This will list the timezones as followed

Africa/Abidjan
Africa/Accra
Africa/Bamako
...
...
America/Menominee
America/Panama
America/Regina
....
....
Europe/Berlin
Europe/Athens

When you go through the list and you’re identify the correct timezone for your servers, run the commands below to set up.
For example, if your server is in the Central timezone in the United States, you’ll want to choose America/Chicago.

The the timezone for Central in US, run the commands below.

sudo timedatectl set-timezone America/Chicago

 

To view the status of the change, run the commands below.

sudo timedatectl

 

That’s it.

 

To automatically synchronize your server internal clocks using ntp servers online, run the commands below to install NTP client.

sudo yum install ntpdate

 

After installing it, run the commands below to synchronize the clock to one of the many NTP servers online. Here’s one server listed for the US areas.

sudo ntpdate 0.us.pool.ntp.org

 

Finally, run the commands below to change the hardware clock.

sudo hwclock --systohc

 

Enjoy!