繁体   English   中英

在类路径中找不到Hadoop配置,使用Java在本地服务器中运行mapreduce

[英]Cannot find Hadoop Configuration in classpath, running mapreduce in server from local using Java

所以,

import java.io.IOException;
import java.util.Properties;

import org.apache.pig.ExecType;
import org.apache.pig.PigServer;


public class CommitPig {

    public static void main(String[] args)
    {
        try{
        String pigScript = "category_count.pig";
        pigScriptReader psReader = new pigScriptReader();
        psReader.readPigScript( pigScript );
        } catch ( IOException e){
            e.printStackTrace();
        }

        try{
            Properties props = new Properties();
            props.setProperty("fs.default.name", "<server id>");
            props.setProperty("mapred.job.tracker.http.address", "<server id>");
            props.setProperty("<server id> ");
            PigServer pigServer = new PigServer( ExecType.MAPREDUCE, props); 
            runIdQuery(pigServer,"<input location>");

        } catch ( Exception e){
            e.printStackTrace();
        }

    }

    private static void runIdQuery(PigServer pigServer, String inputFile) throws IOException {

        pigServer.registerQuery("A = load '" + inputFile + "' using PigStorage(' ');");
        pigServer.registerQuery("B = filter A BY $0 == 'testing';");
        pigServer.store("B","id.out");

    }
}

到目前为止,这是我正在运行的代码。

我正在尝试使用Java从本地连接到群集服务器,以运行Pig查询。

它给我错误

ERROR 4010: Cannot find hadoop configurations in classpath (neither hadoop-site.xml nor core-site.xml was found in the classpath)

我尝试按照apache的指示在集群中设置类路径。

以Mapreduce模式运行Pig脚本要以mapreduce模式运行Pig脚本,请执行以下操作:

  1. 将PIG_CLASSPATH环境变量设置为群集配置目录的位置(该目录包含core-site.xml,hdfs-site.xml和mapred-site.xml文件): export PIG_CLASSPATH=/mycluster/conf

  2. 将HADOOP_CONF_DIR环境变量设置为集群配置目录的位置: export HADOOP_CONF_DIR=/mycluster/conf

但是我仍然遇到相同的错误。 我在这里理解错了吗? 有人可以帮助我了解这里的问题是什么以及如何解决吗?

谢谢 !

export HADOOP_HOME=/path/to/hadoop

奔猪再次为我修复了它

尝试:

HADOOP_CLASSPATH=/mycluster/conf

您也可以检查hadoop-env.sh脚本,以查看在其中设置了什么类路径。

请添加conf文件夹作为-classpath的参数。 那应该工作

 -classpath /home/nubes/pig/conf:/home/nubes/hadoop/conf;

您必须在“属性”文件中将属性“ pig.use.overriden.hadoop.configs”设置为true,PigServer将使用文件中定义的属性,而不是在类路径中查找配置文件

导出HADOOP_CLASSPATH = $ HADOOP_HOME / etc / hadoop

我在maven的pom.xml中包含了hadoop配置文件(core-site.xml和mapred-site.xml)。

<build>
...
<resources>
<resource>
<director>[hadoop-directory]/etc/hadoop</directory>
<includes>
<include>core-site.xml</include>
<include>mapred-site.xml</include>
</includes>
</resource>
</resources>
...
</build>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM