1.hdfs系统会把用到的数据存储在core-site.xml中由hadoop.tmp.dir指定,而这个值默认位于/tmp/hadoop-${user.name}下面, 由于/tmp目录在系统重启时候会被删除,所以应该修改目录位置。 修改core-site.xml(在所有站点上都修改)
<property>
<name>hadoop.tmp.dir</name>
<value>/var/hadoop</value>
</property>
2.第一次启动时要讲namenode format一下 hdfs namenode format
3.通过java访问hdfs程序,就把hdfs集群当成一个大的系统磁盘就行了
4.windows上的权限系统和linux上的权限系统,测试期间为了简单起见可以关闭权限检查 在namenode的hdfs-site.xml上,添加配置:
<
property
>
<
name
>dfs.permissions.enabled</
name
>
<
value
>false</
value
>
</
property
>
重新启动namenode hadoop-daemon.sh stop namenode hadoop-daemon.sh start namenode
URL.setURLStreamHandlerFactory(
new
FsUrlStreamHandlerFactory());
IOUtils.copyBytes(in, System.out,
4096
,
true
);
6.使用fileSystem类
Configuration conf =
new
Configuration();
FileSystem fileSystem = FileSystem.get(conf);
boolean
b = fileSystem.exists(
new
Path(
"/hello"
));
System.out.println(b);
boolean
success = fileSystem.mkdirs(
new
Path(
"/mashibing"
));
System.out.println(success);
success = fileSystem.delete(
new
Path(
"/mashibing"
),
true
);
System.out.println(success);
FSDataOutputStream out = fileSystem.create(
new
Path(
"/test.data"
),
true
);
FileInputStream fis =
new
FileInputStream(
"c:/test/core-site.xml"
);
IOUtils.copyBytes(fis, out,
4096
,
true
);
FileStatus[] statuses = fileSystem.listStatus(
new
Path(
"/"
));
//System.out.println(statuses.length);
for
(FileStatus status : statuses) {
System.out.println(status.getPath());
System.out.println(status.getPermission());
System.out.println(status.getReplication());
}