Hadoop Installation Guide

Requirements

Before installing Hadoop, ensure your system meets the basic hardware and software requirements. Hadoop clusters can consist of multiple computers or run in pseudo-distributed mode. Different deployment modes have different hardware requirements, but core software dependencies are similar. Understanding these requirements helps plan Hadoop cluster scale and configuration, avoiding unnecessary issues during installation.

For hardware, small test clusters should have at least 4 CPU cores, 8GB RAM, and 500GB hard disk per machine. For production environments, each machine should have 8 or more CPU cores, 16GB or more RAM, and 1TB or larger hard disk. DataNodes store large amounts of data, so disk capacity is especially important. Hadoop recommends RAID configuration or JBOD (Just a Bunch Of Disks) configuration—the latter allows Hadoop to manage disk space more flexibly.

For operating systems, Hadoop supports Linux (Ubuntu, CentOS, Debian, Red Hat, etc.) and Windows (via Cygwin or Windows Subsystem for Linux). Production environments strongly recommend Linux for best performance and stability. Hadoop also integrates well with various cloud platforms and can be deployed on AWS, Azure, Google Cloud, and other cloud services.

Java is Hadoop's only runtime dependency. Hadoop 3.x requires Java 8 or higher. Oracle JDK or OpenJDK is recommended. Ensure Java is properly installed and the JAVA_HOME environment variable is set before installing Hadoop. Verify Java installation with:

java -version
echo $JAVA_HOME

Networking is fundamental for Hadoop cluster operation. All nodes in the cluster should be able to communicate with each other over the network, preferably using high-speed networks (such as Gigabit Ethernet). Nodes need SSH passwordless login configured so Hadoop can distribute tasks and transfer data between nodes. Additionally, configure hostname and IP address mappings for all nodes in /etc/hosts.

Installation Steps

Standalone Mode Installation

Standalone mode is the simplest Hadoop installation method, with all components running in the same JVM process. This mode is primarily used for development and testing and does not involve distributed storage or computing. First, download Hadoop's binary distribution from the official Apache Hadoop website:

# Download Hadoop (replace with latest version)
wget https://dlcdn.apache.org/hadoop/common/hadoop-3.3.6/hadoop-3.3.6.tar.gz

# Extract to specified directory
tar -xzf hadoop-3.3.6.tar.gz -C /usr/local/

# Rename directory (optional)
mv /usr/local/hadoop-3.3.6 /usr/local/hadoop

Next, configure environment variables. Edit ~/.bashrc or /etc/profile and add the following:

export HADOOP_HOME=/usr/local/hadoop
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64  # Adjust based on actual Java path

Apply the configuration:

source ~/.bashrc

Verify installation:

hadoop version

Pseudo-Distributed Mode Installation

Pseudo-distributed mode simulates a distributed environment on a single machine, with NameNode, DataNode, ResourceManager, and NodeManager all running on the same machine. This mode is suitable for developing and testing distributed functionality.

First, configure Hadoop's core files. Navigate to the Hadoop configuration directory:

cd $HADOOP_HOME/etc/hadoop

Configure core-site.xml, specifying HDFS as the default file system:

<configuration>
    <property>
        <name>fs.defaultFS</name>
        <value>hdfs://localhost:9000</value>
    </property>
    <property>
        <name>hadoop.tmp.dir</name>
        <value>/usr/local/hadoop/tmp</value>
    </property>
</configuration>

Configure hdfs-site.xml, specifying HDFS replication factor (1 for pseudo-distributed):

<configuration>
    <property>
        <name>dfs.replication</name>
        <value>1</value>
    </property>
    <property>
        <name>dfs.namenode.name.dir</name>
        <value>file:///usr/local/hadoop/data/namenode</value>
    </property>
    <property>
        <name>dfs.datanode.data.dir</name>
        <value>file:///usr/local/hadoop/data/datanode</value>
    </property>
</configuration>

Configure mapred-site.xml, specifying the resource scheduling framework for MapReduce:

<configuration>
    <property>
        <name>mapreduce.framework.name</name>
        <value>yarn</value>
    </property>
    <property>
        <name>mapreduce.application.classpath</name>
        <value>$HADOOP_MAPRED_CLASSPATH</value>
    </property>
</configuration>

Configure yarn-site.xml, configuring YARN-related properties:

<configuration>
    <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>
</configuration>

SSH Passwordless Login Configuration

Nodes in the Hadoop cluster need SSH passwordless login configured so the master node can access slave nodes without passwords:

# Generate SSH key pair
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa

# Add public key to authorized_keys
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

# Set correct permissions
chmod 0600 ~/.ssh/authorized_keys

# Test SSH login
ssh localhost

For multi-node clusters, copy the public key to all nodes:

ssh-copy-id user@slave1
ssh-copy-id user@slave2

Format and Start HDFS

Before using HDFS for the first time, format the NameNode:

hdfs namenode -format

Start HDFS and YARN:

start-dfs.sh
start-yarn.sh

Or use start-all.sh to start all services at once:

start-all.sh

Verify service startup:

# View Java processes
jps

