第一步:安装jdk

由于hadoop是java开发的,所以需要JDK来运行代码。这里安装的是jdk1.6.

jdk的安装见http://www.cnblogs.com/tommyli/archive/2012/01/06/2314706.html

第二步:创建独立的用户

useradd hadoop
passwd hadoop

有些机器不能设置空密码的时候

passwd -d hadoop

这里的用户名为hadoop,如果你要调试的时候要注意名字。

比如我用windows调试linux的集群,这个名字应该是windows系统的用户名(否则你没有权限提交作业到hadoop)。

第三步:设置用户无密码登陆

su - hadoop
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys
exit

第四步:下载hadoop

mkdir /opt/hadoop
cd /opt/hadoop/
wget http://apache.mesi.com.ar/hadoop/common/hadoop-1.2.0/hadoop-1.2.0.tar.gz
tar -xzf hadoop-1.2.0.tar.gz
mv hadoop-1.2.0 hadoop
chown -R hadoop /opt/hadoop
cd /opt/hadoop/hadoop/

第五步:配置hadoop

vi conf/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://10.53.132.52:54310</value>
<description>The name of the default file system. A URI whose
scheme and authority determine the FileSystem implementation. The
uri's scheme determines the config property (fs.SCHEME.impl) naming
the FileSystem implementation class. The uri's authority is used to
determine the host, port, etc. for a filesystem.</description>
</property> <property>
<name>dfs.permissions</name>
<value>false</value>
</property>
vi conf/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>

  

vi conf/mapred-site.xml
<property>
<name>mapred.job.tracker</name>
<value>10.53.132.52: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>

第六步:开启hadoop

bin/hadoop namenode -format
bin/start-all.sh

关闭是

bin/stop-all.sh

验证开启是

jps
26049 SecondaryNameNode
25929 DataNode
26399 Jps
26129 JobTracker
26249 TaskTracker
25807 NameNode

第七步:下载并设置eclipse的hadoop插件。

插件文件是:hadoop-eclipse-plugin-1.2.0.jar

放到eclipse的plugins目录下即可。

第八步:打开eclipse创建map/reduce项目。

修改map/reduce和hdfs的地址和端口

第九步:调试hadoop

package org.apache.hadoop.examples;

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.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser; public class WordCount { public static class TokenizerMapper
extends Mapper<Object, Text, Text, IntWritable>{
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(Object key, Text value, Context context)
throws IOException, InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString());
while (itr.hasMoreTokens()) {
word.set(itr.nextToken());
context.write(word, one);
}
}
} public static class IntSumReducer
extends Reducer<Text,IntWritable,Text,IntWritable> {
private IntWritable result = new IntWritable();
public void reduce(Text key, Iterable<IntWritable> values,Context context)
throws IOException, InterruptedException {
int sum = 0;
for (IntWritable val : values) {
sum += val.get();
}
result.set(sum);
context.write(key, result);
}
} public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
conf.set("mapred.job.tracker", "10.53.132.52:54311"); //conf.addResource(new Path("\\soft\\hadoop\\conf\\core-site.xml"));
//conf.addResource(new Path("\\soft\\hadoop\\conf\\hdfs-site.xml")); String[] ars=new String[]{"input","output"};
String[] otherArgs = new GenericOptionsParser(conf, ars).getRemainingArgs();
if (otherArgs.length != 2) {
System.err.println("Usage: wordcount ");
System.exit(2);
}
Job job = new Job(conf, "word count");
job.setJarByClass(WordCount.class);
job.setMapperClass(TokenizerMapper.class);
job.setCombinerClass(IntSumReducer.class);
job.setReducerClass(IntSumReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}

(这里是吧作业提交到远端的hadoop)

调试

结果

