Transcription

HadoopAbout this tutorialHadoop is an open-source framework that allows to store and process big data in adistributed environment across clusters of computers using simple programming models.It is designed to scale up from single servers to thousands of machines, each offering localcomputation and storage.This brief tutorial provides a quick introduction to Big Data, MapReduce algorithm, andHadoop Distributed File System.AudienceThis tutorial has been prepared for professionals aspiring to learn the basics of Big DataAnalytics using Hadoop Framework and become a Hadoop Developer. SoftwareProfessionals, Analytics Professionals, and ETL developers are the key beneficiaries of thiscourse.PrerequisitesBefore you start proceeding with this tutorial, we assume that you have prior exposure toCore Java, database concepts, and any of the Linux operating system flavors.Copyright & Disclaimer Copyright 2014 by Tutorials Point (I) Pvt. Ltd.All the content and graphics published in this e-book are the property of Tutorials Point (I)Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republishany contents or a part of contents of this e-book in any manner without written consentof the publisher.We strive to update the contents of our website and tutorials as timely and as precisely aspossible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt.Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of ourwebsite or its contents including this tutorial. If you discover any errors on our website orin this tutorial, please notify us at [email protected]

HadoopTable of ContentsAbout this tutorial ······· iAudience ····················· iPrerequisites ··············· iCopyright & ····· iTable of Contents ······· ii1.HADOOP BIG DATA OVERVIEW ·············· 1What is Big Data? ······· 1What Comes Under Big Data? ············· 1Benefits of Big Data ···· 2Big Data Technologies ························· 2Operational vs. Analytical ········· 3Big Data Challenges ···· 42.HADOOP BIG DATA SOLUTIONS ············· 5Traditional Enterprise Approach ········· 5Google’s Solution ······· 5Hadoop ······················ 63.HADOOP INTRODUCTION ······················ 7Hadoop Architecture ·· 7MapReduce ················ 7Hadoop Distributed File System ·········· 8How Does Hadoop Work? ··················· 8Advantages of Hadoop ························ 9ii

Hadoop4.HADOOP ENVIRONMENT SETUP ·········· 10Pre-installation Setup ························ 10Installing Java ··········· 11Downloading ·· 12Hadoop Operation Modes ················· 13Installing Hadoop in Standalone Mode ······················ 13Installing Hadoop in Pseudo Distributed Mode ·········· 15Verifying Hadoop Installation ············ 185.HADOOP HDFS ······················· 21Features of HDFS ······ 21HDFS Architecture ···· 21Goals of HDFS ··········· 226.HADOOP HDFS OPERATIONS ··············· 23Starting HDFS ··········· 23Listing Files in HDFS ·· 23Inserting Data into HDFS ··················· 23Retrieving Data from HDFS ················ 24Shutting Down the HDFS ··················· 247.HADOOP COMMAND ············ 25HDFS Command Reference ················ 258.HADOOP ···· 28What is MapReduce? ························ 28The Algorithm ·········· 28Inputs and Outputs (Java Perspective) ······················· 29iii

HadoopTerminology ············· 29Example Scenario ····· 30Compilation and Execution of Process Units Program ························· 33Important Commands ······················· 36How to Interact with MapReduce Jobs ······················· 389.HADOOP STREAMING · 40Example using Python ······················· 40How Streaming 42Important Commands ······················· 4210. HADOOP MULTI-NODE CLUSTER ········· 44Installing Java ··········· 44Creating User Account ······················· 45Mapping the nodes ·· 45Configuring Key Based Login ············· 46Installing Hadoop ····· 46Configuring Hadoop · 46Installing Hadoop on Slave ······· 48Configuring Hadoop on Master Server ······················· 48Starting Hadoop Services ·················· 49Adding a New DataNode in the Hadoop Cluster ········· 49Adding a User and SSH Access ··········· 49Set Hostname of New Node ·············· 50Start the DataNode on New Node ····· 51Removing a DataNode from the Hadoop Cluster ········ 51iv

1. HADOOP BIG DATA OVERVIEWHadoop“90% of the world’s data was generated in the last few years.”Due to the advent of new technologies, devices, and communication means like socialnetworking sites, the amount of data produced by mankind is growing rapidly every year. Theamount of data produced by us from the beginning of time till 2003 was 5 billion gigabytes.If you pile up the data in the form of disks it may fill an entire football field. The same amountwas created in every two days in 2011, and in every ten minutes in 2013. This rate is stillgrowing enormously. Though all this information produced is meaningful and can be usefulwhen processed, it is being neglected.What is Big Data?Big Data is a collection of large datasets that cannot be processed using traditional computingtechniques. It is not a single technique or a tool, rather it involves many areas of businessand technology.What Comes Under Big Data?Big data involves the data produced by different devices and applications. Given below aresome of the fields that come under the umbrella of Big Data. Black Box Data: It is a component of helicopter, airplanes, and jets, etc. It capturesvoices of the flight crew, recordings of microphones and earphones, and theperformance information of the aircraft. Social Media Data: Social media such as Facebook and Twitter hold information andthe views posted by millions of people across the globe. Stock Exchange Data: The stock exchange data holds information about the ‘buy’and ‘sell’ decisions made on a share of different companies made by the customers. Power Grid Data: The power grid data holds information consumed by a particularnode with respect to a base station. Transport Data: Transport data includes model, capacity, distance and availability ofa vehicle. Search Engine Data: Search engines retrieve lots of data from different databases.5

