复习总结03:辅助系统Azkaban/flume/sqoop

…………………………………………………………………………………………一、Flume…………………………………………………………………………………………………………

一、Flume概述:
分布式,高可靠,高可用海量日志采集、聚合和传输系统。通过对flume设置来实现采集需求。
flume可以采集文件,socket数据包等各种形式源数据  输出到HDFS,Hbase,Hive,Kafka。
用agent对象来完成采集和输出
①source采集数据源------channel内部数据传输通道------sink下沉地数据目的地
不用设置hdfs,flume自己定位

二、案例①  监控某个文件的变化把新文件采集到HDFS上
设置好文件路径执行: bin/flume-ng   agent    -c     conf     -f      conf/tail-hdfs.conf    -n    a1
设置好flume对某文件的监听
然后执行
1
while true
2
do
3
echo ********** >> /home/hadoop/log/test.log
4
sleep 1
5
done
观察hdfs上flume/events/17-08-14/1630/log-.1502699961742   发现日志文件滚动生成

tail-hdfs.conf文件如下
1
# Name the components on this agent
2
a1.sources = r1
3
a1.sinks = k1
4
a1.channels = c1
5
 
        
6
#exec 指的是命令
7
# ………………………………………………………………描述数据源………………………………………………………………
8
a1.sources.r1.type = exec
9
#F根据文件名追中, f根据文件的nodeid追中
10
a1.sources.r1.command = tail -F /home/hadoop/log/test.log
11
a1.sources.r1.channels = c1
12
 
        
13
# ………………………………………………………………描述数据终点……………………………………………………
14
#下沉目标
15
a1.sinks.k1.type = hdfs
16
a1.sinks.k1.channel = c1
17
#指定目录, flum帮做目的替换
18
a1.sinks.k1.hdfs.path = /flume/events/%y-%m-%d/%H%M/
19
#文件的命名, 前缀
20
a1.sinks.k1.hdfs.filePrefix = events-
21
 
        
22
#10 分钟就改目录
23
a1.sinks.k1.hdfs.round = true
24
a1.sinks.k1.hdfs.roundValue = 10
25
a1.sinks.k1.hdfs.roundUnit = minute
26
 
        
27
#文件滚动之前的等待时间(秒)
28
a1.sinks.k1.hdfs.rollInterval = 3
29
 
        
30
#文件滚动的大小限制(bytes)
31
a1.sinks.k1.hdfs.rollSize = 500
32
 
        
33
#写入多少个event数据后滚动文件(事件个数)
34
a1.sinks.k1.hdfs.rollCount = 20
35
 
        
36
#5个事件就往里面写入
37
a1.sinks.k1.hdfs.batchSize = 5
38
 
        
39
#用本地时间格式化目录
40
a1.sinks.k1.hdfs.useLocalTimeStamp = true
41
 
        
42
#下沉后, 生成的文件类型,默认是Sequencefile,可用DataStream,则为普通文本
43
a1.sinks.k1.hdfs.fileType = DataStream
44
 
        
45
# Use a channel which buffers events in memory
46
a1.channels.c1.type = memory
47
a1.channels.c1.capacity = 1000
48
a1.channels.c1.transactionCapacity = 100
49
 
        
50
# Bind the source and sink to the channel
51
a1.sources.r1.channels = c1
52
a1.sinks.k1.channel = c1

三、案例②  监控某个文件夹下的文件
备注:只能往该文件夹下放文件 mv test.log /home/hadoop/log    不能内部生成才会监测到,并且将文件的内部信息输出到con
执行:bin/flume-ng   agent     -c     ./conf     -f       ./conf/spool-logger.conf      -n     a1     -Dflume.root.logger=INFO,console
移动某文件到该监测文件夹 :  mv test.log  /home/hadoop/log
此时控制台输出文件内容 每一行输出一次:{ headers:{file=/home/hadoop/log/words.txt} body: 68 65 6C 6C 6F 20 74 6F 6D                    hello tom }

spool-logger.conf文件如下
1
# Name the components on this agent
2
a1.sources = r1
3
a1.sinks = k1
4
a1.channels = c1
5
 
        
6
# 描述数据源
7
a1.sources.r1.type = spooldir
8
a1.sources.r1.spoolDir = /home/hadoop/flumespool       //指定监听的文件夹
9
a1.sources.r1.fileHeader = true
10
 
        
11
# Describe the sink
12
a1.sinks.k1.type = logger
13
 
        
14
# Use a channel which buffers events in memory
15
a1.channels.c1.type = memory
16
a1.channels.c1.capacity = 1000
17
a1.channels.c1.transactionCapacity = 100
18
 
        
19
# Bind the source and sink to the channel
20
a1.sources.r1.channels = c1
21
a1.sinks.k1.channel = c1


四、关于命令解析
1
 bin/flume-ng agent   -c  ./conf   -f ./conf/spool-logger.conf   -n a1   -Dflume.root.logger=INFO,console

-c   conf      指定flume自身的配置文件所在目录

-f   conf/netcat-logger.conf     指定采集方案的脚本文件

-n  a1     指定这agent的名字

-Dflume.root.logger=INFO,console    控制台输出

./flume-ng agent 命令  -c conf文件夹 -f 配置文件  -n a1  配置agent

……………………………………………………………………………………………二、Azkaban…………………………………………………………………………………………………………

Azkaban概述
       一个完整的数据分析系统通常都是由大量任务单元组成:shell脚本程序,java程序,mapreduce程序、hive脚本等各任务单元。
这些任务之间存在时间先后及前后依赖关系为了很好地组织起这样的复杂执行计划,需要一个工作流调度系统来调度执行;

 

例如,我们可能有这样一个需求,某个业务系统每天产生20G原始数据,我们每天都要对其进行处理,处理步骤如下所示:

1、 通过Hadoop先将原始数据同步到HDFS上;

2、 借助MapReduce计算框架对原始数据进行转换,生成的数据以分区表的形式存储到多张Hive表中;

3、 需要对Hive中多个表的数据进行JOIN处理,得到一个明细数据Hive大表;

4、 将明细数据进行复杂的统计分析,得到结果报表信息;

5、 需要将统计分析得到的结果数据同步到业务系统中,供业务调用使用。



………………………………………………………………………………………………三、sqoop…………………………………………………………………………………………………………

一、sqoop概述:

sqoopapache旗下一款Hadoop和关系数据库服务器之间传送数据”的工具。

导入数据MySQLOracle导入数据到HadoopHDFSHIVEHBASE等数据存储系统;

导出数据:Hadoop的文件系统中导出数据到关系数据库

 

 

将导入或导出命令翻译成mapreduce程序来实现运算框架仍然还是:MapReduce!

在翻译出的mapreduce中主要是对inputformatoutputformat进行定制

运算中会出现hackdata的检查,发现不存在,暂未解决

二、MySQL的操作
MySQL创建数据表:
A:MySQL中创建数据表emp ,emp_add ,emp_conn 
mysql> create table emp(
> id int(4) ,
> name char(20) ,
> sex int(4) ,
> degree double(16,2));

B:导入数据文件  emp.txt     # 文件内的每个元素之间用Tab分开
load data local infile  '/home/hadoop/emp.txt' into table emp;


三、sqoop导入导出数据表操作:
从本地MySQL------->>>>------hdfs:
①、MySQL中 数据库userdb的数据表emp导入到hdfs中   其数据库文件放在           /user/hadoop/emp
./sqoop import   --connect jdbc:mysql://localhost:3306/userdb     --username root     --password root   --table emp     --m 1
                                                指定MySQL下的数据库userdb                             root名                root的密码            导入的数据表 

②、MySQL中 数据库userdb的数据表emp_add导入到hive中,其数据库文件放在/user/hive/emp_add  在hive> 下能查看到新的表emp_add (先放在hadoop下,后移动到hive下

./sqoop import   --connect jdbc:mysql://localhost:3306/userdb   --username root    --password root   --table emp_add   --hive-import  --m 1

                                                                                                                                                                                                          指定是导入到hive中

③、MySQL中 数据库的userdb的数据表emp_conn导入到hdfs的指定文件夹下 
./sqoop import     --connect jdbc:mysql://localhost:3306/userdb      --username root     --password root      --target-dir /queryresult                --table emp_conn --m 1                                                                                                                                                     指定导入的文件夹  

从hdfs-------->>>>------本地MySQL               
④、hdfs上的数据表,导出到本地的MySQL中。首先,要先在本地新建一个同样的表,名字可以不同,格式要同

./sqoop export   --connect jdbc:mysql://localhost:3306/userdb     --username root    --password root     --table employee 

--export-dir /user/hadoop/emp/                                                                                                            指定导出后,保存到本地的数据表名

  指定导出的数据表


执行语句:./sqoop import    --connect 连接数据库  --用户名  --密码  --表(MySQL里的)  --导入模式  --m 1



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值