端口号
http://192.168.172.172:50070http://taomaster:8088/clusterhttp://taomaster:19888/50090 NN
sbin/mr-jobhistory-daemon.sh stop historyserversbin/yarn-daemon.sh stop nodemanagersbin/yarn-daemon.sh stop resourcemanagerhadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.10.1.jar wordcount /user/tao/input /user/tao/output
配置文件
rsync -rvl xxx root@tao01:/opt/ #不同节点复制xsync bin/ #分发echo $PATH #查看可以加入的类似环境变量
任务管理
crontab -e #创建systemctl crond restarttail -f xxx #查看内容crontab -l #查看crontab -r #删除
对于副本数的设置:
代码中设置>idea里面的配置>集群中中site配置>默认配置
删除节点:
rm -rf data/ logs/bin/hdfs namenode -format #格式化hdfs oev -p XML -i edits_0000000000000000123-0000000000000000123 -o edist.xml #用于查看edits文件hdfs oiv -i inputfile -o outputfile -P process #用于查看Hadoop fsimage inputfile: 要查看的fsimage文件 outputfile: 用于保存格式化之后的文件 process: 使用什么进程解码,XML|Web|...
hadoop archive -archiveName input.har -p /tao /output #小文件压缩hdfs dfs -ls -R har:///output/input.har #小文件压缩查看hadoop fs -expunge #清空回收站
快照
hdfs dfsadmin -allowSnapshot /taohdfs dfs -createSnapshot /taohdfs snapshotDiff /tao . .snapshot/s20201211-073639.540
MapReduce—计算
MrAppMaster:整个程序过程调度和状态协调,一个job老大
MapTask:Map阶段的处理流程
ReduceTask:Reduce阶段处理流程
MapReduce框架原理
Hadoop序列化特点:
1.紧凑:高效使用存储空间
2.快速:读写数据的额外开销小
3.可扩展:随着通信协议的升级而升级
4.互操作:支持多语言交互
自定义bean对象实现序列化接口
给集群提交哪些东西:
1.切片
2.xml
3.jar包
FileInputForma切片源码:
max(minSize,min(maxSize,blocksize)) 默认值:1,Long,128M(本地是32M)
1.1倍
FileInputFormat:
以文件为单位的,key是偏移量,value是内容
CombineTextInputFormat:
合并小文件
设置setMaxInputSplitSize
切片多少,就开多少个MapTask
KeyValueTextInputFormat
key是第一个单词,value是之后内容
conf.set(KeyValueLineRecordReader.KEY_VALUE_SEPERATOR," ");job.setInputFormatClass(KeyValueTextInputFormat.class);
NLineInputFormat
自定义InputFormat
区别和联系
1.TextInputFormat 文件个数 k是偏移量,v是内容 Mapper
2.KeyValueTextInputFormat 同上 k是切片后第一列内容,v是一行剩余内容 Mapper
3.NLineInputFormat 按行切片 k是偏移量,v是内容 Mapper
4.CombineTextInputFormat 取决设定最大值,小于该值,会合并一起,若大于则要除以2 默认 Mapper
5.自定义 默认切片 与定义有关(Text,BytesWritable) Mapper
Shuffle机制
Partition分区
1.自定义类继承Partitioner
2.job驱动设置
job.setPartitionerClass(ProviderPaatition.class);job.setNumReduceTasks(3);
3.设置ReduceTask(和分区相同)
debug注意
1.不要在Driver里面打断点
优化:
job.setCombinerClass(WordcountCombiner.class);public class WordcountCombiner extends Reducer <Text, IntWritable, Text, IntWritable> {@Overrideprotected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {int sum = 0;//1.累加求和for(IntWritable value : values) {sum += value.get();}//2.写出context.write(key, new IntWritable(sum));}}
分割常识:
\t 相当于tab,缩进
\n 回车
\r 换行
\s 作为分隔符表示空白
设置ReduceTask并行度
job.setNumReduceTasks();
OutputFormat数据输出
1.TextOutputFormat
2.SequenceFileoutputFormat
3.自定义OutputFormat
a.自定义一个类继承FileOutputFormatb.改写RecordWriter,具体改写输出数据的方法write()
自定义Format案例:日志根据内容的分类
参照com.tao.mr.outputformat
Join多种应用
表的合并
Reduce Join
com.tao.mr.order
Map join
com.tao.mr.cache
一张表小,一张表大
注意:job.setNumReduceTask(0) 减少Shuff,减少IO
数据清洗
需求:去除日志中字段长度小于11的日志
压缩
IO密集,多压缩
——————————Map——————————Reduce——————————
扩 展名匹配 LZO Snappy
Yarn资源调度器
基本架构:ResorceManager、NodeManager、ApplicatioMaster、Container等组件
MapReduce慢原因
1.计算机性能:CPU、内存、磁盘、网络
2.IO操作优化:数据倾斜、Map和Reduce数设置不合理、Map久使Reduce等待久、小文件过多、大量不可分块的超大文件、Spill次数过多、Merge次数过多
MapReduce优化方法:
1.数据输入
合并小文件 CombineTextInputFormat
2.Map阶段
a.减少Spill次数,调整io.sort.mb(环形缓冲区100M)和sort.spill.percent(到达80%),较少磁盘IO
b.减少合并次数,调整io.sort.factor,增大Merge文件的数目,减少Merge次数
c.不影响业务前提下,先进性Combine,减少IO
3.Reduce阶段
a.合理设置Map和Reduce数
b.设置Map和Reduce共存,调整slowstart.completemaps
c.规避使用Reduce
d.合理设置Reduce端的buffer,mapred.job.reduce.input.buffer.percent,默认是0
4.IO传输
压缩数据,减少网络IO时间,Snappy和LZO编码
使用SequenceFile二进制文件 作为中间值 格式紧凑 可以把小文件封装一起
5.数据倾斜问题
频率、大小
a.抽样和范围分区
b.自定义分区
c.使用Combine
d.采用Map Join
6.常用参数设置
资源相关 mapred-default.xml yarn-default.xml
mapreduce.map.memory.mb MapTask可用资源上限,默认1G
mapreduce.map.cpu.vcores cpu核数,默认1
mapreduce.task.io.sort.mb Shuff缓冲区大小
容错…
HDFS小文件优化
小文件多会在NameNode建立过多的索引
1.数据采集
a.合成大文件上传HDFS
b.业务处理前,使用MapReduce程序对小文件合并
1.Sequence File
2.Hadoop Archive
3.CombineFileInputFprmat(合成一个单独的Split)
4.开启JVM重用 mapreduce.job.jvm.numtasks 10-20
面试
几种排序:
1.部分排序
2.全排序
3.辅助排序(GroupComparator)除了他其他都在map阶段
4.二次排序(bean对象多个条件,判断条件为两个)
5.自定义排序(bean对象)