HadoopThus Big Data includes huge volume, high velocity, and extensible variety of data. The datain it will be of three types. Structured data: Relational data. Semi Structured data: XML data. Unstructured data: Word, PDF, Text, Media Logs.Benefits of Big Data Using the information kept in the social network like Facebook, the marketing agenciesare learning about the response for their campaigns, promotions, and other advertisingmediums. Using the information in the social media like preferences and product perception oftheir consumers, product companies and retail organizations are planning theirproduction. Using the data regarding the previous medical history of patients, hospitals areproviding better and quick service.Big Data TechnologiesBig data technologies are important in providing more accurate analysis, which may lead tomore concrete decision-making resulting in greater operational efficiencies, cost reductions,and reduced risks for the business.6

HadoopTo harness the power of big data, you would require an infrastructure that can manage andprocess huge volumes of structured and unstructured data in real-time and can protect dataprivacy and security.There are various technologies in the market from different vendors including Amazon, IBM,Microsoft, etc., to handle big data. While looking into the technologies that handle big data,we examine the following two classes of technology:Operational Big DataThese include systems like MongoDB that provide operational capabilities for real-time,interactive workloads where data is primarily captured and stored.NoSQL Big Data systems are designed to take advantage of new cloud computingarchitectures that have emerged over the past decade to allow massive computations to berun inexpensively and efficiently. This makes operational big data workloads much easier tomanage, cheaper, and faster to implement.Some NoSQL systems can provide insights into patterns and trends based on real-time datawith minimal coding and without the need for data scientists and additional infrastructure.Analytical Big DataThese includes systems like Massively Parallel Processing (MPP) database systems andMapReduce that provide analytical capabilities for retrospective and complex analysis thatmay touch most or all of the data.MapReduce provides a new method of analyzing data that is complementary to the capabilitiesprovided by SQL, and a system based on MapReduce that can be scaled up from single serversto thousands of high and low end machines.These two classes of technology are complementary and frequently deployed together.Operational vs. Analytical SystemsOperationalAnalyticalLatency1 ms - 100 ms1 min - 100 minConcurrency1000 - 100,0001 - 10Access PatternWrites and ReadsReadsQueriesSelectiveUnselective7

HadoopData ScopeOperationalRetrospectiveEnd UserCustomerData ScientistTechnologyNoSQLMapReduce, MPP DatabaseBig Data ChallengesThe major challenges associated with big data are as follows: Capturing data Curation Storage Searching Sharing Transfer Analysis PresentationTo fulfill the above challenges, organizations normally take the help of enterprise servers.8

2. HADOOP BIG DATA SOLUTIONSHadoopTraditional Enterprise ApproachIn this approach, an enterprise will have a computer to store and process big data. For storagepurpose, the programmers will take the help of their choice of database vendors such asOracle, IBM, etc. In this approach, the user interacts with the application, which in turnhandles the part of data storage and analysis.LimitationThis approach works fine with those applications that process less voluminous data that canbe accommodated by standard database servers, or up to the limit of the processor that isprocessing the data. But when it comes to dealing with huge amounts of scalable data, it is ahectic task to process such data through a single database bottleneck.Google’s SolutionGoogle solved this problem using an algorithm called MapReduce. This algorithm divides thetask into small parts and assigns them to many computers, and collects the results from themwhich when integrated, form the result dataset.9

HadoopHadoopUsing the solution provided by Google, Doug Cutting and his team developed an OpenSource Project called HADOOP.Hadoop runs applications using the MapReduce algorithm, where the data is processed inparallel with others. In short, Hadoop is used to develop applications that could performcomplete statistical analysis on huge amounts of data.10

3. HADOOP INTRODUCTIONHadoopHadoop is an Apache open source framework written in java that allows distributed processingof large datasets across clusters of computers using simple programming models. The Hadoopframework application works in an environment that provides distributed storage andcomputation across clusters of computers. Hadoop is designed to scale up from single serverto thousands of machines, each offering local computation and storage.Hadoop ArchitectureAt its core, Hadoop has two major layers namely:(a) Processing/Computation layer (MapReduce), and(b) Storage layer (Hadoop Distributed File System).MapReduceMapReduce is a parallel programming model for writing distributed applications devised atGoogle for efficient processing of large amounts of data (multi-terabyte data-sets), on large11

