Configuration of Hadoop Cluster Using Ansible
Tags: bigdata, ansible, aws, arth
Published: 2021-03-27 02:42:28

Hello Readers,

After reading this article you will able to configure Hadoop Cluster using Ansible.

Before starting Let me tell you a little bit about Hadoop and Ansible.
#What Is Hadoop?
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8msmcxi269ch972vf62j.png)
Hadoop is an open-source, Java-based programming framework that supports the storage and processing of extremely large data sets in a distributed computing environment. It is part of the Apache project sponsored by the Apache Software Foundation.
Some Basic Terminology:

Namenode: Also called the master node is the main component of the Hadoop Cluster. It stores the metadata about block locations etc. This metadata is useful for file read and write operations.

Datanode: Also known as the Slave node, is someone who shares their own components with the master node. It is the final location for storing the files. There can be many data-nodes in one cluster.

#What Is Ansible? 
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e4et1tg5t1o4dov9w8nc.png)
Ansible is open-source software that automates software provisioning, configuration management, and application deployment. To more about Ansible You can Read my other Article on “Ansible In Action”. I am providing its link below.
Link: https://dev.to/piyushbagani15/ansible-in-action-how-aws-is-solving-challenges-using-ansible-oll

#Some Basic Terminology:

Controller Node: Machine where Ansible is installed.

Managed Node: The network devices (and/or servers) you manage with Ansible.

That’s All. Now Let’s stick to our main Objective.

The task that we are going to perform in this blog are:
🎇Configure Namenode (Master).
🎇Format the Namenode.
🎇Configure the Datanode (Slave).
🎇Check the connection between Datanode and Namenode.

Here I am going to launch 3 instances on AWS cloud. First will act as Controller Node, Second for Namenode and the last one is Datanode. Here Namenode and Datanode are acting as Managed Nodes.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fowb2jbxh065qco9k8r4.png)
Firstly, In the controller node, We need to install Ansible. Before this Install Python using the yum install python3 Command.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0dow2n7arm12eanyswxb.png)
Now We will setup the configuration file of Ansible by making a directory using mkdir /etc/ansible/ command. We need to write some code inside the configuration file of ansible.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ghs0ad563ghjeq1xqaub.png)
To avoid some warnings given by the command we have to disable it, using command_warnings=false

The remote user is that we are going to log in, here we have launched the ec2 instances hence the remote username is ec2-user

Also, we need to disable the ssh key, as when we do ssh it asks you for yes or no. We have to write host_key_checking=false to disable it.

Ansible uses existing privilege escalation systems to execute tasks with root privileges or with another user’s permissions. Because this feature allows you to ‘become’ another user, different from the user that logged into the machine (remote user), we call it to become. The become keyword leverages existing privilege escalation tools like sudo, su, pfexec, doas, pbrun, dzdo, ksu, runas, machinectl, and others.

To login in to that newly launched OS, we need to provide its respective key. Here .pem format will work. We need to give permission to that key in the read mode. Command for that:-

chmod 400 keyname.pem

After setting up the configuration file, the next step is to create inventory. To create an Inventory create a text file and inside the text file provide managed node IP address, username, password, and connection type as shown.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q1lgcue141rhdwz8fjxw.png)
Note: In this Inventory, we have given the .pem file for password as we are doing this practical/task on AWS cloud. If we want we can do it in Local VM(s). The changes we need to do are simple and as follows:
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pnhcdu4vfperi9o1k052.png)
Now, check the connectivity with Managed Node using the command ansible all -m ping.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rmw7nvojsxdr7txsxj0e.png)
Now Start writing the playbook for configuring the Namenode. Also, It is good that we know how to setup a cluster manually as it provides the steps, and hence writing the playbook will be very much easy.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aekwy5b0vyn16i2wfsh2.png)
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/queyi0c7mq2lsuyfvx41.png)
Now just the playbook using the command ansible-playbook namenode.yml If no error comes then you will see that Namenode is configured and the service is running perfectly.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/36h9g1m9h570r8vwn0m2.png)
Here We can see all the tasks are performing great. Also, I have shown the content I wrote in the hdfs-site.xml and core-site.xml file as they are very much important.

Atlast by running the “ jps ” command manually we can also check the service is running or not.

Now let us write the playbook for Datanode. Again to the steps to configure it manually would be helpful. By chance I have attached the images which show how it executes afterward. Don’t worry about the code, I will provide my GitHub repo link at the end where you will find the entire code.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h6nrvrrzgq67t7dhhs1p.png)
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xhubv7gjagund3xemhr1.png)
Hence, here the execution of the datanode1.yml completes and the final result can be seen in the below-attached image.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dft7yq9hs08l4hnb9sw7.png)
Finally, we have configured Namenode and Datanode using Ansible.

Let’s Check the report of the cluster we configured.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/autm5axg2amaopff4c2u.png)
Here we can see that here Number of Datanodes is 1 and it is contributing its storage to the cluster.

We can Verify it from Hadoop WebUI.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pet6571x431xcivvyueg.png)
So that’s how we can set up the Hadoop cluster using Ansible.

#Thank you!!!🎇🎇

#Keep Learning, Keep Hustling🎇 

GitHub Repo:https://github.com/PiyushBagani15/Ansible_Hadoop_Integration