gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 14:28:56 26 4
gpt4 key购买 nike

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

我在本地有 Windows 8.1,在虚拟机上有 Ubuntu 12.0.4。我已经在那里安装了 Hadoop 并且它正在运行。

编辑:VM 上的 Hadoop 设置:核心站点.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 player)上的网络是NAT,ip地址是192.168.35.128。

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

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: No FileSystem for scheme: hdfs

很明显我错过了一些东西。我的操作系统是 Windows 8,VM 上是 Ubuntu。

重要编辑 No.2:

telnet 192.168.36.128 54310

成功了,但是应用程序还是什么都没有...

最佳答案

发生此错误是由于类路径中缺少库 hadoop-hdfs-*.jar。访问HDFS文件系统,单独添加hadoop-hdfs-*.jar无法解决问题,需要依赖如下。

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

关于java - 配置 JAVA 项目以在不同的(虚拟)机器上使用 hadoop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22195640/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com