Hadoopclusters (thousands of nodes) of commodity hardware in a reliable, fault-tolerant manner.The MapReduce program runs on Hadoop which is an Apache open-source framework.Hadoop Distributed File SystemThe Hadoop Distributed File System (HDFS) is based on the Google File System (GFS) andprovides a distributed file system that is designed to run on commodity hardware. It has manysimilarities with existing distributed file systems. However, the differences from otherdistributed file systems are significant. It is highly fault-tolerant and is designed to bedeployed on low-cost hardware. It provides high throughput access to application data and issuitable for applications having large datasets.Apart from the above-mentioned two core components, Hadoop framework also includes thefollowing two modules: Hadoop Common: These are Java libraries and utilities required by other Hadoopmodules. Hadoop YARN: This is a framework for job scheduling and cluster resourcemanagement.How Does Hadoop Work?It is quite expensive to build bigger servers with heavy configurations that handle large scaleprocessing, but as an alternative, you can tie together many commodity computers withsingle-CPU, as a single functional distributed system and practically, the clustered machinescan read the dataset in parallel and provide a much higher throughput. Moreover, it is cheaperthan one high-end server. So this is the first motivational factor behind using Hadoop that itruns across clustered and low-cost machines.Hadoop runs code across a cluster of computers. This process includes the following coretasks that Hadoop performs: Data is initially divided into directories and files. Files are divided into uniform sizedblocks of 128M and 64M (preferably 128M). These files are then distributed across various cluster nodes for further processing. HDFS, being on top of the local file system, supervises the processing. Blocks are replicated for handling hardware failure. Checking that the code was executed successfully. Performing the sort that takes place between the map and reduce stages.12

Hadoop Sending the sorted data to a certain computer. Writing the debugging logs for each job.Advantages of Hadoop Hadoop framework allows the user to quickly write and test distributed systems. It isefficient, and it automatic distributes the data and work across the machines and inturn, 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 failuresat the application layer. Servers can be added or removed from the cluster dynamically and Hadoop continuesto operate without interruption. Another big advantage of Hadoop is that apart from being open source, it is compatibleon all the platforms since it is Java based.13

4. HADOOP ENVIRONMENT SETUPHadoopHadoop is supported by GNU/Linux platform and its flavors. Therefore, we have to install aLinux operating system for setting up Hadoop environment. In case you have an OS otherthan Linux, you can install a Virtualbox software in it and have Linux inside the Virtualbox.Pre-installation SetupBefore installing Hadoop into the Linux environment, we need to set up Linux using ssh(Secure Shell). Follow the steps given below for setting up the Linux environment.Creating a UserAt the beginning, it is recommended to create a separate user for Hadoop to isolate Hadoopfile system from Unix file system. Follow the steps given below to create a user: Open the root using the command “su”. Create a user from the root account using the command “useradd username”. Now you can open an existing user account using the command “su username”.Open the Linux terminal and type the following commands to create a user. supassword:# useradd hadoop# passwd hadoopNew passwd:Retype new passwdSSH Setup and Key GenerationSSH setup is required to do different operations on a cluster such as starting, stopping,distributed daemon shell operations. To authenticate different users of Hadoop, it is requiredto provide public/private key pair for a Hadoop user and share it with different users.The following commands are used for generating a key value pair using SSH. Copy the publickeys form id rsa.pub to authorized keys, and provide the owner with read and writepermissions to authorized keys file respectively.14

Hadoop ssh-keygen -t rsa cat /.ssh/id rsa.pub /.ssh/authorized keys chmod 0600 /.ssh/authorized keysInstalling JavaJava is the main prerequisite for Hadoop. First of all, you should verify the existence of javain your system using the command “java -version”. The syntax of java version command isgiven below. java -versionIf everything is in order, it will give you the following output.java version "1.7.0 71"Java(TM) SE Runtime Environment (build 1.7.0 71-b13)Java HotSpot(TM) Client VM (build 25.0-b02, mixed mode)If java is not installed in your system, then follow the steps given below for installing java.Step 1Download java (JDK latest version - X64.tar.gz) by visiting the following downloads/jdk7-downloads-1880260.html.Then jdk-7u71-linux-x64.tar.gz will be downloaded into your system.Step 2Generally you will find the downloaded java file in Downloads folder. Verify it and extract thejdk-7u71-linux-x64.gz file using the following commands. cd Downloads/ lsjdk-7u71-linux-x64.gz tar zxf jdk-7u71-linux-x64.gz lsjdk1.7.0 71jdk-7u71-linux-x64.gzStep 315

