我试图在Windows上运行Java代码以使用redhat 7.7访问virtualbox 6.1中的Hadoop 3.1.3。
具有所有组件(NameNode,datanode等)正常工作的Hadoop。
19856 NameNode
20864 NodeManager
20274 SecondaryNameNode
20532 ResourceManager
20043 DataNode
创建端口前言VBox后,我可以从Windows显示hadoop数据节点和群集
主机IP 127.0.0.1
必需IP 192.168.122.1
用于以下端口:
9870
80888
9000
9866
9864
9869
9865
9867
] 1
Hadoop可以正常工作,并且可以在主机和gust上显示
可从http://localhost:8088/cluster
上的窗口访问
可从http://192.168.122.1:8088
上的Linux红帽访问
可通过http://localhost:9870/
上的窗口浏览器访问
可通过http://192.168.122.1:9870
上的Linux红帽浏览器访问
Linux /ect/hosts
######127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
####::1 localhost localhost.localdomain localhost6 localhost6.localdomain6q
192.168.122.1 master.hadoop master
Virsualbox网络:
NAT
Java代码在virtualbox上成功运行(与hadoop一起使用gust),但无法在Windows(主机)上成功运行
import java.io.IOException;
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
public class HadoopFileSystemCat {
public static void main(String[] args) throws IOException {
String uri = "hdfs://localhost:9000/TES";
Configuration conf = new Configuration();
conf.set("fs.hdfs.impl","org.apache.hadoop.hdfs.DistributedFileSystem");
FileSystem fs = FileSystem.get(URI.create(uri),conf);
FSDataInputStream in = null;
try {
in = fs.open(new Path(uri));
System.out.println(fs.getFileBlockLocations(new Path(uri),0)[0]);
System.out.println(fs.getFileBlockLocations(new Path(uri),0)[0].getNames()[0]);
IOUtils.copyBytes(in,System.out,4096,false);
} finally {
IOUtils.closeStream(in);
}
}
}
代码输出
0,10,localhost
192.168.122.1:9866
异常消息
Exception in thread "main" org.apache.hadoop.hdfs.BlockMissingException: Could not obtain block: BP-428104912-127.0.0.1-1586539199175:blk_1073741825_1001 file=/DDD
at org.apache.hadoop.hdfs.DFSInputStream.refetchLocations(DFSInputStream.java:875)
at org.apache.hadoop.hdfs.DFSInputStream.chooseDataNode(DFSInputStream.java:858)
at org.apache.hadoop.hdfs.DFSInputStream.chooseDataNode(DFSInputStream.java:837)
at org.apache.hadoop.hdfs.DFSInputStream.blockSeekTo(DFSInputStream.java:566)
at org.apache.hadoop.hdfs.DFSInputStream.readWithStrategy(DFSInputStream.java:756)
at org.apache.hadoop.hdfs.DFSInputStream.read(DFSInputStream.java:825)
at java.io.DataInputStream.read(DataInputStream.java:100)
at org.apache.hadoop.io.IOUtils.copyBytes(IOUtils.java:94)
at org.apache.hadoop.io.IOUtils.copyBytes(IOUtils.java:68)
at com.mycompany.hdfs_java_api.HadoopFileSystemCat.main(HadoopFileSystemCat.java:39)
实际上我们可以通过终端看到的
[muneeralnajdi@localhost hadoop]$ bin/hdfs dfs -ls /
Found 1 items
-rw-r--r-- 1 muneeralnajdi supergroup 10 2020-04-10 20:25 /DDD
Hadoop配置
Core-site.xsml
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://master.hadoop:9000</value>
</property>
</configuration>
yarn-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:/home/muneeralnajdi/hadoop_store/hdfs/namenode</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/home/muneeralnajdi/hadoop_store/hdfs/datanode</value>
</property>
<property>
<name>dfs.client.use.datanode.hostname</name>
<value>true</value>
<description>Whether clients should use datanode hostnames when
connecting to datanodes.
</description>
</property>
<property>
<name>dfs.namenode.http-address</name>
<value>master.hadoop:9870</value>
</property>
</configuration>
hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:/home/muneeralnajdi/hadoop_store/hdfs/namenode</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/home/muneeralnajdi/hadoop_store/hdfs/datanode</value>
</property>
<property>
<name>dfs.client.use.datanode.hostname</name>
<value>true</value>
<description>Whether clients should use datanode hostnames when
connecting to datanodes.
</description>
</property>
<property>
<name>dfs.namenode.http-address</name>
<value>master.hadoop:9870</value>
</property>
</configuration>
任何人都可以帮助我解决此问题
我回答了一些问题
Access to file on Hadoop Virtualbox Cluster
但是Java API仍然无法从Windows访问datanode块