13/09/17 17:50:32 INFO input.FileInputFormat: Total input paths to process : 2
13/09/17 17:50:33 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
13/09/17 17:50:33 WARN snappy.LoadSnappy: Snappy native library not loaded
13/09/17 17:50:33 INFO mapred.JobClient: Running job: job_201309171747_0002
13/09/17 17:50:34 INFO mapred.JobClient: map 0% reduce 0%
13/09/17 17:50:39 INFO mapred.JobClient: map 100% reduce 0%
13/09/17 17:50:47 INFO mapred.JobClient: map 100% reduce 33%
13/09/17 17:50:48 INFO mapred.JobClient: map 100% reduce 100%
13/09/17 17:50:49 INFO mapred.JobClient: Job complete: job_201309171747_0002
13/09/17 17:50:49 INFO mapred.JobClient: Counters: 29
13/09/17 17:50:49 INFO mapred.JobClient: Job Counters
13/09/17 17:50:49 INFO mapred.JobClient: Launched reduce tasks=1
13/09/17 17:50:49 INFO mapred.JobClient: SLOTS_MILLIS_MAPS=6115
13/09/17 17:50:49 INFO mapred.JobClient: Total time spent by all reduces waiting after reserving slots (ms)=0
13/09/17 17:50:49 INFO mapred.JobClient: Total time spent by all maps waiting after reserving slots (ms)=0
13/09/17 17:50:49 INFO mapred.JobClient: Launched map tasks=2
13/09/17 17:50:49 INFO mapred.JobClient: Data-local map tasks=2
13/09/17 17:50:49 INFO mapred.JobClient: SLOTS_MILLIS_REDUCES=8702
13/09/17 17:50:49 INFO mapred.JobClient: File Output Format Counters
13/09/17 17:50:49 INFO mapred.JobClient: Bytes Written=41
13/09/17 17:50:49 INFO mapred.JobClient: FileSystemCounters
13/09/17 17:50:49 INFO mapred.JobClient: FILE_BYTES_READ=79
13/09/17 17:50:49 INFO mapred.JobClient: HDFS_BYTES_READ=286
13/09/17 17:50:49 INFO mapred.JobClient: FILE_BYTES_WRITTEN=174015
13/09/17 17:50:49 INFO mapred.JobClient: HDFS_BYTES_WRITTEN=41
13/09/17 17:50:49 INFO mapred.JobClient: File Input Format Counters
13/09/17 17:50:49 INFO mapred.JobClient: Bytes Read=50
13/09/17 17:50:49 INFO mapred.JobClient: Map-Reduce Framework
13/09/17 17:50:49 INFO mapred.JobClient: Map output materialized bytes=85
13/09/17 17:50:49 INFO mapred.JobClient: Map input records=2
13/09/17 17:50:49 INFO mapred.JobClient: Reduce shuffle bytes=85
13/09/17 17:50:49 INFO mapred.JobClient: Spilled Records=12
13/09/17 17:50:49 INFO mapred.JobClient: Map output bytes=82
13/09/17 17:50:49 INFO mapred.JobClient: Total committed heap usage (bytes)=602996736
13/09/17 17:50:49 INFO mapred.JobClient: CPU time spent (ms)=2020
13/09/17 17:50:49 INFO mapred.JobClient: Combine input records=8
13/09/17 17:50:49 INFO mapred.JobClient: SPLIT_RAW_BYTES=236
13/09/17 17:50:49 INFO mapred.JobClient: Reduce input records=6
13/09/17 17:50:49 INFO mapred.JobClient: Reduce input groups=5
13/09/17 17:50:49 INFO mapred.JobClient: Combine output records=6
13/09/17 17:50:49 INFO mapred.JobClient: Physical memory (bytes) snapshot=555175936
13/09/17 17:50:49 INFO mapred.JobClient: Reduce output records=5
13/09/17 17:50:49 INFO mapred.JobClient: Virtual memory (bytes) snapshot=1926799360
13/09/17 17:50:49 INFO mapred.JobClient: Map output records=8