# Expected processes:
# NameNode
# DataNode
# SecondaryNameNode
# ResourceManager
# NodeManager

Access Hadoop services via Web UI: NameNode Web UI at http://localhost:9870, ResourceManager Web UI at http://localhost:8088.

Fully Distributed Cluster Installation

Cluster Planning

Fully distributed mode requires multiple physical or virtual machines to form a cluster. Before installation, perform reasonable cluster planning. Determine cluster scale (number of nodes) and assign roles to each node (NameNode, Secondary NameNode, DataNode, ResourceManager, NodeManager). For small clusters, NameNode and ResourceManager can be deployed on the same machine; for large clusters, separate deployment is recommended for better performance.

Network planning is also important. All nodes should be on the same internal network with low latency and high bandwidth. Configure hostnames and IP addresses for all nodes in /etc/hosts:

192.168.1.1 master
192.168.1.2 slave1
192.168.1.3 slave2
192.168.1.4 slave3

Configuration File Modifications

In fully distributed mode, more configuration files need modification. First configure the workers file (slaves file in earlier versions), listing all DataNode and NodeManager nodes:

slave1
slave2
slave3

Configuration of core-site.xml and hdfs-site.xml is similar to pseudo-distributed mode, but more properties need to be added. For NameNode HA configuration, configure two NameNodes:

<configuration>
    <property>
        <name>fs.defaultFS</name>
        <value>hdfs://mycluster</value>
    </property>
    <property>
        <name>hadoop.tmp.dir</name>
        <value>/usr/local/hadoop/tmp</value>
    </property>
</configuration>

Configure hdfs-site.xml for NameNode HA:

<configuration>
    <property>
        <name>dfs.nameservices</name>
        <value>mycluster</value>
    </property>
    <property>
        <name>dfs.ha.namenodes.mycluster</name>
        <value>nn1,nn2</value>
    </property>
    <property>
        <name>dfs.namenode.http-address.mycluster.nn1</name>
        <value>master:9870</value>
    </property>
    <property>
        <name>dfs.namenode.http-address.mycluster.nn2</name>
        <value>slave1:9870</value>
    </property>
    <property>
        <name>dfs.namenode.shared.edits.dir</name>
        <value>qjournal://master:8485;slave1:8485/mycluster</value>
    </property>
    <property>
        <name>dfs.client.failover.proxy.provider.mycluster</name>
        <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
    </property>
</configuration>

YARN configuration is similar; configure ResourceManager HA in yarn-site.xml.

Synchronize Configuration Files

Synchronize the configured Hadoop installation directory to all nodes. Copy individually using scp:

scp -r /usr/local/hadoop user@slave1:/usr/local/
scp -r /usr/local/hadoop user@slave2:/usr/local/
scp -r /usr/local/hadoop user@slave3:/usr/local/

Or use rsync for distributed replication:

rsync -avz /usr/local/hadoop slave1:/usr/local/
rsync -avz /usr/local/hadoop slave2:/usr/local/
rsync -avz /usr/local/hadoop slave3:/usr/local/

Start the Cluster

Format the NameNode on the NameNode node (first start):

hdfs namenode -format

Start HDFS:

start-dfs.sh

Start YARN:

start-yarn.sh

Check process status on all nodes to ensure services are running properly:

# On NameNode
jps

# On DataNode
jps

Verification and Testing

HDFS Testing

Create directories and upload files to test HDFS:

# Create directory
hdfs dfs -mkdir -p /user/test

# Upload local file to HDFS
hdfs dfs -put localfile.txt /user/test/

# List files
hdfs dfs -ls /user/test

# Read file
hdfs dfs -cat /user/test/localfile.txt

# Delete file
hdfs dfs -rm /user/test/localfile.txt

MapReduce Testing

Run MapReduce example programs to verify cluster functionality:

# Run WordCount example
hadoop jar $HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduce-examples-3.3.6.jar wordcount /input /output

# View results
hdfs dfs -cat /output/part-r-00000

Cluster Health Check

Use Hadoop's built-in commands to check cluster status:

# View HDFS status
hdfs dfsadmin -report

# View YARN node status
yarn node -list -all

# View application status
yarn application -list

Common Issues

Java Version Incompatibility

If you encounter Java version-related errors, ensure the installed Java version is compatible with the Hadoop version. Hadoop 3.x requires Java 8 or higher. Switch Java version with:

update-alternatives --config java

Insufficient Disk Space

DataNodes may fail to work properly due to insufficient disk space. Regularly monitor disk usage to ensure DataNodes have sufficient available space. Configure dfs.datanode.fsdataset.volume.choosing.policy in hdfs-site.xml as AvailableSpaceVolumeChoosingPolicy to let DataNodes prefer disks with more available space.

Insufficient Memory

If cluster nodes have insufficient memory, YARN may fail to start containers. Adjust memory configuration in yarn-site.xml:

<property>
    <name>yarn.nodemanager.resource.memory-mb</name>
    <value>16384</value>
</property>
<property>
    <name>yarn.scheduler.minimum-allocation-mb</name>
    <value>1024</value>
</property>