当前位置: 移动技术网 > IT编程>数据库>其他数据库 > 大数据入门:Hadoop安装、环境配置及检测

大数据入门:Hadoop安装、环境配置及检测

2018年11月26日  | 移动技术网IT编程  | 我要评论

126电影网,机械公敌下载,房屋贷款计算器最新2013

目录


@


hadoop所用安装包和配置文件等我找到最方便使用的方式再上传到博客,如果有需要也欢迎找我分享。


  • 这篇博客是建立在我另一篇博客的基础上,建议先浏览博文

在windows下,

1.导包hadoop包

我用的是破解版的文件,不需要安装,直接解压到d盘下
在这里插入图片描述


2.配置环境变量

  • 接下来配置环境变量,相信配置过jdk的同学们对这一步应该不算陌生。

我的电脑——>属性——>高级系统设置——>环境变量——>系统变量——>编辑path,增加 %hadoop_home%\bin ——>新建一个变量名为 hadoop_home,变量值为 hadoop安装路径的系统变量——>确定操作——>完成
在这里插入图片描述

在这里插入图片描述

找到系统变量,编辑path
在这里插入图片描述

加上 %hadoop_home%\bin即可
在这里插入图片描述

确定之后,新建一个系统变量
在这里插入图片描述

在这里插入图片描述
然后依次确定刚才的操作,配置环境变量工作完成。


3.把winutil包拷贝到hadoop bin目录下

在这里插入图片描述


4.把hadoop.dll放到system32下

路径:c:\windows\system32
在这里插入图片描述


5.检测hadoop是否正常安装

5.1在maven项目中检测,将配置文件放入resource包下

在这里插入图片描述

5.2然后通过一个简单的wordcount程序检测hadoop是否安装成功

先在本地电脑写一个txt文件,内容随便输入,
如:
在这里插入图片描述

5.3保存好之后,写程序:

(检测这里将程序复制过去就可以,先不用理解,后续学习)

package com.oracle.demo.mr;

import org.apache.hadoop.fs.path;
import org.apache.hadoop.io.intwritable;
import org.apache.hadoop.io.longwritable;
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 java.io.ioexception;

public class wordcount {
    public class wcmapper extends mapper<longwritable,text,text,intwritable> {
        @override
        protected void map(longwritable key, text value, context context) throws ioexception, interruptedexception {
            string line = value.tostring();
            string[] strs = line.split(" ");
            for (string s:strs){
                text outkey = new text(s);
                intwritable outvalue = new intwritable(1);
                context.write(outkey,outvalue);
            }
        }
    }
    public class wcreduce extends reducer<text,intwritable,text,intwritable> {
        @override
        protected void reduce(text key, iterable<intwritable> values, context context) throws ioexception, interruptedexception {
            int count = 0;
            for (intwritable n:values){
                count += n.get();

            }
            context.write(key,new intwritable(count));
        }
    }
    public static void main(string[] args) throws ioexception, classnotfoundexception, interruptedexception {
        job job = job.getinstance();

        job.setmapoutputkeyclass(text.class);
        job.setmapoutputvalueclass(intwritable.class);

        job.setmapoutputkeyclass(text.class);
        job.setmapoutputvalueclass(intwritable.class);

        job.setmapperclass(com.oracle.demo.mr.wcmapper.class);
        job.setreducerclass(com.oracle.demo.mr.wcreduce.class);

        fileinputformat.setinputpaths(job,new path("e:\\bigdata\\input.txt"));
        fileoutputformat.setoutputpath(job,new path("e:\\bigdata\\output"));

        job.waitforcompletion(true);
    }
}

注意:
在这里插入图片描述
运行之后控制台显示:
在这里插入图片描述
。。。
在这里插入图片描述
。。。
在这里插入图片描述

表示运行成功,没有错误

5.4最后我们打开输出文件查看:

在这里插入图片描述

结果是:
在这里插入图片描述
此刻,表示hadoop安装成功,大功告成了。


6.容易出现的错误:

6.1.导包错误

6.2.输出文件存在

exception in thread "main" org.apache.hadoop.mapred.filealreadyexistsexception: output directory file:/e:/bigdata/output already exists
在这里插入图片描述
如何解决:之前运行的输出文件删除即可。

6.3.环境搭建或配置等错误

在这里插入图片描述


这篇博客是我自己安装完之后写出来的,如果过程中有什么疏漏或者疑问,欢迎和我交流。安装过程中也许会遇到一些自己解决不了的错误,不要急躁,慢慢找方法解决就好了,希望你能成为一个优秀的程序员。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网