hadoop linux集群设置,和windows远程调用集群

hadoop linux集群设置

1.安装jdk1.8以上。设置环境变量。

2.安装hadoop,设置环境变量。

3.修改配置文件。

  • 环境安装好之后可以登录网站查看:
  • 集群情况:http://192.168.37.207:9870/dfshealth.html#tab-overview
  • yarn节点情况:http://192.168.37.207:8088/cluster

windows远程调用集群

一.windows系统环境设置

1.拷贝linux集群hadoop文件夹复制到linux系统

2.配置windows环境,hosts。

3.安装对应版本的hadoop.dll、winutils.exe。

二.windows远程调用集群计算

1.项目构成-代码附在最后

  • wordMapper:map()方法
  • wordReduce:reduce()方法
  • wordCount:提交作业到集群运行
  • resource:linux集群文件拷贝过来
    在这里插入图片描述

2.设置运行环境

在这里插入图片描述
(1)mainclass格式都是:包名.类名
(2)program arguments:运行程序时需要两个参数,一个是输入文件,一个是结果输出路径。
其中第一个路径及文件必须是已经存在的,第二个参数中的output目录必须是不存在的(hdfs会自己创建输出文件,文件已存在会报错)。
在这里插入图片描述
(3)Working directory:工作路径,选择你本地安装的hadoop的路径。

3.提交job之后在网页查看任务运行状况

  • IDE运行截图
    在这里插入图片描述
  • 网页截图:
    在这里插入图片描述
  • 可以看到任务提交次数和运行status,history查看详细记录。
    在这里插入图片描述

代码Wordcount

public class WordCount {
    private static String uri="hdfs://master:9000";
    private static String log4jPropertiesPath="/log4j.properties";
    private static String owner="wy";
    public static void main(String[] args) throws Exception {

        System.setProperty("hadoop.home.dir", "D:\\hadoop-3.1.2");
        Configuration conf = new Configuration();

        //远程操作配置
        //配置了fs.defaultFS选项,则下面的setInputPaths等配置不需要再配置前缀
        conf.set("fs.defaultFS", uri);
        //MapReduce运行环境为yarn
        conf.set("mapreduce.framework.name", "yarn");
        //yarn的recourseManager的主机名
      //  conf.set("yarn.resourcemanager.hostname", "192.168.37.207");
        //表示MapReduce是跨平台运行的
        conf.set("mapreduce.app-submission.cross-platform", "true");
        //设置jar包位置
        conf.set("mapred.jar","C:\\javaProject\\idealProject\\Hadoop\\hadoopdemo\\build\\libs\\hadoopdemo-1.0-SNAPSHOT.jar");

        Job job = Job.getInstance(conf,"myTask-1");

        job.setMapperClass(WordMapper.class);
        job.setReducerClass(WordReducer.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(LongWritable.class);

        //设置文件输入类型和文件输出类型

        //参数代入文件
//        String[] otherArgs = new GenericOptionsParser(conf,args).getRemainingArgs();
//        //若每次传入的数据量不是两个,则显示报错信息。
//        if (otherArgs.length !=2) {
//            System.err.println("Usage: wordcount <in> <out>");
//            System.exit(2);
//        }
//        FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
//        FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));

        //代码写入文件
        FileInputFormat.addInputPath(job, new Path("/input/wordcount/"));
        FileOutputFormat.setOutputPath(job, new Path("/output/wordcount/resultOf_"+job.getJobName()));

        //job.waitForCompletion(true);
        System.exit(job.waitForCompletion(true)? 0 : 1);
    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值