(10) 访问 Web 界面 http://名称节点IP地址:50070 查看 NameNode 和 Datanode 信息。
时间: 2024-03-10 22:47:55 浏览: 164
以下是Java代码示例,可以通过Java代码实现访问Web界面 http://名称节点IP地址:50070 查看NameNode和DataNode的信息:
```java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class HadoopWebInterface {
public static void main(String[] args) {
try {
String url = "http://名称节点IP地址:50070/";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
int responseCode = con.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(new InputStreamReader(
con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
} else {
System.out.println("访问失败,错误码:" + responseCode);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
```
该代码通过HTTPURLConnection实现访问Hadoop管理界面,并输出界面内容。可以将“名称节点IP地址”替换为实际的节点IP地址。
阅读全文