Immediately after the completion of the installation and running of Hadoop, it is time to run the relevant example, and the simplest and most straightforward example is the HelloWorld-wordcount example. Follow the blog to run: http://xiejianglei163.blog.163.com/blog/static/1247276201443152533684/ First create a folder, and create two files, directory arbitrary, for the following file structure: Examples -
The following programs are successfully tested on hadoop1.2.1.
In this example, the source code is first presented, then the execution steps are described in detail, and the source code and execution process are analyzed.
I. Source Code
package org.jediael.hadoopdemo.wordcount;import java.io.IOException;import java.util.StringTokenizer;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.IntWritable;import org.apache.hadoop.io.LongWritable;imp
Hadoop wordcount instance code, hadoopwordcount
A simple example is provided to illustrate what MapReduce is:
We need to count the number of times each word appears in a large file. The file is too large. We split the file into small files and arrange multiple people to collect statistics. This process is "Map ". Then combine the statistics of each person. This is "Reduce ".
In the preceding example, if Map
Tags: enc good ons word image ast JD Hello WordCountCloud Address: https://pan.baidu.com/s/1CmBAJMdcwCxLGuCwSTcJNw Password: QOCWPrerequisites: Starting the cluster, configuring the JDK and Hadoop environment variables is necessary to delete the output files in the virtual machine using[[email protected] sbin]# Hadoop fs-rm-r/outputdeleted/output[[email protected] sbin]# llGive
localhost cannot be directly logged on, run the following command to log on directly.
Ssh-keygen-t dsa-p'-f ~ /. Ssh/id_dsaCat ~ /. Ssh/id_dsa.pub> ~ /. Ssh/authorized_keys
7. Format namenode. Run bin/hadoop namenode-format
8. Start hadoop. Run bin/start-all.sh
9. Run the wordcount example. First, put the input file required for the example on DFS, but an error
Hadoop construction and wordcount instance running in CentOS
I have encountered a lot of troubles in learning to get hadoop recently. It is recorded here to facilitate future viewing. CentOS7 installed in VMwareWorkstation10.0.4Install and configure jdk
Java-version to check whether java is installed
Use env | grepJAVA_HOME or echo $ JAVA_HOME $ PATH to check whe
,There's wordcount.java inside.Linux starts Hadoop (with JPS check is started), after the Eclipse connection, the Hadoop directory will be displayed as follows
Modify CodeNow that the setup aspect is basically complete, the next step is to modify and HDFs path configuration for Wordcount.javaOpen Wordcount.java (may be an error),Change the main method as follows:
If genericopti
1. Start the hadoop daemon
Bin/hadoop start-all.sh
2. Create an Input Folder under the bin directory of hadoop
Mkdire Input
3. After Entering the input directory, create two new text files under the input directory and want them to write content
Echo "Hello Excuse me fuck Thank you"> test1.txt
Echo "hello how do you do thank you"> test2.txt
4. Enter the bin direc
com.sun.tools.javac.Main wordcount.javajar CF wc.jar WordCount*. class4. Run the third step to build the Wc.jar package. It is important to note that the output folder is not created manually and is created automatically when the system is run.Bin/hadoop jar Wc.jar Wordcount/user/root/wordcount/input/user/root/
Write the WordCount program data as follows:Hello BeijingHello ShanghaiHello ChongqingHello TianjinHello GuangzhouHello Shenzhen...1, Wcmapper:Package com.hadoop.testHadoop;Import java.io.IOException;Import org.apache.hadoop.io.LongWritable;Import Org.apache.hadoop.io.Text;Import Org.apache.hadoop.mapreduce.Mapper;In 4 generics, the first two are the types that specify mapper input data, Keyin is the type of the input key, and Valuein is the type of t
hadoop-2.6.0 Pseudo-distribution Run WordCount1 , start Hadoop:2 , create the file folder:This is built on a local hard drive:To view the file files that were created:Enter the directory to create two txt files:The results are as follows:3 , create an Input folder directory on HDFS input:Transfer the files created on the local hard drive into input:View results:4 , Hado
[Email protected] file]$ Hadoop jar ~/hadoop-2.5.2/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.5.2.jar Wordcount/inputfile output16/04/11 22:31:02 INFO Client. Rmproxy:connecting to ResourceManager at master/192.168.222.122:1804016/04/11 22:31:03 INFO input. Fileinput
Copy an objectThe content of the copied "input" folder is as follows:The content of the "conf" file under the hadoop installation directory is the same.Now, run the wordcount program in the pseudo-distributed mode we just built:After the operation is complete, let's check the output result:Some statistical results are as follows:At this time, we will go to the hadoop
procedureMake the Java program into a jar package and upload it to the Hadoop server (any Namenode node on the boot)3. Data sourceThe data source is as follows:Hadoop java text hdfstom Jack Java textjob hadoop ABC lusihdfs Tom textPut the content in a TXT file and put it in HDFs/usr/input (under HDFs, not Linux), and you can upload it using the Eclipse plugin:4. Execute JAR Package# fully qualified name
Tests of other versions are invalid:
I used the configuration to run it successfully!
Eclipse version: eclipse-jee-europa-winter-linux-gtk.tar
Hadoop version: hadoop-0.20.2
Linux: Ubuntu 8
I. Install JDK-6, SSH (a little, Google just)
2. install and configure the hadoop-0.20.2 (a little Google)
Iii. Eclipse plugin Loading
The plugin is under contrib/elicipse-plu
Copy an object The content of the copied "input" folder is as follows: The content of the "conf" file under the hadoop installation directory is the same. Now, run the wordcount program in the pseudo-distributed mode we just built: After the operation is complete, let's check the output result: Some statistical results are as follows: At this time, we will go to the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.