Practical: 9
Submitted By:
AIM:
HADOOP IMPLEMENTATION
IN LINUX
GANPAT UNIVERSITY
U. V. Patel College of Engineering
HADOOP
Hadoop is an Apache open source framework written in java that allows distributed processing of large datasets across clusters of computers using simple programming models. A Hadoop frame-worked application works in an environment that provides distributed storage and computation across clusters of computers. Hadoop is designed to scale up from single server to thousands of machines, each offering local computation and storage.
HADOOP ARCHITECTURE
● Hadoop Common: These are Java libraries and utilities required by other Hadoop modules. These libraries provides filesystem and OS level abstractions and contains the necessary Java files and scripts required to start Hadoop.
● Hadoop YARN: This is a framework for job scheduling and cluster resource management. ● Hadoop Distributed File System (HDFS™): A distributed file system that provides
high-throughput access to application data.
● Hadoop MapReduce: This is YARN-based system for parallel processing of large data sets
MapReduce
Hadoop MapReduce is a software framework for easily writing applications which process big amounts of data in-parallel on large clusters (thousands of nodes) of commodity hardware in a reliable, fault-tolerant manner.
The term MapReduce actually refers to the following two different tasks that Hadoop programs perform: ● The Map Task: This is the first task, which takes input data and converts it into a set of data,
where individual elements are broken down into tuples (key/value pairs).
Typically both the input and the output are stored in a file-system. The framework takes care of scheduling tasks, monitoring them and re-executes the failed tasks.
The MapReduce framework consists of a single master JobTracker and one slave TaskTracker per cluster-node. The master is responsible for resource management, tracking resource
consumption/availability and scheduling the jobs component tasks on the slaves, monitoring them and re-executing the failed tasks. The slaves TaskTracker execute the tasks as directed by the master and provide task-status information to the master periodically.
The JobTracker is a single point of failure for the Hadoop MapReduce service which means if JobTracker goes down, all running jobs are halted
Hadoop Distributed File System (HDFS)
The Hadoop Distributed File System (HDFS) is based on the Google File System (GFS) and provides a distributed file system that is designed to run on large clusters (thousands of computers) of small computer machines in a reliable, fault-tolerant manner.
HDFS uses a master/slave architecture where master consists of a single NameNode that manages the file system metadata and one or more slave DataNodes that store the actual data.
A file in an HDFS namespace is split into several blocks and those blocks are stored in a set of
DataNodes. The NameNode determines the mapping of blocks to the DataNodes. The DataNodes takes care of read and write operation with the file system. They also take care of block creation, deletion and replication based on instruction given by NameNode.
How Does Hadoop Work?
Stage 1
A user/application can submit a job to the Hadoop (a hadoop job client) for required process by specifying the following items:
1. The location of the input and output files in the distributed file system.
2. The java classes in the form of jar file containing the implementation of map and reduce functions.
3. The job configuration by setting different parameters specific to the job.
Stage 2
The Hadoop job client then submits the job (jar/executable etc) and configuration to the JobTracker which then assumes the responsibility of distributing the software/configuration to the slaves, scheduling tasks and monitoring them, providing status and diagnostic information to the job-client.
Stage 3
Advantages of Hadoop
● Hadoop framework allows the user to quickly write and test distributed systems. It is efficient, and it automatic distributes the data and work across the machines and in turn, utilizes the underlying parallelism of the CPU cores.
● Hadoop does not rely on hardware to provide fault-tolerance and high availability (FTHA), rather Hadoop library itself has been designed to detect and handle failures at the application layer. ● Servers can be added or removed from the cluster dynamically and Hadoop continues to operate
without interruption.
● Another big advantage of Hadoop is that apart from being open source, it is compatible on all the platforms since it is Java based
Configuration of Hadoop File System (HDFS) on a
single-node cluster:
Step 1: Installing JAVA in your system
sudo apt-get update
sudo apt-get install openjdk-7-jdk
Check java version
Step 2: Add hadoop group and add a hduser (hadoop user)
$ sudo addgroup hadoop$ sudo adduser --ingroup hadoop hduser
Step 3:
Configuring SSH Server:
$ ssh-keygen -t rsa -P ""
Check ssh in localhost:
$ Ssh localhost
Step 4: Disable IPV6
Virat@virat-Aspire-5750G:~$ sudo gedit /etc/sysctl.conf
Add this lines at last in file
# disable ipv6
net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.lo.disable_ipv6 = 1
You can check whether IPv6 is enabled on your machine with the following . A return value of 0 means IPv6 is enabled, a value of 1 means disabled (that’s what we want).
$ cat /proc/sys/net/ipv6/conf/all/disable_ipv6
Step 5: INSTALLATION of Hadoop
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:
$cd /usr/local/hadoop
$ sudo tar xzf hadoop-2.7.2.tar.gz
$ sudo mv hadoop-2.7.2 hadoop
Step 6:Editing bashrc file
Add following line to ~/.bashrc file. To set path of hadoop and java
hduser@virat-Aspire-5750G:~$ vi ~/.bashrc
Check hadoop :
$Hadoop versionStep 7: Editing Configuration files
$cd /usr/local/hadoop/hadoop-2.7.2/etc/hadoop
$vi hadoop-env.sh
Add following lines to hadoop-env.sh
# The java implementation to use.
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-i386
Add the following snippets between the
<configuration> ... </configuration>
tags in the respective configuration XML file.
$vi core-site.xml
<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>
determine the host, port, etc. for a filesystem.</description> </property>
$ vi mapred-site.xml.template
<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>
$vi hdfs-site.xml
<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>
Step 7:
Formatting the HDFS filesystem via the NameNode
$ /usr/local/hadoop/hadoop2.7.2/bin/hadoop namenode
-format
Step 8: Starting your single-node cluster
hduser@virat-Aspire-5750G:/usr/local/hadoop/hadoop-2.7.2$
sbin/start-all.sh
Step 10:Stopping your single-node cluster
hduser@virat-Aspire-5750G:/usr/local/hadoop/hadoop-2.7.2$
sbin/stop-all.sh
Running a MapReduce job
hduser@virat-Aspire-5750G:/usr/local/hadoop/hadoop-2.7.2$
sbin/start-all.sh
//create input directory
$hadoop dfs -mkdir -p /user/hduser/input
//create output directory
$HADOOP_HOME/bin/hdfs dfs -mkdir /user/hduser/output
//put files in input
$hadoop fs -put /input/*.txt /user/hduser/input
$hadoop fs -put /input /user/hduser/input
//see input directory
$bin/hadoop dfs -ls /user/hduser/input
//run mapReduce job
//part-r-00000 contains output
//see output
bin/hadoop dfs -cat /user/hduser/output/part-r-00000
Useful Commands:
//delete files from output
$hadoop fs -rm -r /user/hduser/output
//run another mapreduce program
$bin/hadoop jar
$HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar wordcount /user/hduser/input
/user/hduser/output