【自学笔记】Hadoop基础知识点总览-持续更新
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
- Hadoop基础知识点总览
- 1. Hadoop简介
- 2. Hadoop生态系统
- 3. HDFS(Hadoop Distributed File System)
- HDFS基本命令
- 4. MapReduce
- WordCount示例(Java)
- 5. YARN(Yet Another Resource Negotiator)
- 6. 其他组件简介
- 总结
Hadoop基础知识点总览
1. Hadoop简介
Hadoop是一个由Apache基金会所开发的分布式系统基础架构,它能利用集群的威力进行高速运算和存储。用户可以在不了解分布式底层细节的情况下,开发分布式程序。充分利用集群的威力进行高速运算和存储。
2. Hadoop生态系统
Hadoop生态系统包含了多个组件,其中最重要的是HDFS(Hadoop Distributed File System)和MapReduce。其他重要的组件还包括YARN(Yet Another Resource Negotiator)、Hive、HBase、Zookeeper、Sqoop、Flume等。
3. HDFS(Hadoop Distributed File System)
HDFS是Hadoop的分布式文件系统,具有高容错性的特点,并且设计用来部署在低廉的硬件上。它提供高吞吐量的数据访问,适合那些有着超大数据集的应用程序。
HDFS基本命令
以下是一些HDFS的基本命令示例:
# 启动HDFS
start-dfs.sh
# 查看HDFS上的文件列表
hdfs dfs -ls /
# 在HDFS上创建一个目录
hdfs dfs -mkdir /user/hadoop/data
# 将本地文件上传到HDFS
hdfs dfs -put localfile.txt /user/hadoop/data/
# 从HDFS下载文件到本地
hdfs dfs -get /user/hadoop/data/localfile.txt ./
# 删除HDFS上的文件
hdfs dfs -rm /user/hadoop/data/localfile.txt
4. MapReduce
MapReduce是一种编程模型和处理大量数据的框架。它基于一个“Map(映射)”函数,用来把一组键值对映射成另一组键值对,以及一个“Reduce(归约)”函数,用来保证所有映射的键值对中的每一个中间键值对都恰好被归约一次。
WordCount示例(Java)
以下是一个简单的WordCount程序的Map和Reduce函数示例:
// Mapper类
public class WordCountMapper extends Mapper<LongWritable, Text, Text, LongWritable> {
private final static LongWritable one = new LongWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String line = value.toString();
String[] words = line.split("\\s+");
for (String str : words) {
word.set(str);
context.write(word, one);
}
}
}
// Reducer类
public class WordCountReducer extends Reducer<Text, LongWritable, Text, LongWritable> {
public void reduce(Text key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {
long sum = 0;
for (LongWritable val : values) {
sum += val.get();
}
context.write(key, new LongWritable(sum));
}
}
// 主类
public class WordCount {
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "word count");
job.setJarByClass(WordCount.class);
job.setMapperClass(WordCountMapper.class);
job.setCombinerClass(WordCountReducer.class);
job.setReducerClass(WordCountReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(LongWritable.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
5. YARN(Yet Another Resource Negotiator)
YARN是Hadoop的资源管理器,负责为应用程序分配系统资源。它将资源管理功能和应用程序调度/监控功能分开,使得Hadoop能够运行更多种类的应用程序。
6. 其他组件简介
- Hive:一个数据仓库软件,可以将结构化的数据文件映射为一张数据库表,并提供类SQL查询功能。
- HBase:一个分布式的、可扩展的大数据存储系统,支持对大数据的随机、实时读写访问。
- Zookeeper:一个为分布式应用提供一致性服务的开源项目,它主要是用来解决分布式环境中数据一致性的问题。
希望这个示例对你有所帮助!你可以根据自己的需要添加更多的内容或代码块。如果你有任何其他问题或需要进一步的帮助,请随时提问。
总结
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,自学记录Hadoop基础知识点总览。