HadoopTo make java available to all the users, you have to move it to the location “/usr/local/”. Openroot, and type the following commands. supassword:# mv jdk1.7.0 71 /usr/local/# exitStep 4For setting up PATH and JAVA HOME variables, add the following commands to /.bashrcfile.export JAVA HOME /usr/local/jdk1.7.0 71export PATH PATH: JAVA HOME/binNow apply all the changes into the current running system. source /.bashrcStep 5Use the following commands to configure java alternatives:# alternatives --install /usr/bin/java java usr/local/java/bin/java 2# alternatives --install /usr/bin/javac javac usr/local/java/bin/javac 2# alternatives --install /usr/bin/jar jar usr/local/java/bin/jar 2# alternatives --set java usr/local/java/bin/java# alternatives --set javac usr/local/java/bin/javac# alternatives --set jar usr/local/java/bin/jarNow verify the installation using the command java -version from the terminal as explainedabove.Downloading HadoopDownload and extract Hadoop 2.4.1 from Apache software foundation using the followingcommands. su16

Hadooppassword:# cd /usr/local# wget hadoop-2.4.1.tar.gz# tar xzf hadoop-2.4.1.tar.gz# mv hadoop-2.4.1/* to hadoop/# exitHadoop Operation ModesOnce you have downloaded Hadoop, you can operate your Hadoop cluster in one of the threesupported modes: Local/Standalone Mode: After downloading Hadoop in your system, by default, it isconfigured in a standalone mode and can be run as a single java process. Pseudo Distributed Mode: It is a distributed simulation on single machine. EachHadoop daemon such as hdfs, yarn, MapReduce etc., will run as a separate javaprocess. This mode is useful for development. Fully Distributed Mode: This mode is fully distributed with minimum two or moremachines as a cluster. We will come across this mode in detail in the coming chapters.Installing Hadoop in Standalone ModeHere we will discuss the installation of Hadoop 2.4.1 in standalone mode.There are no daemons running and everything runs in a single JVM. Standalone mode issuitable for running MapReduce programs during development, since it is easy to test anddebug them.Setting Up HadoopYou can set Hadoop environment variables by appending the following commands to /.bashrc file.export HADOOP HOME /usr/local/hadoopBefore proceeding further, you need to make sure that Hadoop is working fine. Just issue thefollowing command: hadoop version17

HadoopIf everything is fine with your setup, then you should see the following result:Hadoop 2.4.1Subversion https://svn.apache.org/repos/asf/hadoop/common -r 1529768Compiled by hortonmu on 2013-10-07T06:28ZCompiled with protoc 2.5.0From source with checksum 79e53ce7994d1628b240f09af91e1af4It means your Hadoop's standalone mode setup is working fine. By default, Hadoop isconfigured to run in a non-distributed mode on a single machine.ExampleLet's check a simple example of Hadoop. Hadoop installation delivers the following exampleMapReduce jar file, which provides basic functionality of MapReduce and can be used forcalculating, like Pi value, word counts in a given list of files, etc. HADOOP les-2.2.0.jarLet's have an input directory where we will push a few files and our requirement is to countthe total number of words in those files. To calculate the total number of words, we do notneed to write our MapReduce, provided the .jar file contains the implementation for wordcount. You can try other examples using the same .jar file; just issue the following commandsto check supported MapReduce functional programs by hadoop-mapreduce-examples2.2.0.jar file. hadoop jar HADOOP les2.2.0.jarStep 1Create temporary content files in the input directory. You can create this input directoryanywhere you would like to work. mkdir input cp HADOOP HOME/*.txt input ls -l inputIt will give the following files in your input directory:18

Hadooptotal 24-rw-r--r-- 1 root root 15164 Feb 21 10:14 LICENSE.txt-rw-r--r-- 1 root root101 Feb 21 10:14 NOTICE.txt-rw-r--r-- 1 root root 1366 Feb 21 10:14 README.txtThese files have been copied from the Hadoop installation home directory. For yourexperiment, you can have different and large sets of files.Step 2Let's start the Hadoop process to count the total number of words in all the files available inthe input directory, as follows: hadoop jar HADOOP les2.2.0.jar wordcount input ouput19

HadoopEnd of ebook previewIf you liked what you saw Buy it from our store @ https://store.tutorialspoint.com20

Hadoop 6 Thus Big Data includes huge volume, high velocity, and extensible variety of data. The data in it will be of three types. Structured data: Relational data. Semi Structured data: XML data. Unstructured data: Word, PDF, Text, Media Logs. Benefits of Big DataFile Size: 845KBPage Count: 21Explore furtherHadoop Tutorial For Beginners Pdf - XpCoursewww.xpcourse.comHow to Install and Run Hadoop on Windows for Beginners .www.datasciencecentral.comHow to Start Learning Hadoop for Beginners? - Whizlabs Blogwww.whizlabs.comHadoop Tutorialwww.tutorialspoint.comLearn Big Data Hadoop Tutorial - javatpointwww.javatpoint.comRecommended to you b