部署hadoop的开发环境的更多相关文章

  1. 基于Eclipse的Hadoop应用开发环境配置

    基于Eclipse的Hadoop应用开发环境配置 我的开发环境: 操作系统ubuntu11.10 单机模式 Hadoop版本:hadoop-0.20.1 Eclipse版本:eclipse-java- ...

  2. 【Yeoman】热部署web前端开发环境

    本文来自 “简时空”:<[Yeoman]热部署web前端开发环境>(自动同步导入到博客园) 1.序言 记得去年的暑假看RequireJS的时候,曾少不更事般地惊为前端利器,写了<Sp ...

  3. hadoop搭建开发环境及编写Hello World

    hadoop搭建开发环境及编写Hello World   本文地址:http://www.cnblogs.com/archimedes/p/hadoop-helloworld.html,转载请注明源地 ...

  4. 批量部署Hadoop集群环境(1)

    批量部署Hadoop集群环境(1) 1. 项目简介: 前言:云火的一塌糊涂,加上自大二就跟随一位教授做大数据项目,所以很早就产生了兴趣,随着知识的积累,虚拟机已经不能满足了,这次在服务器上以生产环境来 ...

  5. 使用 docker 部署常用的开发环境

    使用 docker 部署常用的开发环境 Intro 使用 docker,很多环境可以借助 docker 去部署,没必要所有的环境都在本地安装,十分方便. 前段时间电脑之前返厂修了,回来之后所有的软件都 ...

  6. 使用vagrant一键部署本地php开发环境(二)制作自己的vagrant box

    在上篇的基础上 ,我们已经安装好了virtualbox和vagrant,没有安装的话,参照上篇 使用vagrant一键部署本地php开发环境(一) 1.从网易镜像或阿里等等镜像下载Centos7 ht ...

  7. 【原创干货】大数据Hadoop/Spark开发环境搭建

    已经自学了好几个月的大数据了,第一个月里自己通过看书.看视频.网上查资料也把hadoop(1.x.2.x).spark单机.伪分布式.集群都部署了一遍,但经历短暂的兴奋后,还是觉得不得门而入. 只有深 ...

  8. windows部署React-Native的开发环境实践(技术细节)

    前情摘要 众所周知,有人说.net可以用Xamrian,呵呵,不习惯收费的好么?搞.Net的人设置一次java的环境变量,可能都觉得实在太麻烦了,可能是因为这些年微软确实把我们给带坏了,所有东西一键安 ...

  9. Hadoop Eclipse开发环境搭建

        This document is from my evernote, when I was still at baidu, I have a complete hadoop developme ...

随机推荐

  1. Java-JUC(八):使用wait,notify|notifyAll完成生产者消费者通信,虚假唤醒(Spurious Wakeups)问题出现场景,及问题解决方案。

    模拟通过线程实现消费者和订阅者模式: 首先,定义一个店员:店员包含进货.卖货方法:其次,定义一个生产者,生产者负责给店员生产产品:再者,定义一个消费者,消费者负责从店员那里消费产品. 店员: /** ...

  2. Android性能优化系列之App启动优化

    Android性能优化系列之布局优化 Android性能优化系列之内存优化 Android性能优化系列之apk瘦身 应用的启动速度缓慢是我们在开发过程中常常会遇到的问题,比方启动缓慢导致的黑屏.白屏问 ...

  3. Angular入门笔记

    AngularJS(下面简称其为ng)是Google开源的一款JavaScript MVC框架,弥补了HTML在构建应用方面的不足,其通过使用指令(directives)结构来扩展HTML词汇,使开发 ...

  4. WinRAR如何批量分别压缩不同的文件夹

    全选所有文件夹,然后右击添加到压缩文件,然后在文件选项中勾选把每个文件放到单独的压缩文件中   OK了  

  5. 微软BI 之SSRS 系列 - 如何实现报表导航 Navigation 和钻取 Drill Down 的效果

    开篇介绍 如何在 SSRS 报表中实现标签导航 Navigation 和向下钻取 Drill Down的效果? 如同下面这个例子一样 - 在页面第一次加载的时候,默认显示是全部地区的销售总和情况,上面 ...

  6. .NET MVC中登陆授权过滤器的使用

    1.写个类LoginAuthorityAttribute,继承自AuthorizeAttribute using System; using System.Collections.Generic; u ...

  7. MySql【Insert Select Not Exist】判断记录再添加值的方案

    INSERT INTO content ( detail, status, beginTime, endTime) SELECT @detail, , NULL, NULL FROM DUAL WHE ...

  8. Serializable 介绍

    今天咱们简单介绍一些serializable. 1.序列化是干什么的? 简单说就是为了保存在内存中的各种对象的状态(也就是实例变量,不是方法),并且可以把保存的对象状态再读出来.虽然你可以用你自己的各 ...

  9. 转:nginx基础概念(keepalive、pipe)

    keapalive 当然,在nginx中,对于http1.0与http1.1也是支持长连接的.什么是长连接呢?我们知道,http请求是基于TCP协议之上的,那么,当客户端在发起请求前,需要先与服务端建 ...

  10. WritePrivateProfileString GetPrivateProfileString 读取写 配置文件

    Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfi ...