文件上载时报错 org.apache.hadoop.security.AccessControlException:Permission denied

来源:互联网 发布:js判断数字是否为整数 编辑:程序博客网 时间:2024/06/05 19:34

最近开始学习Hadoop,刚刚写了个向HDFS中上载文件的java程序,结果总是报错

Exception in thread "main" org.apache.hadoop.security.AccessControlException: org.apache.hadoop.security.AccessControlException: Permission denied: user=lzy,access=WRITE, inode="":root:supergroup:rwxr-xr-xat sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)at java.lang.reflect.Constructor.newInstance(Constructor.java:513)at org.apache.hadoop.ipc.RemoteException.instantiateException(RemoteException.java:95)at org.apache.hadoop.ipc.RemoteException.unwrapRemoteException(RemoteException.java:57)at org.apache.hadoop.hdfs.DFSClient.mkdirs(DFSClient.java:1428)at org.apache.hadoop.hdfs.DistributedFileSystem.mkdirs(DistributedFileSystem.java:332)at org.apache.hadoop.fs.FileSystem.mkdirs(FileSystem.java:1126)</span>
后来才发现是hdfs-site.xml中的配置写错了,应该是
<pre name="code" class="html"><span style="font-size:18px;"> <property>    <name>dfs.permissions</name>    <value>false</value>  </property></span>
我写成了dfss.permissions,太粗心了!

修改完成后重启Hadoop,就可以啦!

PS:关闭Hadoop命令:stop-all.sh
开启Hadoop命令:start-all.sh
附上刚刚写的上载文件的小程序,方便以后查看:
import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.net.URI;import java.net.URISyntaxException;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.FSDataOutputStream;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.IOUtils;public class App2 {public static void main(String[] args) throws IOException, URISyntaxException {final  String path = "hdfs://hadoop:9000";final String PATH_DIR = "/d2";final String PATH_FILE = "/d2/d3";FileSystem fileS = FileSystem.get(new URI(path), new Configuration());fileS.mkdirs(new Path(PATH_DIR));FSDataOutputStream out = fileS.create(new Path(PATH_FILE));FileInputStream in = new FileInputStream("D://log.txt");IOUtils.copyBytes(in, out, 1024,true);}}



0 0
原创粉丝点击