Ansible to setup chronyd (ntp) service

Chrony is a service for keeping your servers time in sync, similar to NTPd, see https://chrony.tuxfamily.org/ for more.

– Chrony provides another implementation of NTP.
– Chrony is designed for systems that are often powered down or disconnected from the network.
– The main configuration file is /etc/chrony.conf.
– Parameters are similar to those in the /etc/ntp.conf file.
– chronyd is the daemon that runs in user space.
– chronyc is a command-line program that provides a command prompt and a number of commands. Examples:
tracking: Displays system time information
sources: Displays information about current sources.

source of above: https://www.thegeekdiary.com/centos-rhel-7-configuring-ntp-using-chrony/

Steps to deploy chronyd on the 1+3 node cluster with CentOS7 as operating system on each node:

  1. Our cluster has 1+3 nodes, named master, slave1, slave2, slave3 with following DHCP assigned IPs.

slave1: 10.xx.0.xx

slave2: 10.xx.0.xx

slave3: 10.xx.0.xx

2. On master node (controller node – where ansible is installed), install ansible and configure chronyd with below conf file configuration. (ansible installation steps source : https://unixcop.com/ansible-installation-configuration-on-centos-7-8/)

In master Under /etc

#start of chronyd.conf : source – https://www.ibm.com/docs/en/db2/11.5?topic=servers-setting-up-network-time-protocol

server 127.xxx.x.x # This is the IP of our Lab NTP server

driftfile /var/lib/chrony/drift

local stratum 10

allow all

#end of chronyd.conf

In slave nodes under /etc

#start of chronyd.conf-slaves

rtcsync

server <master node IP 10.xx.0.xx> iburst prefer

driftfile /var/lib/chrony/drift

logdir /var/log/chrony

#end of chronyd.conf-slaves

3. make copy of abovechronyd.conf-slaves file as /home/chrony.conf.j2 or under any path where ansible playbook is run.

4. ansible configuration of yml for chronyd is created as below :

“chrony-config.yml”: source – https://www.redhat.com/sysadmin/ansible-chrony-daemon

chrony-config.yml file

Under /home, execute below command:

“ansible-playbook chrony-config.yml”

output:

chronyd-config.yml ansible execution

Now manually sync the time on each node including master as shown below:

timedatectl set-time “2021-11-17 11:53:59” –> my current time IST – run this command on master and slave nodes simultaneously (I used moba-xterm multi execution mode for this).

Multi-Execution in Mobaxterm

Above command is used to set the time manually from the approximate LOCAL time got from the wall clock, your phone, the Internet etc

Now restart the chronyd service on all nodes inclusing master

Once above is completed verified chronyd status as shown below:

Hence you can see using ansible chronyd configuration and few commands we have time synced across the cluster nodes. The time is set to 2021-11-17 13:18:38 IST on all nodes including the master node.

So now i can proceed with spark cluster configuration on this cluster!! Once i am done with it, i will post the link to the same.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s