Steps To Setup Hadoop 2.4.0 (Single Node Cluster) on CentOS/RHEL

Apache Hadoop 2.4.0 significant improvements over the previous stable releases. This version has many improvements in HDFS and MapReduce. This how to guide will help you to install Hadoop 2.4.0 on CentOS 6.5 System. This article doesn’t includes overall configuration of hadoop, we have only basic configuration required to start working with hadoop.

hadoop-st

Step 1. Install JAVA/JDK

Java is the primary requirement for running hadoop on any system, So make sure you have java installed on your system using following command.

# java -version 

java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) Client VM (build 25.5-b02, mixed mode)

If you don’t have java installed on your system, use one of following link to install it first.

Install JAVA/JDK 8 on CentOS and RHEL 6/5

Step 2. Setup Hadoop User

We recommend to create a normal (nor root) account for hadoop working. So create a system account using following command.

# useradd hadoop
# passwd hadoop

After creating account, it also required to set up key based ssh to its own account. To do this use execute following commands.

# su - hadoop
$ ssh-keygen -t rsa
$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
$ chmod 0600 ~/.ssh/authorized_keys

Lets verify key based login. Below command should not ask for password but first time it will prompt for adding RSA to the list of known hosts.

$ ssh localhost
$ exit

Step 3. Download Hadoop 2.4.0

Now download hadoop 2.4.0 source archive file using below command. You can also select alternate download mirror for increasing download speed.

$ cd ~
$ wget http://apache.claz.org/hadoop/common/hadoop-2.4.0/hadoop-2.4.0.tar.gz
$ tar xzf hadoop-2.4.0.tar.gz

Step 4. Configure Hadoop 2.4.0

4.1. Setup Environment Variables

First we need to set environment variable uses by hadoop. Edit ~/.bashrc file and append following values at end of file.

export HADOOP_HOME=/home/hadoop/hadoop
export HADOOP_INSTALL=$HADOOP_HOME
export HADOOP_MAPRED_HOME=$HADOOP_HOME
export HADOOP_COMMON_HOME=$HADOOP_HOME
export HADOOP_HDFS_HOME=$HADOOP_HOME
export YARN_HOME=$HADOOP_HOME
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export PATH=$PATH:$HADOOP_HOME/sbin:$HADOOP_HOME/bin

Now apply the changes in current running environment

$ source ~/.bashrc

Now edit $HADOOP_HOME/etc/hadoop/hadoop-env.sh file and set JAVA_HOME environment variable

export JAVA_HOME=/opt/jdk1.8.0_05/

4.2. Edit Configuration Files

Hadoop has many of configuration files, which need to configure as per requirements of your hadoop infrastructure. Lets start with the configuration with basic hadoop single node cluster setup. first navigate to below location

$ cd $HADOOP_HOME/etc/hadoop

Edit core-site.xml

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

Edit hdfs-site.xml

<configuration>
<property>
 <name>dfs.replication</name>
 <value>1</value>
</property>

<property>
  <name>dfs.name.dir</name>
    <value>file:///home/hadoop/hadoopdata/hdfs/namenode</value>
</property>

<property>
  <name>dfs.data.dir</name>
    <value>file:///home/hadoop/hadoopdata/hdfs/datanode</value>
</property>
</configuration>

Edit mapred-site.xml

<configuration>
 <property>
  <name>mapreduce.framework.name</name>
   <value>yarn</value>
 </property>
</configuration>

Edit yarn-site.xml

<configuration>
 <property>
  <name>yarn.nodemanager.aux-services</name>
    <value>mapreduce_shuffle</value>
 </property>
</configuration>

4.3. Format Namenode

Now format the namenode using following command, make sure that Storage directory is

$ hdfs namenode -format

[Sample output]

14/05/04 21:30:55 INFO namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG:   host = svr1.tecadmin.net/192.168.1.11
STARTUP_MSG:   args = [-format]
STARTUP_MSG:   version = 2.4.0
...
...
14/05/04 21:30:56 INFO common.Storage: Storage directory /home/hadoop/hadoopdata/hdfs/namenode has been successfully formatted.
14/05/04 21:30:56 INFO namenode.NNStorageRetentionManager: Going to retain 1 images with txid >= 0
14/05/04 21:30:56 INFO util.ExitUtil: Exiting with status 0
14/05/04 21:30:56 INFO namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at svr1.tecadmin.net/192.168.1.11
************************************************************/

Step 5. Start Hadoop Cluster

Lets start your hadoop cluster using the scripts provides by hadoop. Just navigate to your hadoop sbin directory and execute scripts one by one.

$ cd $HADOOP_HOME/sbin/

Now run start-dfs.sh script.

$ start-dfs.sh

[Sample output]
14/05/04 21:37:56 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Starting namenodes on [localhost]
localhost: starting namenode, logging to /home/hadoop/hadoop/logs/hadoop-hadoop-namenode-svr1.tecadmin.net.out
localhost: starting datanode, logging to /home/hadoop/hadoop/logs/hadoop-hadoop-datanode-svr1.tecadmin.net.out
Starting secondary namenodes [0.0.0.0]
0.0.0.0: starting secondarynamenode, logging to /home/hadoop/hadoop/logs/hadoop-hadoop-secondarynamenode-svr1.tecadmin.net.out
14/05/04 21:38:16 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable

Now run start-yarn.sh script.

$ start-yarn.sh

[Sample output]
starting yarn daemons
starting resourcemanager, logging to /home/hadoop/hadoop/logs/yarn-hadoop-resourcemanager-svr1.tecadmin.net.out
localhost: starting nodemanager, logging to /home/hadoop/hadoop/logs/yarn-hadoop-nodemanager-svr1.tecadmin.net.out

Step 6. Access Hadoop Services in Browser

Hadoop NameNode started on port 50070 default. Access your server on port 50070 in your favorite web browser.


http://svr1.tecadmin.net:50070/

hadoop-2.4.0-dfs

Now access port 8088 for getting the information about cluster and all applications


http://svr1.tecadmin.net:8088/

hadoop-2.4.0-cluster

Access port 50090 for getting details about secondary namenode.


http://svr1.tecadmin.net:50090/

hadoop-2.4.0-namenode

Access port 50075 to get details about DataNode


http://svr1.tecadmin.net:50075/

hadoop-2.4.0-datanode

Step 7. Test Hadoop Setup

7.1 - Make the HDFS directories required using following commands.

$ bin/hdfs dfs -mkdir /user
$ bin/hdfs dfs -mkdir /user/hadoop

7.2 - Now copy all files from local file system /var/log/httpd to hadoop distributed file system using below command

$ bin/hdfs dfs -put /var/log/httpd logs

7.3 - Now browse hadoop distributed file system by opening below url in browser.


http://svr1.tecadmin.net:50070/explorer.html#/user/hadoop/logs

hadoop-test-uploaded-files

7.4 - Now copy logs directory for hadoop distributed file system to local file system.

$ bin/hdfs dfs -get logs /tmp/logs
$ ls -l /tmp/logs/

