配置JAVA项目以在不同(虚拟)机器上使用hadoop

时间:2014-03-05 10:52:40

标签: java maven hadoop

我在Intellij Idea本地有一个maven项目,我想将其设置为使用我在虚拟机上安装的Hadoop。有什么建议吗?

我在本地使用Windows 8.1,在虚拟机上使用Ubuntu 12.0.4。我已经在那里安装了Hadoop并且它正在工作。

编辑: VM上的Hadoop设置: 芯的site.xml

<configuration>
<property>
  <name>hadoop.tmp.dir</name>
  <value>/app/hadoop/tmp</value>
  <description>A base for other temporary directories.</description>
</property>

<property>
  <name>fs.default.name</name>
  <value>hdfs://localhost:54310</value>
  <description>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.</description>
</property>

</configuration>

和mapred-site.xml

<configuration>
<property>
  <name>mapred.job.tracker</name>
  <value>localhost:54311</value>
  <description>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.
  </description>
</property>

</configuration>

和hdfs-site.xml

<configuration>
<property>
  <name>dfs.replication</name>
  <value>1</value>
  <description>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.
  </description>
</property>

</configuration>

我的虚拟机(vmware播放器)上的网络是NAT,IP地址是192.168.35.128。

然后,我在Intellij Idea中有一个简单的java项目(dint认为这很重要但无论如何......),这是我的配置:

String hdfsUrl = "hdfs://192.168.36.128:54310";
FileSystem hdfs;
final Configuration config = new Configuration();
config.set(FS_DEFAULT_NAME, hdfsUrl);
 try {
            hdfs = FileSystem.get(config);
            if (hdfs != null) {
                hdfsAvailable = true;
            } else {
                throw new IOException("Unable to get hdfs, is NULL");
            }
        } catch (IOException e) {
            logger.warn(e.toString());
        }

当我开始时,我收到以下错误:

  

java.io.IOException:没有用于scheme的文件系统:hdfs

显然,我错过了一些东西。我的操作系统是Windows 8,而VM则是Ubuntu。

重要编辑编号2:

  

telnet 192.168.36.128 54310

是成功的,但是从应用程序中找不到任何东西......

4 个答案:

答案 0 :(得分:1)

这是我的日食(没有任何插件)。

Configuration configuration = new Configuration();
    configuration.set("fs.defaultFS", "hdfs://name-node:8020");
    FileSystem fs = FileSystem.get(configuration);


    Path filePath = new Path(
            "hdfs://name-node:8020/user/test/000000_0");

答案 1 :(得分:1)

我之前见过这个错误。我在客户端的类路径中缺少hadoop-hdfs jar。在您的情况下,想法项目是hdfs客户端。 “hdfs”方案在HdfsConstants.java中定义,该方法打包在hadoop-hdfs.jar中。由于hdfs可以在项目外部访问,因此缺少类是最可能的问题。尝试在构建路径中添加hadoop-hdfs和hadoop-common。

我假设您正在使用hadoop 2.X

答案 2 :(得分:1)

由于类路径中缺少库 hadoop-hdfs - * .jar 而发生此错误。对于访问HDFS文件系统,如果你添加hadoop-hdfs - * .jar就不能解决这个问题,需要关注依赖项。

hadoop-hdfs-*.jar
hadoop-common-*.jar
dependecy jars inside common/lib directory.

答案 3 :(得分:1)

使用配置对象添加配置文件

 Configuration conf = new Configuration();
     conf.addResource(new Path("/path of file /core-site.xml"));
     conf.addResource(new Path("/path of file /hdfs-site.xml"));
相关问题