Hadoop Installation

Hadoop version 1 and 2 have different installation steps. Hadoop can be delpoyed as

  • Standalone: In this mode, there are no daemons running; everything runs as in a single JVM. This mode is suitable for running the MapReduce program during development, as it is easy to test and debug.
  • Pseudo-distributed: The Hadoop daemon process runs on a local machine simulating a cluster on a small scale.
  • Fully distributed: Here, Hadoop runs on a cluster of machines providing a production environment.

Hadoop 1 Installation

The steps involve, having required software, if not then installing them. Downloading Apache Hadoop stable release and installing as per above listed needed deployment states on Linux operating system.

Required Software – Required software for installation include:

  • JavaTM 1.6.x, preferably from Sun, must be installed.
  • ssh must be installed and sshd must be running to use the Hadoop scripts that manage remote Hadoop daemons.

Installing Software – If cluster doesn’t have the requisite software you will need to install it.

For example on Ubuntu Linux:

$ sudo apt-get install ssh

$ sudo apt-get install rsync

Download – To get a Hadoop distribution, download a recent stable release from one of the Apache Download Mirrors at – http://hadoop.apache.org/releases.html.

Prepare to Start the Hadoop Cluster – Unpack the downloaded Hadoop distribution. In the distribution, edit the file conf/hadoop-env.sh to define at least JAVA_HOME to be the root of your Java installation as

# set to the root of your Java installation

export JAVA_HOME=/usr/java/latest

Try the following command:

$ bin/hadoop

This will display the usage documentation for the hadoop script.

Add a dedicated Hadoop user account

While it is not required, it is generally recommended to create a separate user account to run the Hadoop installation. Start by adding a group by executing the following command.

sudo addgroup hadoop

Create a user (hduser) and add it to the group (hadoop) created above.

sudo adduser –ingroup hadoop hduser

You will be asked to provide the password and other information.

Configuring SSH Access

Hadoop requires SSH access to manage its nodes, i.e. remote machines and your local machine if you want to use Hadoop on it. This access allows master node to login to it’s slave nodes and to start and stop the services on them. For single node setup of Hadoop (as in this tutorial), we need to configure SSH access to localhost for the hduser user we created in the step above.

Make sure that SSH is up and running on the Linux box, and configured to allow SSH public key authentication.

  • Login as ‘hduser’.
  • Generate SSH key for user hduser, by executing the command – ssh-keygen -t rsa -P “”
  • You will be asked the location where you would like to save the key file. Just click <Enter> to go with the default. The RSA key will be generated at ‘/home/hduser/.ssh’. This key generated with an empty password. Generally, it is not a good practice to have empty passwords, but in this case we need that there should not be any manual intervention when Hadoop is interacting with its nodes.
  • Enable SSH Access to your local machine with this newly created key, by executing the following command – cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
  • Last step is to test the ssh setup by connecting your local machine with the hduser user. This will add your machine’s host key fingerprint to the hduser user’s known_hosts file – ssh hduser@localhost

Now install Hadoop cluster in one of the three supported modes – Local (Standalone) Mode, Pseudo-Distributed Mode and Fully-Distributed Mode

Standalone Operation

By default, Hadoop is configured to run in a non-distributed mode, as a single Java process. This is useful for debugging.

The following example copies the unpacked conf directory to use as input and then finds and displays every match of the given regular expression. Output is written to the given output directory.

$ mkdir input

$ cp conf/*.xml input

$ bin/hadoop jar hadoop-examples-*.jar grep input output ‘dfs[a-z.]+’

$ cat output/*

Pseudo-Distributed Operation

Hadoop can also be run on a single-node in a pseudo-distributed mode where each Hadoop daemon runs in a separate Java process.

Configuration

Use the following:

conf/core-site.xml:

<configuration>

<property>

<name>fs.default.name</name>

<value>hdfs://localhost:9000</value>

</property>

</configuration>

conf/hdfs-site.xml:

<configuration>

<property>

<name>dfs.replication</name>

<value>1</value>

</property>

</configuration>

conf/mapred-site.xml:

<configuration>

<property>

<name>mapred.job.tracker</name>

<value>localhost:9001</value>

</property>

</configuration>

Setup passphraseless ssh

Now check that you can ssh to the localhost without a passphrase:

$ ssh localhost

If you cannot ssh to localhost without a passphrase, execute the following commands:

$ ssh-keygen -t dsa -P ” -f ~/.ssh/id_dsa

$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

Execution

Format a new distributed-filesystem:

$ bin/hadoop namenode -format

Start the hadoop daemons:

$ bin/start-all.sh

The hadoop daemon log output is written to the ${HADOOP_LOG_DIR} directory (defaults to ${HADOOP_HOME}/logs).

Browse the web interface for the NameNode and the JobTracker; by default they are available at:

NameNode – http://localhost:50070/

JobTracker – http://localhost:50030/

Copy the input files into the distributed filesystem:

$ bin/hadoop fs -put conf input

Run some of the examples provided:

$ bin/hadoop jar hadoop-examples-*.jar grep input output ‘dfs[a-z.]+’

Examine the output files:

Copy the output files from the distributed filesystem to the local filesytem and examine them:

$ bin/hadoop fs -get output output

$ cat output/*

or

View the output files on the distributed filesystem:

$ bin/hadoop fs -cat output/*

When you’re done, stop the daemons with:

$ bin/stop-all.sh

Fully-Distributed Operation

It will be covered in the cluster setup, chapter.

Hadoop 2 Installation

Hadoop 2 installation follows same steps as listed earlier, changes are present in YARN installation and pseudo-distributed operation’s configuration, are listed

Pseudo-Distributed Operation

Hadoop can also be run on a single-node in a pseudo-distributed mode where each Hadoop daemon runs in a separate Java process.

Configuration

Use the following:

etc/hadoop/core-site.xml:

<configuration>

<property>

<name>fs.defaultFS</name>

<value>hdfs://localhost:9000</value>

</property>

</configuration>

etc/hadoop/hdfs-site.xml:

<configuration>

<property>

<name>dfs.replication</name>

<value>1</value>

</property>

</configuration>

Setup passphraseless ssh

Now check that you can ssh to the localhost without a passphrase:

$ ssh localhost

If you cannot ssh to localhost without a passphrase, execute the following commands:

$ ssh-keygen -t dsa -P ” -f ~/.ssh/id_dsa

$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

$ export HADOOP\_PREFIX=/usr/local/hadoop

Execution

The following instructions are to run a MapReduce job locally.

Format the filesystem:

$ bin/hdfs namenode -format

Start NameNode daemon and DataNode daemon:

$ sbin/start-dfs.sh

The hadoop daemon log output is written to the $HADOOP_LOG_DIR directory (defaults to $HADOOP_HOME/logs).

Browse the web interface for the NameNode; by default it is available at:

NameNode – http://localhost:50070/

Make the HDFS directories required to execute MapReduce jobs:

$ bin/hdfs dfs -mkdir /user

$ bin/hdfs dfs -mkdir /user/<username>

Copy the input files into the distributed filesystem:

$ bin/hdfs dfs -put etc/hadoop input

Run some of the examples provided:

$ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.1.jar grep input output ‘dfs[a-z.]+’

Examine the output files: Copy the output files from the distributed filesystem to the local filesystem and examine them:

$ bin/hdfs dfs -get output output

$ cat output/*

or

View the output files on the distributed filesystem:

$ bin/hdfs dfs -cat output/*

When you’re done, stop the daemons with:

$ sbin/stop-dfs.sh

YARN on a Single Node

You can run a MapReduce job on YARN in a pseudo-distributed mode by setting a few parameters and running ResourceManager daemon and NodeManager daemon in addition.

The following instructions assume that 1 to 4. steps of the above instructions are already executed.

Configure parameters as follows:etc/hadoop/mapred-site.xml:

<configuration>

<property>

<name>mapreduce.framework.name</name>

<value>yarn</value>

</property>

</configuration>

etc/hadoop/yarn-site.xml:

<configuration>

<property>

<name>yarn.nodemanager.aux-services</name>

<value>mapreduce_shuffle</value>

</property>

</configuration>

Start ResourceManager daemon and NodeManager daemon:

$ sbin/start-yarn.sh

Browse the web interface for the ResourceManager; by default it is available at:

ResourceManager – http://localhost:8088/

Run a MapReduce job.

When you’re done, stop the daemons with:

$ sbin/stop-yarn.sh

Setup Configuration

Edit hadoop-env.sh:

Edit configuration file conf/hadoop-env.sh and set JAVA_HOME

export JAVA_HOME=path to be the root of your Java installation(eg: /usr/lib/jvm/java-6-sun)

Edit core-site.xml:

Edit configuration file conf/core-site.xml and add following entries:

<configuration>

<property>

<name>fs.default.name</name> <value>hdfs://localhost:9000</value>

</property>

<property>

<name>hadoop.tmp.dir</name>

<value><PATH-WHERE-YOU-HAVE-READ-WRITE-PRIVILEGES></value>

</property>

</configuration>

Edit hdfs-site.xml:

Edit configuration file conf/hdfs-site.xml and add following entries:

<configuration>

<property>

<name>dfs.replication</name>

<value>1</value>

</property>

</configuration>

Edit mapred-site.xml:

Edit configuration file conf/mapred-site.xml and add following entries:

<configuration>

<property>

<name>mapred.job.tracker</name>

<value>localhost:9001</value>

</property>

</configuration>

Hardware Recommendations
HDFS Basics (Blocks, Namenodes and Datanodes)

Get industry recognized certification – Contact us

keyboard_arrow_up
Open chat
Need help?
Hello 👋
Can we help you?