2014-03-30 76 views
0

我想从群集外创建HDFS文件(HDFS的API),像这样:Hadoop的远程文件创建失败

Configuration conf = new Configuration(); 
conf.set("mapred.job.tracker", "192.168.56.101:54310"); 

conf.set("fs.default.name", "hdfs://192.168.56.101:54311"); 

FileSystem fs = FileSystem.get(conf); 

fs.createNewFile(new Path("/app/hadoop/tmp/data/tools.txt")); 

四处错误:

Exception in thread "main" org.apache.hadoop.ipc.RemoteException: java.io.IOException: Unknown protocol to job tracker: org.apache.hadoop.hdfs.protocol.ClientProtocol 
at org.apache.hadoop.mapred.JobTracker.getProtocolVersion(JobTracker.java:370) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:622) 
at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:587) 
at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1432) 
at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1428) 
at java.security.AccessController.doPrivileged(Native Method) 
at javax.security.auth.Subject.doAs(Subject.java:416) 
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1190) 
at org.apache.hadoop.ipc.Server$Handler.run(Server.java:1426) 
at org.apache.hadoop.ipc.Client.call(Client.java:1113) 
at org.apache.hadoop.ipc.RPC$Invoker.invoke(RPC.java:229) 
at $Proxy1.getProtocolVersion(Unknown Source) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
at java.lang.reflect.Method.invoke(Method.java:597) 
at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:85) 
at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:62) 
at $Proxy1.getProtocolVersion(Unknown Source) 
at org.apache.hadoop.ipc.RPC.checkVersion(RPC.java:422) 
at org.apache.hadoop.hdfs.DFSClient.createNamenode(DFSClient.java:183) 
at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:281) 
at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:245) 
at org.apache.hadoop.hdfs.DistributedFileSystem.initialize(DistributedFileSystem.java:100) 
at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:1446) 
at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:67) 
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:1464) 
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:263) 
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:124) 
at LineCounter.main(LineCounter.java:107) 

回答

0

的Namenode暴露了两个端口一个是ipc端口(默认为8020)和WebUI(默认为50070)。对于从远程机器访问HDFS文件系统,不需要设置属性mapred.job.tracker只有fs.default.name就足够了,并确保您使用正确的hdfs相关库版本作为群集,namenode可从远程机器访问。

在连接到远程hdfs之前,通过检查群集中anynodes或edgenode的core-site.xml文件来找到fs.default.name(默认为8020)的值。您可以确保IPC端口的正确与否在任何节点执行以下命令

hadoop fs -ls hdfs://192.168.56.101:54310/ 

如果你能在conf.set方法访问HDFS你可以给(以上hdsf URI)

0

您可以请检查名称节点和Jobtracker deamons是否正在运行,您提到的端口是否正确。

0

我用下面的,它为我的作品在Linux VM单节点集群上:

Configuration conf = new Configuration(); 
     conf.set("fs.default.name", "hdfs://localhost:9000"); 

我建议你尝试9000的端口号,否则找出需要正确的端口号可以从您的Hadoop配置文件“site-core.xml”中使用。我的文件是这样的:

<?xml version="1.0"?> 
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?> 
<configuration> 
    <property> 
    <name>fs.default.name</name> 
    <value>hdfs://localhost:9000</value> 
    </property> 
    <property> 
    <name>hadoop.tmp.dir</name> 
    <value>~/hacking/hd-data/tmp</value> 
    </property> 
    <property> 
    <name>fs.checkpoint.dir</name> 
    <value>~/hacking/hd-data/snn</value> 
    </property> 
</configuration> 

此外,作为sachinjose指出,我建议过您删除从您的代码如下:

conf.set("mapred.job.tracker", "192.168.56.101:54310"); 
+0

更正端口信息,但现在越来越以下错误。导致:org.apache.hadoop.ipc.RemoteException:org.apache.hadoop.security.AccessControlException:权限被拒绝:user = user,access = WRITE,inode =“data”:hduser:supergroup:rwxr-xr-x(用户是windows用户名,集群用户名是hduser) – user1927808