How to set up a custom Hadoop single node cluster in the pseudo-distributed mode

In this article, we’ll explore how to set up a custom Hadoop single node cluster in the pseudo-distributed mode.

Apache Hadoop provides a software framework for distributed storage and processing of big data using the MapReduce programming model. The core of Apache Hadoop consists of a storage part, known as Hadoop Distributed File System (HDFS), and a processing part which is a MapReduce programming model. Hadoop splits files into large blocks and distributes them across nodes in a cluster. It then transfers packaged code into nodes to process the data in parallel. This approach takes advantage of data locality, where nodes manipulate the data they have access to. This allows the dataset to be processed faster and more efficiently. Hadoop can be installed in 3 different modes: Standalone mode, Pseudo-Distributed mode, and Fully-Distributed mode.

Standalone mode is the default mode in which Hadoop runs. Standalone mode is mainly used for debugging where you don’t really use HDFS.

This draft helps you create your own custom Hadoop pseudo mode cluster. The environment used in this setup is ubuntu 18.04 and the Hadoop version is 3.1.2.

Prerequisites

Create A New User [optional]

Note: Follow this step if you want to install hadoop for a new user else skip to next part.

sudo addgroup hadoop
sudo adduser --ingroup hadoop hdfsuser

Note:

 If you want to add an existing user to the group then use the following command
usermod -a -G hadoop username
sudo visudo
hdfsuser ALL=(ALL:ALL) ALL
su - hdfsuser

Java installation

java -version
sudo apt-get update
sudo apt install openjdk-8-jre-headless openjdk-8-jdk
java -version

Setting up SSH keys

sudo apt-get install ssh
sudo apt-get install sshd

Generating Keys …

ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod og-wx ~/.ssh/authorized_keys
ssh localhost

Note: If it doesn’t ask for a password and logs you in, then the configuration was successful, else remove the generated key and follow the steps again.

Hadoop 3.x Installation

cd /usr/local
sudo wget http://archive.apache.org/dist/hadoop/common/hadoop-3.1.2/hadoop-3.1.2.tar.gz
sudo tar xvzf hadoop-3.1.2.tar.gz
sudo mv hadoop-3.1.2 hadoop

Setup Hadoop in Pseudo-Distributed Mode

sudo chown -R hdfsuser:hadoop /usr/local/hadoop
sudo chmod -R 777 /usr/local/hadoop

Disable IPv6

cat /proc/sys/net/ipv6/conf/all/disable_ipv6
sudo nano /etc/sysctl.conf
# Disable ipv6
net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default_ipv6=1
net.ipv6.conf.lo.disable_ipv6=1

Save the file and exit

If ipv6 is still not disabled, then the problem will be /etc/sysctl.conf not being activated. To solve this, activate the conf by running

sudo sysctl -p

Adding Hadoop Environment Variables

sudo nano ~/.bashrc
# HADOOP ENVIRONMENT
export HADOOP_HOME=/usr/local/hadoop
export HADOOP_CONF_DIR=/usr/local/hadoop/etc/hadoop
export HADOOP_MAPRED_HOME=/usr/local/hadoop
export HADOOP_COMMON_HOME=/usr/local/hadoop
export HADOOP_HDFS_HOME=/usr/local/hadoop
export YARN_HOME=/usr/local/hadoop
export PATH=$PATH:/usr/local/hadoop/bin
export PATH=$PATH:/usr/local/hadoop/sbin

# HADOOP NATIVE PATH
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export HADOOP_OPTS=-Djava.library.path=$HADOOP_PREFIX/lib
source ~/.bashrc

Configuring Hadoop …

cd /usr/local/hadoop/etc/hadoop/
sudo nano hadoop-env.sh
export HADOOP_OPTS=-Djava.net.preferIPv4Stack=true
export JAVA_HOME=/usr
export HADOOP_HOME_WARN_SUPPRESS="TRUE"
export HADOOP_ROOT_LOGGER="WARN,DRFA"
export HDFS_NAMENODE_USER="hdfsuser"
export HDFS_DATANODE_USER="hdfsuser"
export HDFS_SECONDARYNAMENODE_USER="hdfsuser"
export YARN_RESOURCEMANAGER_USER="hdfsuser"
export YARN_NODEMANAGER_USER="hdfsuser"
sudo nano yarn-site.xml
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
sudo nano hdfs-site.xml
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>/usr/local/hadoop/yarn_data/hdfs/namenode</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/usr/local/hadoop/yarn_data/hdfs/datanode</value>
</property>
<property>
<name>dfs.namenode.http-address</name>
<value>localhost:50070</value>
</property>
sudo nano core-site.xml
<property>
<name>hadoop.tmp.dir</name>
<value>/bigdata/hadoop/tmp</value>
</property>
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:9000</value>
</property>
sudo nano mapred-site.xml
<property>
<name>mapred.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>localhost:10020</value>
</property>

Creating directories

sudo mkdir -p /bigdata/hadoop/tmp
sudo chown -R hdfsuser:hadoop /bigdata/hadoop/tmp
sudo chmod -R 777 /bigdata/hadoop/tmp

Note: If you don’t want to change ownership, skip the chown command. Remember this in further steps also.

sudo mkdir -p /usr/local/hadoop/yarn_data/hdfs/namenode
sudo mkdir -p /usr/local/hadoop/yarn_data/hdfs/datanode
sudo chmod -R 777 /usr/local/hadoop/yarn_data/hdfs/namenode
sudo chmod -R 777 /usr/local/hadoop/yarn_data/hdfs/datanode
sudo chown -R hdfsuser:hadoop /usr/local/hadoop/yarn_data/hdfs/namenode
sudo chown -R hdfsuser:hadoop /usr/local/hadoop/yarn_data/hdfs/datanode

Finishing up

hdfs namenode -format
start-dfs.sh
start-yarn.sh

Note: 

You can also use 

start-all.sh

 to start all the services
http://localhost:50070

To access ResourceManager, navigate to the ResourceManager web UI at

http://localhost:8088

To check if HDFS is running, you can use the Java Process Status tool.

jps
ResourceManager
DataNode
SecondaryNameNode
NodeManager
NameNode
stop-dfs.sh
stop-yarn.sh
stop-all.sh
I hope we all agree that our future will be highly data-driven. In today’s connected and digitally transformed the world, data collected from several sources can help an organization to foresee its future and make informed decisions to perform better. Here is an interesting article to learn more about Big Data and Big Data Ingestion

Written by

Adarsh M S

Technology enthusiast with an urge to explore into vast areas of advancing technologies. Experienced in domains like Computer Vision, Natural Language Processing, Big data. Believes in open source contributions and loves to provide support to the community. Actively involved in building open source tools related to information retrieval.

More from Adarsh M S →