当前位置: 首页 > news >正文

阿里云搭建hadoop集群服务器,内网、外网访问问题(详解。。。)

  这个问题花费了我将近两天的时间,经过多次试错和尝试,现在想分享给大家来解决此问题避免大家入坑,以前都是在局域网上搭建的hadoop集群,并且是局域网访问的,没遇见此问题。

因为阿里云上搭建的hadoop集群,需要配置映射集群经过内网访问,也就是局域网的ip地址。

  如果配置为公网IP地址,就会出现集群启动不了,namenode和secondarynamenode启动不了,如果将主机的映射文件配置为内网IP集群就可以正常启动了。但通过eclipse开发工具访问

会出错,显示了阿里云内网的ip地址来访问datanode,这肯定访问不了啊,这问题真实醉了,就这样想了找了好久一致没有思路。

  最终发现需要在hdfs-site.xml中修改配置项dfs.client.use.datanode.hostname设置为true,就是说客户端访问datanode的时候是通过主机域名访问,就不会出现通过内网IP来访问了

最初查看日志发现:

一、查看日志

1. less hadoop-hadoop-namenode-master.log 

 2.less hadoop-hadoop-secondarynamenode-master.log 

二、解决集群访问问题

1.查看hosts映射文件

上面是公网IP需要替换为内网IP

然后正常搭建hadoop集群

2.core-site.xml

<!-- 指定HADOOP所使用的文件系统schema(URI),HDFS的老大(NameNode)的地址 -->
<property>
    <name>fs.defaultFS</name>
    <value>hdfs://master:9000</value>
</property>
<!-- 指定hadoop运行时产生文件的存储目录 -->
<property>
    <name>hadoop.tmp.dir</name>
    <value>/home/hadoop/BigData/hadoop-2.7.3/data</value>
</property>

3.hadoop-env.sh 修改export JAVA_HOME值

export JAVA_HOME=/home/hadoop/BigData/jdk1.8

4.hdfs-site.xml 注意:添加一个dfs.client.use.datanode.hostname配置

<!-- 指定namenode的http通信地址 -->
<property>
    <name>dfs.namenode.secondary.http-address</name>
    <value>master:50090</value>
</property>
<!-- 指定HDFS副本的数量 -->
<property>
    <name>dfs.replication</name>
    <value>1</value>
</property>
<property>
    <name>dfs.permissions</name>
    <value>false</value>
</property>
<!-- 如果是通过公网IP访问阿里云上内网搭建的集群 -->
<property>
    <name>dfs.client.use.datanode.hostname</name>
    <value>true</value>
    <description>only cofig in clients</description>
</property>

5.mapred-site.xml

<!-- 指定mr运行在yarn上 -->
<property>
    <name>mapreduce.framework.name</name>
    <value>yarn</value>
</property>
<!-- jobhistory的address -->
<property>
    <name>mapreduce.jobhistory.address</name>
    <value>master:10020</value>
</property>
<!-- jobhistory的webapp.address -->
<property>
    <name>mapreduce.jobhistory.webapp.address</name>
    <value>master:19888</value>
</property>

6. yarn-site.xml

<!-- 指定YARN的老大(ResourceManager)的地址 -->
<property>
    <name>yarn.resourcemanager.hostname</name>
    <value>master</value>
</property>
<!-- reducer获取数据的方式 -->
<property>
    <name>yarn.nodemanager.aux-services</name>
    <value>mapreduce_shuffle</value>
</property>

7.hadoop namenode -format格式化,然后启动start-all.sh

 8.在本地IDE环境中编写单词统计测试集群访问

