eclipse里搭建hadoop环境遇到的问题

0.依赖的jar包
share\hadoop\common\hadoop-common-2.8.0.jar
share\hadoop\common\lib\全部
share\hadoop\hdfshadoop-hdfs-2.8.0.jar
share\hadoop\hdfs\lib\全部
重复的部分覆盖即可;

1.Caused by: java.lang.IllegalArgumentException: Wrong FS: hdfs:/, expected: file:///  
        at org.apache.hadoop.fs.FileSystem.checkPath(FileSystem.java:642)  

解决:需要将core-site.xml和hdfs-site.xml文件拷贝到eclipse中工程的src目录下

2.log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.lang.IllegalArgumentException: java.net.UnknownHostException: hserver1

解决:如果配置的是系统名称,如:hserver1,将配置文件中的系统名称改成ip,如:192.168.229.141

3.Exception in thread "main" org.apache.hadoop.security.AccessControlException: Permission denied: user=luxuefeng, access=WRITE, inode="/":root:supergroup:drwxr-xr-x
at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.check(FSPermissionChecker.java:310)

解决:需要设置window用户访问hadoop目录的权限
run as中选择run configration,配置Arguments参数,将-DHADOOP_USER_NAME设置为linux环境中配置时的用户
-DHADOOP_USER_NAME=root
但这样每个方法都要配置,
终极解决:初始化时指定用户
public void init() throws IOException, InterruptedException, URISyntaxException{
Configuration conf = new Configuration();
fs = FileSystem.get(new URI("hdfs://192.168.229.141:9000/"),conf,"root");
}

4.java.lang.RuntimeException: java.io.FileNotFoundException: java.io.FileNotFoundException: HADOOP_HOME and hadoop.home.dir are unset. -see https://wiki.apache.org/hadoop/WindowsProblems
at org.apache.hadoop.util.Shell.getWinUtilsPath(Shell.java:716)
测试下载方法时遇到的,
/**
* 下载文件
* @throws IOException 
* */
@Test
public void download() throws IOException{
//下载时,源路径和目标路径刚好相反
Path local = new Path("hdfs://192.168.229.141:9000/baidu_url.txt");
Path dst = new Path("G:/baidu_url3.txt");

fs.copyToLocalFile(local, dst);
}

Problems running Hadoop on Windows
Hadoop requires native libraries on Windows to work properly -that includes to access the file:// filesystem, where Hadoop uses some Windows APIs to implement posix-like file access permissions.
This is implemented in HADOOP.DLL and WINUTILS.EXE.
In particular, %HADOOP_HOME%\BIN\WINUTILS.EXE must be locatable.
If it is not, Hadoop or an application built on top of Hadoop will fail.
How to fix a missing WINUTILS.EXE
You can fix this problem in two ways
Install a full native windows Hadoop version. The ASF does not currently (September 2015) release such a version; releases are available externally.
Or: get the WINUTILS.EXE binary from a Hadoop redistribution. There is a repository of this for some Hadoop versions on github.
Then
Set the environment variable %HADOOP_HOME% to point to the directory above the BIN dir containing WINUTILS.EXE.
Or: run the Java process with the system property hadoop.home.dir set to the home directory.

解决:将安装在cent os中的hadoop.tar.gz解压在windows一份。
然后重点在这里,仅仅解压缩了这个hadoop的包还不够,还需要这俩东西:hadoop.dll和winutils.exe下载链接及其附属(hadoop.exp、hadoop.lib、hadoop.pdb、libwinutils.lib、winutils.pdb)。缺少会报错,我在报错前已经把这俩及其相关的东西都放上了,所以不知会报啥错。再说一点如果版本不一致会报java.lang.UnsatisfiedLinkError:org.apache.hadoop.io.nativeio.NativeIO$Windows.createDirectoryWithMode0(Ljava/lang/String;I)V错误 
在你的环境变量中的系统变量中配置了HADOOP_HOME并且指向hadoop程序包的本目录即可(如我本机就是D:\hadoop-2.8.0),并且在系统变量的path中附加了%HADOOP_HOME%\bin及%HADOOP_HOME%\sbin就能在你的windows上运行hadoop程序了,然后重启电脑。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值