知識庫

How to Sync Time with Timezone on CentOS 7 Print

  • 0

 

 

 

How to Synchronize Time and Timezone on CentOS 7 / RHEL 7 / SL 7 / OL 7. Time synchronization is the most vital part of any Linux distros. The configuration of time sync is straight forward using NTP (Network Time Protocol). It includes some couple of commands that works fine with the time synchronization. Keeping different clocks running into a same severs is a quite interesting task to keep running your system time up to date. When any user login to your system so it is so important task to note the user login time according to the local time of that system time zone. Most of the services are running in different time zones so it is vital need to run the system with accurate time.

Step-1 : Check the different available time zones
$ sudo timedatectl list-timezones
 
Step-2 : Set your Time Zone from different timezone
$ sudo timedatectl Asia/Kolkata
 
Step-3 : Sync time using NTP daemons

There are two types of NTP daemons including chronyd and ntpd. You should select and use only one to avoid running two NTP daemons at a same time on same machine this cause ntp incompatibility and instability using two NTP daemons at same time.
This tutorial includes two NTP daemons you should select any one:

  1. Sync time using chronyd (Suitable for virtual system)
  2. Sync time using ntpd (Suitable for networking system)
1. Sync time using chronyd

Install the chronyd package

$ sudo yum install chrony
 

Start the chronyd services

$ sudo systemctl start chrnoyd
 

Edit the configuration file

$ sudo vi /etc/chrony.conf
 

Add these lines

For CentOS

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
 

For RHEL

server 0.rhel.pool.ntp.org iburst
server 1.rhel.pool.ntp.org iburst
server 2.rhel.pool.ntp.org iburst
server 3.rhel.pool.ntp.org iburst
 

After adding these lines simply save and exit.
Restart the services to make changes in effect.

$ sudo systemctl restart chrnoyd
 

 

Enable this services to run at every boot.

 

 

$ sudo systemctl enable chrnoyd
 
OR
 
2. Sync time using ntpd

Install the ntpd package

$ sudo yum install ntp
 

Start the ntpd services

$ sudo systemctl start ntpd
 

Edit the configuration file

$ sudo vi /etc/ntp.conf
 

Add these lines
For CentOS

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
 

For RHEL

server 0.rhel.pool.ntp.org iburst
server 1.rhel.pool.ntp.org iburst
server 2.rhel.pool.ntp.org iburst
server 3.rhel.pool.ntp.org iburst
 

After adding these lines simply save and exit.
Restart the services to make changes in effect.

$ sudo systemctl restart ntpd
 

Enable this services to run at every boot.

$ sudo systemctl enable ntpd
 

Congratulations, now you have enabled the time synchronization and you are able to run different time zones on same system.

 

 

 


這篇文章有幫助嗎?
Back