设为首页 收藏本站
查看: 1165|回复: 0

[经验分享] 部署hadoop的开发环境

[复制链接]

尚未签到

发表于 2015-7-12 12:19:53 | 显示全部楼层 |阅读模式
  第一步:安装jdk
  由于hadoop是java开发的,所以需要JDK来运行代码。这里安装的是jdk1.6.
  jdk的安装见http://www.iyunv.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




hadoop.tmp.dir
/app/hadoop/tmp
A base for other temporary directories.


fs.default.name
hdfs://10.53.132.52:54310
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.


dfs.permissions
false


  



vi conf/hdfs-site.xml




dfs.replication
1
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.



  



vi conf/mapred-site.xml




mapred.job.tracker
10.53.132.52:54311
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.



  
  第六步:开启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项目。
DSC0000.jpg
  修改map/reduce和hdfs的地址和端口
DSC0001.jpg
  
  第九步:调试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{
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 {
private IntWritable result = new IntWritable();
public void reduce(Text key, Iterable 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)
  调试
DSC0002.jpg
  
  结果



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

DSC0003.jpg
  
  
  
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-85814-1-1.html 上篇帖子: 如何在Hadoop中使用Streaming编写MapReduce(转帖) 下篇帖子: hadoop资料
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表