Hadoop is a framework written in Java for running applications on large clusters of commodity hardware and incorporates
features similar to those of the Google File System (GFS) and of the
MapReduce computing paradigm.
Hadoop’s HDFS is a highly fault-tolerant distributed file
system and, like Hadoop in general, designed to be deployed on low-cost hardware. It provides high throughput access to
application data and is suitable for applications that have large data sets.

The main goal of this tutorial is to get a simple Hadoop installation up and running so that you can play around with
the software and learn more about it.

Prerequisites

Sun Java 6

Hadoop requires a working Java 1.5+ (aka Java 5) installation. However, using
Java 1.6 (aka Java 6) is recommended for running Hadoop. For the
sake of this tutorial, I will therefore describe the installation of Java 1.6.

Important Note: The apt instructions below are taken from this SuperUser.com thread. I got notified that the previous instructions that I provided no longer work. Please be aware that adding a third-party repository to your Ubuntu configuration is considered a security risk. If you do not want to proceed with the apt instructions below, feel free to install Sun JDK 6 via alternative means (e.g. by downloading the binary package from Oracle) and then continue with the next section in the tutorial.

Adding a dedicated Hadoop system user

We will use a dedicated Hadoop user account for running Hadoop. While that’s not required it is recommended because it
helps to separate the Hadoop installation from other software applications and user accounts running on the same
machine (think: security, permissions, backups, etc).

12

$ sudo addgroup hadoop
$ sudo adduser --ingroup hadoop hduser

This will add the user hduser and the group hadoop to your local machine.

Configuring SSH

Hadoop requires SSH access to manage its nodes, i.e. remote machines plus your local machine if you want to use Hadoop
on it (which is what we want to do in this short tutorial). For our single-node setup of Hadoop, we therefore need to
configure SSH access to localhost for the hduser user we created in the previous section.

I assume that you have SSH up and running on your machine and configured it to allow SSH public key authentication. If
not, there are several online guides available.

The second line will create an RSA key pair with an empty password. Generally, using an empty password is not
recommended, but in this case it is needed to unlock the key without your interaction (you don’t want to enter
the passphrase every time Hadoop interacts with its nodes).

Second, you have to enable SSH access to your local machine with this newly created key.

The final step is to test the SSH setup by connecting to your local machine with the hduser user. The step is
also needed to save your local machine’s host key fingerprint to the hduser user’s known_hosts file. If you
have any special SSH configuration for your local machine like a non-standard SSH port, you can define host-specific
SSH options in $HOME/.ssh/config (see man ssh_config for more information).

Enable debugging with ssh -vvv localhost and investigate the error in detail.

Check the SSH server configuration in /etc/ssh/sshd_config, in particular the options PubkeyAuthentication
(which should be set to yes) and AllowUsers (if this option is active, add the hduser user to it). If you
made any changes to the SSH server configuration file, you can force a configuration reload with
sudo /etc/init.d/ssh reload.

Disabling IPv6

One problem with IPv6 on Ubuntu is that using 0.0.0.0 for the various networking-related Hadoop configuration
options will result in Hadoop binding to the IPv6 addresses of my Ubuntu box. In my case, I realized that there’s
no practical point in enabling IPv6 on a box when you are not connected to any IPv6 network. Hence, I simply
disabled IPv6 on my Ubuntu machine. Your mileage may vary.

To disable IPv6 on Ubuntu 10.04 LTS, open /etc/sysctl.conf in the editor of your choice and add the following
lines to the end of the file:

You have to reboot your machine in order to make the changes take effect.

You can check whether IPv6 is enabled on your machine with the following command:

1

$ cat /proc/sys/net/ipv6/conf/all/disable_ipv6

A return value of 0 means IPv6 is enabled, a value of 1 means disabled (that’s what we want).

Alternative

You can also disable IPv6 only for Hadoop as documented in
HADOOP-3437. You can do so by adding the following line to
conf/hadoop-env.sh:

conf/hadoop-env.sh

1

export HADOOP_OPTS=-Djava.net.preferIPv4Stack=true

Hadoop

Installation

Download Hadoop from the
Apache Download Mirrors and extract the contents of the Hadoop
package to a location of your choice. I picked /usr/local/hadoop. Make sure to change the owner of all the
files to the hduser user and hadoop group, for example:

You can repeat this exercise also for other users who want to use Hadoop.

Excursus: Hadoop Distributed File System (HDFS)

Before we continue let us briefly learn a bit more about Hadoop’s distributed file system.

The Hadoop Distributed File System (HDFS) is a distributed file system designed to run on commodity hardware. It has many similarities with existing distributed file systems. However, the differences from other distributed file systems are significant. HDFS is highly fault-tolerant and is designed to be deployed on low-cost hardware. HDFS provides high throughput access to application data and is suitable for applications that have large data sets. HDFS relaxes a few POSIX requirements to enable streaming access to file system data. HDFS was originally built as infrastructure for the Apache Nutch web search engine project. HDFS is part of the Apache Hadoop project, which is part of the Apache Lucene project.

The following picture gives an overview of the most important HDFS components.

Configuration

Our goal in this tutorial is a single-node setup of Hadoop. More information of what we do in this section is available on the Hadoop Wiki.

hadoop-env.sh

The only required environment variable we have to configure for Hadoop in this tutorial is JAVA_HOME. Open
conf/hadoop-env.sh in the editor of your choice (if you used the installation path in this tutorial, the full path
is /usr/local/hadoop/conf/hadoop-env.sh) and set the JAVA_HOME environment variable to the Sun JDK/JRE 6
directory.

Note: If you are on a Mac with OS X 10.7 you can use the following line to set up JAVA_HOME in conf/hadoop-env.sh.

conf/hadoop-env.sh (on Mac systems)

12

# for our Mac usersexport JAVA_HOME=`/usr/libexec/java_home`

conf/*-site.xml

In this section, we will configure the directory where Hadoop will store its data files, the network ports it listens
to, etc. Our setup will use Hadoop’s Distributed File System,
HDFS, even though our little “cluster” only contains our
single local machine.

You can leave the settings below “as is” with the exception of the hadoop.tmp.dir parameter – this parameter you
must change to a directory of your choice. We will use the directory /app/hadoop/tmp in this tutorial. Hadoop’s
default configurations use hadoop.tmp.dir as the base temporary directory both for the local file system and HDFS,
so don’t be surprised if you see Hadoop creating the specified directory automatically on HDFS at some later point.

Now we create the directory and set the required ownerships and permissions:

If you forget to set the required ownerships and permissions, you will see a java.io.IOException when you try to
format the name node in the next section).

Add the following snippets between the <configuration> ... </configuration> tags in the respective configuration
XML file.

In file conf/core-site.xml:

conf/core-site.xml

123456789101112131415

<property><name>hadoop.tmp.dir</name><value>/app/hadoop/tmp</value><description>A base for other temporary directories.</description></property><property><name>fs.default.name</name><value>hdfs://localhost:54310</value><description>The name of the default file system. A URI whose
scheme and authority determine the FileSystem implementation. The
uri's scheme determines the config property (fs.SCHEME.impl) naming
the FileSystem implementation class. The uri's authority is used to
determine the host, port, etc. for a filesystem.</description></property>

In file conf/mapred-site.xml:

conf/mapred-site.xml

12345678

<property><name>mapred.job.tracker</name><value>localhost:54311</value><description>The host and port that the MapReduce job tracker runs
at. If "local", then jobs are run in-process as a single map
and reduce task.
</description></property>

In file conf/hdfs-site.xml:

conf/hdfs-site.xml

12345678

<property><name>dfs.replication</name><value>1</value><description>Default block replication.
The actual number of replications can be specified when the file is created.
The default is used if replication is not specified in create time.
</description></property>

Formatting the HDFS filesystem via the NameNode

The first step to starting up your Hadoop installation is formatting the Hadoop filesystem which is implemented on top
of the local filesystem of your “cluster” (which includes only your local machine if you followed this tutorial). You
need to do this the first time you set up a Hadoop cluster.

Do not format a running Hadoop filesystem as you will lose all the data currently in the cluster (in HDFS)!

To format the filesystem (which simply initializes the directory specified by the dfs.name.dir variable), run the
command

Running a MapReduce job

We will now run your first Hadoop MapReduce job. We will use the
WordCount example job which reads text files and counts how often words
occur. The input is text files and the output is text files, each line of which contains a word and the count of how
often it occurred, separated by a tab. More information of
what happens behind the scenes is available at the
Hadoop Wiki.

An important note about mapred.map.tasks: Hadoop does not honor mapred.map.tasks beyond considering it a hint. But it accepts the user specified mapred.reduce.tasks and doesn’t manipulate that. You cannot force mapred.map.tasks but you can specify mapred.reduce.tasks.

Retrieve the job result from HDFS

To inspect the file, you can copy it from HDFS to the local file system. Alternatively, you can use the command

Note that in this specific output the quote signs (“) enclosing the words in the head output above have not been
inserted by Hadoop. They are the result of the word tokenizer used in the WordCount example, and in this case they
matched the beginning of a quote in the ebook texts. Just inspect the part-00000 file further to see it for
yourself.

The command fs -getmerge will simply concatenate any files it finds in the directory you specify. This means that the merged file might (and most likely will) not be sorted.

Hadoop Web Interfaces

Hadoop comes with several web interfaces which are by default (see conf/hadoop-default.xml) available at these
locations:

These web interfaces provide concise information about what’s happening in your Hadoop cluster. You might want to give
them a try.

NameNode Web Interface (HDFS layer)

The name node web UI shows you a cluster summary including information about total/remaining capacity, live and dead
nodes. Additionally, it allows you to browse the HDFS namespace and view the contents of its files in the web
browser. It also gives access to the local machine’s Hadoop log files.

JobTracker Web Interface (MapReduce layer)

The JobTracker web UI provides information about general job statistics of the Hadoop cluster, running/completed/failed
jobs and a job history log file. It also gives access to the ‘‘local machine’s’’ Hadoop log files (the machine on which
the web UI is running on).

TaskTracker Web Interface (MapReduce layer)

What’s next?

If you’re feeling comfortable, you can continue your Hadoop experience with my follow-up tutorial
Running Hadoop On Ubuntu Linux (Multi-Node Cluster)
where I describe how to build a Hadoop ‘‘multi-node’’ cluster with two Ubuntu boxes (this will increase your current
cluster size by 100%, heh).

Related Links

Change Log

Only important changes to this article are listed here:

2011-07-17: Renamed the Hadoop user from hadoop to hduser based on readers’ feedback. This should make the
distinction between the local Hadoop user (now hduser), the local Hadoop group (hadoop), and the Hadoop CLI
tool (hadoop) more clear.

Comments

About Me

I am a researcher and software engineer based in Switzerland, Europe. I work for the .COM and .NET DNS registry
operator Verisign as the technical lead of its large-scale computing
infrastructure based on the Apache Hadoop stack and as a research affiliate at
Verisign Labs. Read more »