public class WordCount {
    public static class TokenizerMapper extends Mapper<LongWritable, Text, Text, IntWritable>{
        private final static IntWritable one = new IntWritable(1);
        private Text word = new Text();
        @Override
        protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, IntWritable>.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 WordCountReducer extends Reducer<Text, IntWritable, Text,IntWritable>{
            private IntWritable result = new IntWritable();
            @Override
            protected void reduce(Text key, Iterable<IntWritable> values,
                    Reducer<Text, IntWritable, Text, IntWritable>.Context context)
                    throws IOException, InterruptedException {
                    int sum = 0;
                    for(IntWritable item:values) {
                        sum += item.get();
                    }
                    result.set(sum);
                    context.write(key, result);
            }
        }
        public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
            Configuration conf = new Configuration();
            String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
            if(otherArgs.length < 2) {
                System.err.println("Usage: wordcount <in> [<in>....] <out>");
                System.exit(2);
            }
            Job job = Job.getInstance(conf, "word count");
            job.setJarByClass(WordCount.class);
            job.setMapperClass(TokenizerMapper.class);
            job.setCombinerClass(WordCountReducer.class);
            job.setReducerClass(WordCountReducer.class);
            job.setOutputKeyClass(Text.class);
            job.setOutputValueClass(IntWritable.class);
            for(int i = 0; i < otherArgs.length -1; i++) {
                FileInputFormat.addInputPath(job, new Path(otherArgs[i]));
            }
            FileSystem fs = FileSystem.get(conf);
            Path output = new Path(otherArgs[otherArgs.length - 1]);
            if(fs.exists(output)) {
                fs.delete(output, true);
                System.out.println("output directory existed! deleted!");
            }
            FileOutputFormat.setOutputPath(job, output);
            System.exit(job.waitForCompletion(true) ? 0 : 1);
        }
    }
}

9.运行的时候配置一个数据的存放路径和数据的输出路径位置

10 . 正常运行并访问了阿里云的hadoop集群

转载于:https://www.cnblogs.com/ya-qiang/p/10076424.html

相关文章:

  • 枚举与switch组合使用
  • 如何用纯 CSS 创作一个货车 loader
  • 阿里云马劲:保证云产品持续拥有稳定性的实践和思考
  • C# 获取对象 大小 Marshal.SizeOf (sizeof 只能在不安全的上下文中使用)
  • Oracle-SQL*Plus 简单操作
  • thinkphp 使用paginate分页搜索带参数
  • Money去哪了- 每日站立会议
  • ethereumjs/merkle-patricia-tree-2-API
  • 腾讯音乐赴美IPO仅11亿美元,疑受科技股抛售和中美贸易战影响
  • 【quick-cocos2d-lua】 基本类及用法
  • mysql安装时无法启动服务解决方案
  • Linux初级运维(十五)——bash脚本编程之函数
  • Hystrix断路器在微服务网关中的应用
  • 怎么把工作型PPT制作的好看又专业?
  • git切换分支
  • ----------
  • [rust! #004] [译] Rust 的内置 Traits, 使用场景, 方式, 和原因
  • 10个最佳ES6特性 ES7与ES8的特性
  • HTTP中的ETag在移动客户端的应用
  • IndexedDB
  • MobX
  • nodejs:开发并发布一个nodejs包
  • Nodejs和JavaWeb协助开发
  • python_bomb----数据类型总结
  • vue数据传递--我有特殊的实现技巧
  • yii2中session跨域名的问题
  • 解决jsp引用其他项目时出现的 cannot be resolved to a type错误
  • 开源SQL-on-Hadoop系统一览
  • 那些被忽略的 JavaScript 数组方法细节
  • 容器服务kubernetes弹性伸缩高级用法
  • 无服务器化是企业 IT 架构的未来吗?
  • 在Unity中实现一个简单的消息管理器
  • #宝哥教你#查看jquery绑定的事件函数
  • (3)llvm ir转换过程
  • (6)【Python/机器学习/深度学习】Machine-Learning模型与算法应用—使用Adaboost建模及工作环境下的数据分析整理
  • (论文阅读笔记)Network planning with deep reinforcement learning
  • (三)Honghu Cloud云架构一定时调度平台
  • (四)图像的%2线性拉伸
  • (一)为什么要选择C++
  • (幽默漫画)有个程序员老公,是怎样的体验?
  • (正则)提取页面里的img标签
  • .NET Core引入性能分析引导优化
  • .net6+aspose.words导出word并转pdf
  • @zabbix数据库历史与趋势数据占用优化(mysql存储查询)
  • [ 蓝桥杯Web真题 ]-布局切换
  • [].slice.call()将类数组转化为真正的数组
  • [《百万宝贝》观后]To be or not to be?
  • [acwing周赛复盘] 第 69 场周赛20220917
  • [Android]Android开发入门之HelloWorld
  • [Android]通过PhoneLookup读取所有电话号码
  • [Angular 基础] - 数据绑定(databinding)
  • [BZOJ] 1001: [BeiJing2006]狼抓兔子
  • [CF482B]Interesting Array
  • [emacs] CUA的矩形块操作很给力啊
  • [hdu 2896] 病毒侵袭 [ac自动机][病毒特征码匹配]