21 thoughts on “Steps To Setup Hadoop 2.4.0 (Single Node Cluster) on CentOS/RHEL

  1. hi i run the some pi jps some error how to find
    [test@p2 hadoop-2.4.0]$ jps
    10476 SecondaryNameNode
    10296 DataNode
    10201 NameNode
    10762 NodeManager
    11086 Jps
    10661 ResourceManager

    [test@p2 hadoop-2.4.0]bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.4.0.jar pi 10 100
    Number of Maps = 10
    Samples per Map = 100
    14/05/22 13:18:02 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform… using builtin-java classes where applicable
    Wrote input for Map #0
    Wrote input for Map #1
    Wrote input for Map #2
    Wrote input for Map #3
    Wrote input for Map #4
    Wrote input for Map #5
    Wrote input for Map #6
    Wrote input for Map #7
    Wrote input for Map #8
    Wrote input for Map #9
    Starting Job
    14/05/22 13:18:03 INFO client.RMProxy: Connecting to ResourceManager at /0.0.0.0:8032
    java.io.IOException: Failed on local exception: com.google.protobuf.InvalidProtocolBufferException: Protocol message end-group tag did not match expected tag.; Host Details : local host is: “p2.in.krs.na/67.215.65.132″; destination host is: “0.0.0.0”:8032;
    at org.apache.hadoop.net.NetUtils.wrapException(NetUtils.java:764)
    at org.apache.hadoop.ipc.Client.call(Client.java:1414)
    at org.apache.hadoop.ipc.Client.call(Client.java:1363)
    at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:206)
    at $Proxy16.getNewApplication(Unknown Source)
    at org.apache.hadoop.yarn.api.impl.pb.client.ApplicationClientProtocolPBClientImpl.getNewApplication(ApplicationClientProtocolPBClientImpl.java:193)
    at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:190)
    at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:103)
    at $Proxy17.getNewApplication(Unknown Source)
    at org.apache.hadoop.yarn.client.api.impl.YarnClientImpl.getNewApplication(YarnClientImpl.java:165)
    at org.apache.hadoop.yarn.client.api.impl.YarnClientImpl.createApplication(YarnClientImpl.java:173)
    at org.apache.hadoop.mapred.ResourceMgrDelegate.getNewJobID(ResourceMgrDelegate.java:179)
    at org.apache.hadoop.mapred.YARNRunner.getNewJobID(YARNRunner.java:230)
    at org.apache.hadoop.mapreduce.JobSubmitter.submitJobInternal(JobSubmitter.java:357)
    at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1285)
    at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1282)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:416)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1548)
    at org.apache.hadoop.mapreduce.Job.submit(Job.java:1282)
    at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:1303)
    at org.apache.hadoop.examples.QuasiMonteCarlo.estimatePi(QuasiMonteCarlo.java:306)
    at org.apache.hadoop.examples.QuasiMonteCarlo.run(QuasiMonteCarlo.java:354)
    at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)
    at org.apache.hadoop.examples.QuasiMonteCarlo.main(QuasiMonteCarlo.java:363)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.apache.hadoop.util.ProgramDriver$ProgramDescription.invoke(ProgramDriver.java:72)
    at org.apache.hadoop.util.ProgramDriver.run(ProgramDriver.java:145)
    at org.apache.hadoop.examples.ExampleDriver.main(ExampleDriver.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:212)
    Caused by: com.google.protobuf.InvalidProtocolBufferException: Protocol message end-group tag did not match expected tag.
    at com.google.protobuf.InvalidProtocolBufferException.invalidEndTag(InvalidProtocolBufferException.java:94)
    at com.google.protobuf.CodedInputStream.checkLastTagWas(CodedInputStream.java:124)
    at com.google.protobuf.AbstractParser.parsePartialFrom(AbstractParser.java:202)

  2. hi Rahul i follow is i run the pi jops some error came how to solue this problam pls
    test@p2 hadoop-2.4.0]$ hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.4.0.jar pi 5 100
    Number of Maps = 5
    Samples per Map = 100
    14/05/22 19:24:01 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform… using builtin-java classes where applicable
    Wrote input for Map #0
    Wrote input for Map #1
    Wrote input for Map #2
    Wrote input for Map #3
    Wrote input for Map #4
    Starting Job
    14/05/22 19:24:03 INFO client.RMProxy: Connecting to ResourceManager at /127.0.0.1:8032
    14/05/22 19:24:04 INFO input.FileInputFormat: Total input paths to process : 5
    14/05/22 19:24:05 INFO mapreduce.JobSubmitter: number of splits:5
    14/05/22 19:24:05 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1400761600720_0003
    14/05/22 19:24:06 INFO impl.YarnClientImpl: Submitted application application_1400761600720_0003
    14/05/22 19:24:06 INFO mapreduce.Job: The url to track the job: http://p2.in.krs.na:8088/proxy/application_1400761600720_0003/
    14/05/22 19:24:06 INFO mapreduce.Job: Running job: job_1400761600720_0003

  3. When are you publishing next part of this article? I loved this and I am waiting to see how will you test your setup by running some example map reduce job.

  4. Very good article,
    Two issues,
    First exit; ssh localhost will not work for public/private key
    Should be ssh localhost; exit

    Second
    hadoop path shoudl be added for bin directory, thus
    export PATH=$PATH:$HADOOP_HOME/sbin:$HADOOP_HOME/bin
    Other than this, everything worked flawlessly and hadoop is up and running perfectly…
    Thanks much

  5. Dear Rahul,

    Thanks for all the steps. Please update the mapred-site.xml to mapred-site.xml.template.

    Also, please update the testing the setup.

    Thanks,
    Sachin

  6. Dear Rahul,

    thanks for the tutorial, why

    “hadoop/etc/hadoop/hadoop-env.sh”
    “hadoop/etc/hadoop/hadoop-env.sh” E212: Can’t open file for writing

    cant be written?

    thanks.
    frankie

  7. Hi Rahul
    Thank you for sharing this with us. I followed your steps in installing hadoop 2.4 on Centos Vritual Machine. I have an Hbase running on my mac machine, I get connection refused error when hbase tries to connect.
    Here is my setting in core-site.xml

    fs.default.name
    hdfs://localhost:54310

    and on Hbase: hbase-site.xml

    hbase.rootdir
    hdfs://localhost:54310/hbase

    I can telnet onto the port 54310 from the VM but not from a remote machine, i.e my local macbook which is running the virtual machine. Looks like the port is closed to remote client. I have disabled firewall but it didn’t help.

    Any idea?

    Regards,

    Ayache

  8. Nice article. I Managed ot get as far as starting the scripts and ran into problems that required havking the scripts and then got a warnign that ssh could not regonise the host name but start-dfs.sh and start-yarn.sh eventually ran ok, but I could not access hadoop in the browser and wnhen trying to ls the filesystem I get an error
    hdfs dfs -ls
    Exception in thread “main” java.lang.RuntimeException: core-site.xml not found

    However this got me along way forther

  9. Hi Rahul,

    Thank for this article.

    For me everything worked as I followed through this article. But at the last I could not get details of my datanode when I browsed http://server1.com:50075/. The browser says ‘Unable to connect’

    What could be the problem or what mistake I might have done? Please help.

  10. Hi, This one is a great article. I followed many other blogs for this problem. But none of them worked. This one simply worked with no error.

    But i have a little problem.
    I have installed hbase standalone mode.
    Now i want hbase to use hdfs. So in hbase-site.xml file i added this:

    hbase.rootdir
    hdfs://localhost:9000/hbase

    dfs.replication
    1

    But its giving error and not working. Any reason why its not working? I copied the same configuration of yours during my hadoop installation.

    Regards
    Jay

  11. Dear Sir
    after I start hadoop can not run please help advisor
    -used hadoop-2.5.1
    -java ‘ ok
    -but have message below
    /home/hadoop/jhadoop-2.5.1/bin/hdfs:line 262: /user/lib/jvm/java-1.7.0-openjdk-1.7.0.65-2-5.1.2.el7_0x86_64/jre/bin/java: N o such file or directrory

  12. I used
    -CentOS-6.5-i386-bin-DVD1
    java -version “1.7.0.45”
    OpenJDK Runtime Environment (rhel-2.4.3.3.el6-i386 u45-b15)
    OpenJDK Client VM (build 24.45-b08,mixed mode,sharing)
    after that I can not run hadoop how I get it to run

  13. Dear
    How I change command from
    -Old 64 bit
    -1.7.0.51
    -rhel-2.4.5.5.el7-x86_64 u51-b31
    -(build 24.51-b03,mixed mode)
    export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65-2.5.1.2.el7_0.x86_64/jre
    What command change dorectory
    My VM ware java version
    -1.7.0.45
    -rhel-2.4.3.3.el6-i386 u45-b15
    -build 24.45-b08,mixed mode,sharing
    export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6_0.i386/jre
    please help advisor because I am beginner CENT OS and HODOOP
    Best regards

  14. Hello,
    We have followed the given steps for centos 6.5 and hadoop2.5.0. All the dameons get started but still the namenode is not visible on the browser using port no: 50070, error is displayed: “Connection to server sar166.co.com failed”. Please can you suggest some solution!!!
    Thank You.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>