Mapreduce Notes Install mapreduce locally:

26 downloads 871 Views 63KB Size Report
... datasets to test whenever possible. Install mapreduce locally: Based on http:// www.stanford.edu/class/cs246/cs246-11-mmds/hw_files/hadoop_install.pdf.
Mapreduce Notes Running mapreduce locally is a good idea because it allows you to quickly iterate and debug. Use small datasets to test whenever possible.

Install mapreduce locally: Based on http://www.stanford.edu/class/cs246/cs246-11-mmds/hw_files/hadoop_install.pdf 1) Download hadoop http://hadoop.apache.org/mapreduce/releases.html 2) Untar tar xvfz hadoop-0.20.2.tar.gz 3) Set the path to java compiler by editing JAVA_HOME parameter in hadoop/conf/hadoopenv.sh: Mac OS users can use /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home Linux users can run “which java” command to obtain the path. Note that the JAVA_HOME variable shouldn’t contain the bin/java at the end of the path. 4) Create an RSA key to be used by hadoop when ssh’ing to localhost: ssh-keygen -t rsa -P "" cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys In addition, you’ll need to open up your computer/firewall to allow ssh connections (if you haven’t already) 5) Make the following changes to the configuration files under hadoop/conf To core-site.xml: hadoop.tmp.dir TEMPORARY-DIR-FOR-HADOOPDATASTORE fs.default.name hdfs://localhost:54310 To mapred-site.xml: mapred.job.tracker localhost:54311 To hdfs-site.xml: dfs.replication 1

6) Format the hadoop file system. From hadoop directory run the following: ./bin/hadoop namenode -format 7) Run hadoop by running the following script: ./bin/start-all.sh 8) Now you can copy some data from your machine’s file system into hdfs and do ‘ls’ command on hdfs: ./bin/hadoop dfs –put local_machine_path hdfs_path ./bin/hadoop dfs -ls 9) At this point you are ready to run a map reduce job on hadoop. As an example, let’s run WordCount.jar to count the number of times each word appears in a text file. Put a sample text file on hdfs under ‘input’ directory. Download the jar file from: http://www.cs.cmu.edu/~afyshe/ WordCount.jar and run the WordCount map-reduce job: ./bin/hadoop dfs –mkdir input ./bin/hadoop dfs –put local_machine_path/sample.txt input/sample.txt ./bin/hadoop jar ~/path_to_jar_file/WordCount.jar WordCount input output The result will be saved on ‘output’ directory on hdfs.

Set up Eclipse Download and install Eclipse http://www.eclipse.org/downloads/ Create a new project. Add external jar hadoop-version-core.jar to your project (this should have been part of your hadoop download from the first section of this document). Create a new class called WordCount, and get the source from http://wiki.apache.org/hadoop/ WordCount Export your project as a jar by right clicking the project, selecting export, then jar file (under Java), then next, then choose a export destination and click finish. You should now be able to run the jar you created in the same way as the jar you uploaded in the previous section. Now you can write your own mapreduces! Good luck! References: http://snap.stanford.edu/class/cs246-2011/slides/hadoop-session-cs246.pptx http://arifn.web.id/blog/2010/07/29/runningKhadoopKsingleKcluster.html http://arifn.web.id/blog/ 2010/01/23/hadoopKinKnetbeans.html http://www.infosci.cornell.edu/hadoop/mac.html http:// wiki.apache.org/hadoop/GettingStartedWithHadoop