Git Product home page Git Product logo

hadoop-hello-world's Introduction

Hadoop Mac Install and Map Reduce Examples

Prerequisites

Confirm Java 1.6.* or higher for Hadoop

$ java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

Install Homebrew, Git, Maven if needed:

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

% brew install git
% brew install git-flow-avh

% brew install maven

Ensure you can login to your localhost machine:

$ ssh-keygen -t rsa -P ""
$ cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
$ ssh localhost

Installation

Install Hadoop and Hive:

$ brew install hadoop
$ brew install hive

Configuration

Every component of Hadoop is configured using Shell and XML files.

$ cd /usr/local/Cellar/hadoop/2.7.1/libexec/etc/hadoop

Add to hadoop-env.sh your JAVA_HOME path, e.g.:

export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home"

...

export HADOOP_OPTS="$HADOOP_OPTS -Djava.security.krb5.realm= -Djava.security.krb5.kdc="

Add to core-site.xml:

<configuration>
 <property>
   <name>hadoop.tmp.dir</name>
   <value>/tmp/hadoop-${user.name}</value>
   <description>A base for other temporary directories.</description>
 </property>
 <property>
   <name>fs.default.name</name>
   <value>hdfs://localhost:9000</value>
 </property>
</configuration>

Add to hdfs-site.xml:

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

Add to mapred-site.xml:

<configuration>
  <property>
    <name>mapred.job.tracker</name>
    <value>localhost:9001</value>
  </property>
</configuration>

Update your ~/.bash_profile PATH:

PATH=$PATH:/usr/local/Cellar/hadoop/2.7.1/sbin

Source your ~/.bash_profile

$ source ~/.bash_profile

Start / Stop Hadoop

# cleanup HDFS directory
$ rm -rf /tmp/hadoop-*
# format HDFS
$ hadoop namenode -format
# unleash the Hadoop daemons
$ start-all.sh

Make sure all Hadoop processes started correctly:

$ ps aux | grep hadoop | wc -l
     6

Stop Hadoop:

$ stop-all.sh

Hadoop Examples Setup

Build hadoop-hello-world project:

$ cd ~/hadoop-hello-world/
$ mvn clean install

Run the VoteTally Example

Copy test input files to HDFS from local filesystem:

$ hadoop fs -mkdir /input
$ hadoop fs -copyFromLocal src/test/resources/input/votetally /input/.
$ hadoop fs -ls /input
$ hadoop fs -ls /input/votetally
Found 5 items
-rw-r--r--   1 iizrailevsky supergroup      12637 2015-09-26 17:27 /input/votetally/ballotsDistrict0
-rw-r--r--   1 iizrailevsky supergroup      12566 2015-09-26 17:27 /input/votetally/ballotsDistrict1
-rw-r--r--   1 iizrailevsky supergroup      12500 2015-09-26 17:27 /input/votetally/ballotsDistrict2
-rw-r--r--   1 iizrailevsky supergroup      12557 2015-09-26 17:27 /input/votetally/ballotsDistrict3
-rw-r--r--   1 iizrailevsky supergroup      12637 2015-09-26 17:27 /input/votetally/ballotsDistrict4

Run the VoteTally example and check result output:

$ hadoop jar target/hadoop-hello-world.jar com.iizrailevsky.hadoop.example.votetally.VoteTally /input/votetally /output/votetally
$ hadoop fs -ls /output/votetally
$ hadoop fs -cat /output/votetally/part-r-00000
Bush	354
Carson	324
Christie	317

Run the WordCount Example

Copy test input files to HDFS from local filesystem:

$ hadoop fs -mkdir /input
$ hadoop fs -copyFromLocal src/test/resources/input/wordcount /input/.
$ hadoop fs -ls /input/wordcount
Found 2 items
-rw-r--r--   1 iizrailevsky supergroup        520 2014-04-05 15:39 /input/test1
-rw-r--r--   1 iizrailevsky supergroup        590 2014-04-05 15:39 /input/test2

Run the WordCount example and check result output:

$ hadoop jar target/hadoop-hello-world.jar com.iizrailevsky.hadoop.example.wordcount.WordCount /input/wordcount /output/wordcount
$ hadoop fs -ls /output/wordcount
$ hadoop fs -cat /output/wordcount/part-r-00000
Although        1
Cymbeline       3
Denmark 2

hadoop-hello-world's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.