Syncing Date and Timezone – Install and configure ntpd

For various cluster or distributed application setups it’s an explicit requirement to have date and timezone (TZ) on each node synced. The difference in date or TZ may result in serious issues, for example in case of Puppet Master/Agent setup it’s a must requirement to have the data and TZ synced across all the nodes, if not, Puppet master server being the certificate authority may issue agent certificate from the distant past or future, which other nodes will treat as expire.
For syncing data and timezone across all the nodes, for whatever reason the tool at hand is ntpd.
The Network Time Protocol daemon (ntpd) is an operating system program that maintains the system time in synchronization with time servers using the Network Time Protocol (NTP).

First, let’s get the current date and timezone on the system:
[vagrant@localhost ~]$ timedatectl status
Local time: Mon 2016-11-07 17:02:22 MSK
Universal time: Mon 2016-11-07 14:02:22 UTC
RTC time: Mon 2016-11-07 14:02:22
Time zone: Europe/Moscow (MSK, +0300)
NTP enabled: n/a
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
Now change the timezone to UTC – you must select the TZ of your choice:
$ sudo timedatectl set-timezone UTC
Install ntpd
A simple yum install command:
$ sudo yum install ntp ntpdate ntp-doc -y
After installing ntpd, it’s a good practice to run the syncing manually:
$ sudo ntpdate
Start ntpd, and enable it on system reboots:
$ sudo systemctl start ntpd
$ sudo systemctl enable ntpd
Verify – if NTP enabled and NTP synchronized are set to ‘Yes’
[vagrant@localhost etc]$ timedatectl status
Local time: Mon 2016-11-07 14:17:11 UTC
Universal time: Mon 2016-11-07 14:17:11 UTC
RTC time: Mon 2016-11-07 14:17:09
Time zone: UTC (UTC, +0000)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a

Specify pool zones of choice  (Optional)
You can specify for ntpd the time servers i.e. pool zones. You can set the pool zones geographical closer to the datacenter you have your machines at. You can find the available pool-zones here NTP Pool Project. For example – you have your datacenter in the US, and want to set you pool zones accordingly – list of available US pool zones.
Open the ntpd conf, using any of the file editor i.e. vi or gedit:
$ sudo vi /etc/ntp.conf
Comment the current set pool zones (server iburst most probably) and add the new one:

Save and exit.
Re-start ntpd to start syncing using the new time servers:
$ sudo systemctl restart ntpd

Leave a Reply

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