java—尝试将lzo压缩与mapreduce结合使用

jutyujz0  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(468)

我想在mapreduce中使用lzo压缩,但在运行mapreduce作业时出现错误。我正在用一个java程序来使用ubuntu。我只想在本地机器上运行这个。我最初的错误是

ERROR lzo.GPLNativeCodeLoader: Could not load native gpl library

然后继续下去

ERROR lzo.LzoCodec: Cannot load native-lzo without native-hadoop

然后

java.lang.RuntimeException: native-lzo library not available

关于如何下载和配置用于lzo压缩的文件,我遵循了许多联机和文本说明。在这里你可以看到我的hadoop lzo jar文件 lib 文件夹

我已经改变了我的配置。这是我的core-site.xml

<configuration>
<property>
    <name>fs.default.name</name>
    <value>hdfs://localhost:9000</value>
</property>
<property>
    <name>io.compression.codecs</name>
        <value>com.hadoop.compression.lzo.LzoCodec,com.hadoop.compression.lzo.LzopCodec</value>
</property>

<property>
    <name>io.compression.codec.lzo.class</name>
    <value>com.hadoop.compression.lzo.LzoCodec</value>
</property>
<property>
    <name>mapred.output.compress</name>
    <value>true</value>
</property>

<property>
    <name>mapred.output.compression.codec</name>
    <value>com.hadoop.compression.lzo.LzopCodec</value>
</property>
</configuration>

以及我的mapred-site.xml

<configuration>
<property>
    <name>mapred.job.tracker</name>
    <value>localhost:9001</value>
</property>
<property>
    <name>mapred.compress.map.output</name>
    <value>true</value>
</property>
<property>
    <name>mapred.map.output.compression.codec</name>
    <value>com.hadoop.compression.lzo.LzoCodec</value>
</property>
<property>
    <name>mapred.child.env</name>
    <value>JAVA_LIBRARY_PATH=$JAVA_LIBRARY_PATH:/home/matthew/hadoop/lib/native/lib/lib</value>
</property>
</configuration>

我还修改了hadoop-env.sh在同一个conf文件夹中的这些行

export HADOOP_CLASSPATH=/home/hadoop/lib/hadoop-lzo-0.4.13.jar
export JAVA_LIBRARY=/home/hadoop/lib/native/lib/lib

如果你对你的工作感兴趣的话 /home/hadoop/lib/native/lib/lib
值得一提的是,这里是我的驱动程序类,它执行所有的压缩操作

//import java.net.URI;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
//import org.apache.hadoop.filecache.DistributedCache;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
//import org.apache.hadoop.io.compress.CompressionCodec;
import com.hadoop.compression.lzo.LzopCodec;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
//import org.apache.hadoop.mapreduce.lib.output.SequenceFileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

public class FuzzyJoinDriver extends Configured implements Tool{

public static void main(String[] args) throws Exception {     
    int exitCode = ToolRunner.run(new Configuration(), new  FuzzyJoinDriver(),args);
System.exit(exitCode);
}
@Override
public int run(String[] args) throws Exception {
    if (args.length != 2) {
          System.err.println("Usage: FuzzyJoinDriver <input path> <output path>");
          System.exit(-1);
        }

        Configuration conf = new Configuration();
        //Used to compress map output
        //conf.setBoolean("mapred.compres.map.output", true);
        //conf.setClass("mapred.map.output.compression.code", GzipCodec.class, CompressionCodec.class);
        Job job = new Job(conf);
        job.setJarByClass(FuzzyJoinDriver.class);
        job.setJobName("Fuzzy Join");

        //Distributed Cache
        //DistributedCache.addCacheFile(new URI("/cache/ReducerCount.txt"),  job.getConfiguration());

        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));

        job.setMapperClass(FuzzyJoinMapper.class);

        job.setReducerClass(FuzzyJoinReducer.class);
        job.setMapOutputKeyClass(IntWritable.class);
        job.setMapOutputValueClass(RelationTuple.class);

        job.setPartitionerClass(JoinKeyPartitioner.class);

        job.setOutputKeyClass(NullWritable.class);
        job.setOutputValueClass(Text.class);

        //Used to compress output from reducer
        FileOutputFormat.setCompressOutput(job,  true);
        FileOutputFormat.setOutputCompressorClass(job, LzopCodec.class);
        //SequenceFileOutputFormat.setOutputCompressionType(job, org.apache.hadoop.io.SequenceFile.CompressionType.BLOCK);

        return(job.waitForCompletion(true) ? 0 : 1);
    }
}

它编译时没有错误。
我担心我对配置和其他步骤的缺乏理解会导致我走上错误的道路,也许我错过了一些对问题的理解比我更好的简单的东西。谢谢你能走这么远。我知道这是一篇冗长的文章。

yizd12fk

yizd12fk1#

您需要在mapred-site.xml中设置以下属性:

<property>
    <name>mapred.compress.map.output</name>
    <value>true</value>
</property>

<property>
    <name>mapred.map.output.compression.codec</name>
    <value>org.apache.hadoop.io.compress.LzoCodec</value>
</property>

如果要按每个作业执行,还可以通过以下方式之一在代码中直接实现:

conf.set("mapred.compress.map.output", "true")
conf.set("mapred.map.output.compression.codec", "org.apache.hadoop.io.compress.LzoCodec");

jobConf.setMapOutputCompressorClass(LzoCodec.class);

相关问题