cd hadoop-cluster-docker
vim start-container.sh切换到脚本文件夹,使用 Vim 编辑 start-container.sh。在图中光标处添加以下内容,保存并退出。
-p 9000:9000 
重启容器,并查看容器状态,如图即为映射成功。

开启 Web HDFS 管理*
该步非必须。为了方便在网页端管理,因此开启 Web 端,默认关闭。
which hadoop
cd /usr/local/hadoop/etc/hadoop/
lsvi core-site.xml
找到 Hadoop 配置文件路径,使用 Vi 编辑,若 Vi 的插入模式(Insert Mode)中,上下左右变成了 ABCD,那么可以使用以下命令即可:
cp /etc/vim/vimrc ~/.vimrc 修复。
添加以下内容。
<property>
<name>dfs.webhdfs.enabled</name>
<value>true</value>
</property>
启动 Hadoop
同 Linux。
构建依赖
使用 Intellij IDEA 新建一个 Gradle 项目,在 Build.gradle 中加入以下依赖(对应容器 Hadoop 版本)。
compile group: 'org.apache.hadoop', name: 'hadoop-common', version: '2.7.2'
compile group: 'org.apache.hadoop', name: 'hadoop-hdfs', version: '2.7.2'Demo
import org.apache.commons.io.IOUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.*;
import org.junit.Before;
import org.junit.Test;import java.io.FileInputStream;
import java.io.IOException;
import java.net.URI;
/**
* Created by kingcos on 25/03/2017.
*/
public class HDFSOperations {
FileSystem fileSystem;
@Before
public void configure() throws Exception {
Configuration configuration = new Configuration();
configuration.set("fs.defaultFS", "hdfs://192.168.1.120:9000");
fileSystem = FileSystem.get(URI.create("hdfs://192.168.1.120:9000"), configuration, "root");
}
@Test
public void listFiles() throws IOException {
Path path = new Path("/");
RemoteIterator<LocatedFileStatus> iterator = fileSystem.listFiles(path, true);
while (iterator.hasNext()) {
LocatedFileStatus status = iterator.next();
System.out.println(status.getPath().getName());
}
}
@Test
public void rm() throws IOException {










