windows10_intellij本地访问虚拟机ubuntu16.04的Hadoop的实现Demo

win 10_intellij本地实现对虚拟机ubuntu16.04的Hadoop-2.7.7的访问Demo

本人初学hadoop,大数据这块实属萌新小白,今天开始慢慢写点hadoop 学习博客,不是教程,只是希望能逐步总结一些学习过程中失败碰壁的经验,给后面的学习道路打下一些基础,争取不要再犯重复类似的错误。如有大佬能抽空指点,本人更是万分感谢。
经过查阅资料和不断尝试,终于实现了在本地idea intellij环境远程访问虚拟机hadoop。
本文的前提是hadoop已经在vm中部署成功了,详细过程可以参阅:http://blog.csdn.net/lsttoy/article/details/52318232。

Hadoop-2.7.7在Ubuntu的配置如下

  1. 控制台输入ifconfig,可以看到该虚拟机的localhost地址是192.168.190.133;
  2. 在core-site.xml文件中我的配置也应当对应起来
  3. hdfs-site.xml配置如下在这里插入图片描述
  4. 在sbin目录下运行./start-hdfs.sh;
  5. 输入jps可以看到结点的信息
  6. 或者打开浏览器输入:192.168.190.133:50070
  7. 使用ubuntu的指令关闭防火墙: sudo ufw disable
  8. 输入netstat -an | grep 9000查看虚拟机9000端口是否打开

windows及Intellij部分相关配置

  1. cmd打开控制台,尝试ping一下虚拟机ip:192.168.190.133:9000,如果能ping通则进入下一步,如果不行,检查虚拟机防火墙、端口状态。
  2. 参考http://blog.csdn.net/lsttoy/article/details/52419138配置intellij的依赖,需要把部分文件从虚拟机拷贝到本机
  3. Intellij 创建Maven 项目,其中pom.xml如下
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.gee.hadoop4</groupId>
    <artifactId>hadoop4</artifactId>
    <version>1.0-SNAPSHOT</version>

    <repositories>
        <repository>
            <id>cloudera</id>
            <url>https://repository.cloudera.com/aritifactory/cloudera-repos/</url>
        </repository>

    </repositories>

    <dependencies>

        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
            <version>2.7.7</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-hdfs</artifactId>
            <version>2.7.7</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-client</artifactId>
            <version>2.7.7</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>

    </dependencies>
</project>
  1. main目录下,source目录下创建core-site.xml文件代码如下
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>



<configuration>
    <property>

        <name>fs.defaultFS</name>
        <value>hdfs://192.168.190.133:9000</value>
    </property>
</configuration>

5.test/java/目录下创建一个测试demo,这里设为HadoopTest_demo,用于输出当前hdfs目录下所有文件

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.net.URI;

/**
 * Created by Gee on 2020/6/29.
 */
public class HadoopTest_demo {
    public static final String HDFS_PATH = "hdfs://192.168.190.133:9000";

    FileSystem fileSystem = null;
    Configuration configuration = null;

    /*罗列hdfs 目录下所有文件*/
    @Test
    public void listStatus() throws Exception{
        FileStatus[] statuses = fileSystem.listStatus(new Path("/"));
        for (FileStatus status : statuses) {
            System.out.println(status);
        }
    }
    @Before
    public void setUp() throws Exception{
        System.out.print("HDFSApp.setUp");
        configuration = new Configuration();
        fileSystem = FileSystem.get(new URI(HDFS_PATH),configuration);

    }

    @After
    public void tearDown() throws Exception{

        configuration = null;
        fileSystem = null;

        System.out.print("HDFSApp.tearDown");


    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值