Flume以Kafka为Source,以Hive为Sink进行数据转存。

业务背景:公司要求将某四川城市的卡口数据实时接入大数据平台中,历史数据可以通过Hive进行Load,也就是增量数据的对接问题。现场设备采集卡口的数据量在400万左右,不多。设备数据采集后由数据对接人员塞到Kafak中。

思路:由Flume读取Kafka中的原数据,可以直接存入Hive中,也可以写入HDFS,再由Hive外部表加载。由于第一种不需要开发代码,只需配置,故采用了第一种。

常见问题处理 :

1、缺少jar包,特别是hcatalog,antlr-runtime-3.4等;

2、batchSize,消费能力要合适Channel,不然会一直报错Failed;

3、Hive建表时需要配置事务,表名小写,这一类错误报错明显,可以相应改正  ;

4、Hive表中是否有数据,不能用“show create table”,直接看select

配置代码如下:

PS:

1、分区问题:不能直接使用Event Header中的TimeStamp,因为考虑到会有一定的延时,处于时间分界时段的数据会分区错误。需regex_extractor解析Body,获取PassTime字段,加入Header,以此分区。

2、过滤问题:某些数据车牌未正确识别,需过滤,使用拦截器。正则表达式使用 | 进行拼接。

server.sources = test_source
server.channels = test_channel
server.sinks = test_sink

# the source configuration of test_source
server.sources.test_source.type = org.apache.flume.source.kafka.KafkaSource
server.sources.test_source.kafka.topics = kakoudata
server.sources.test_source.kafka.consumer.group.id = groupj
server.sources.test_source.kafka.security.protocol = PLAINTEXT
server.sources.test_source.kafka.auto.offset.reset = smallest
server.sources.test_source.batchDurationMillis = 1000
server.sources.test_source.batchSize = 1000
server.sources.test_source.channels = test_channel
server.sources.test_source.interceptors = i1 i2

server.sources.test_source.interceptors.i1.type = regex_filter
server.sources.test_source.interceptors.i1.regex = [\u4e00-\u9fa5]{1}[A-Z]{1}[A-Z0-9]{5}|[\u4e00-\u9fa5]{1}[A-Z]{1}[A-Z0-9]{4}[\\u4e00-\\u9fa5]{1}|WJ[\u4e00-\u9fa5]{1}[A-Z0-9]{5}
server.sources.test_source.interceptors.i1.excludeEvents = false

server.sources.test_source.interceptors.i2.type = regex_extractor
server.sources.test_source.interceptors.i2.regex = (\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)
server.sources.test_source.interceptors.i2.serializers = s1 s2 s3
server.sources.test_source.interceptors.i2.serializers.s1.name = year
server.sources.test_source.interceptors.i2.serializers.s2.name = month
server.sources.test_source.interceptors.i2.serializers.s3.name = day

# the channel configuration of test_channel
server.channels.test_channel.type = memory
server.channels.test_channel.capacity = 10000
server.channels.test_channel.transactionCapacity = 1000
server.channels.test_channel.channlefullcount = 10
server.channels.test_channel.keep-alive = 3
server.channels.test_channel.byteCapacityBufferPercentage = 20

# the sink configuration of test_sink
server.sinks.test_sink.type = hive
server.sinks.test_sink.hive.metastore = thrift://192.168.95.42:21088
server.sinks.test_sink.hive.database = default
server.sinks.test_sink.hive.table = base_kkdata_invalid
server.sinks.test_sink.hive.txnsPerBatchAsk = 2
server.sinks.test_sink.hive.partition = %{year},%{month},%{day}
server.sinks.test_sink.useLocalTimeStamp = false
server.sinks.wulei_sink.hive.batchSize = 10
server.sinks.test_sink.serializer = JSON
server.sinks.test_sink.channel = test_channel

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~我是L分割线...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Hive见表语句:

create table test_wuleiname(id string, name string)
partitioned by (day string)
clustered by (id) into 2 buckets stored as orc
location '/user/hive/warehouse/test_hhh'
TBLPROPERTIES ('transactional'='true');

Flume:sink.type=hive的更多相关文章

  1. flume的sink写入hive表

    flume的配置文件如下: a1.sources=r1 a1.channels=c1 a1.sinks=s1 a1.sources.r1.type=netcat a1.sources.r1.bind= ...

  2. flume sink两种类型 file_rool 自定义sing com.mycomm.MySink even if there is only one event, the event has to be sent in an array

    mkdir /data/UnifiedLog/; cd /data/UnifiedLog/; wget http://mirror.bit.edu.cn/apache/flume/1.8.0/apac ...

  3. 自定义Flume Sink:ElasticSearch Sink

    Flume Sink的目的是从Flume Channel中获取数据然后输出到存储或者其他Flume Source中.Flume Agent启动的时候,它会为每一个Sink都启动一个SinkRunner ...

  4. Flume启动报错[ERROR - org.apache.flume.sink.hdfs. Hit max consecutive under-replication rotations (30); will not continue rolling files under this path due to under-replication解决办法(图文详解)

    前期博客 Flume自定义拦截器(Interceptors)或自带拦截器时的一些经验技巧总结(图文详解)   问题详情 -- ::, (SinkRunner-PollingRunner-Default ...

  5. Flume Sink Processors官网剖析(博主推荐)

    不多说,直接上干货! Flume Sources官网剖析(博主推荐) Flume Channels官网剖析(博主推荐) Flume Channel Selectors官网剖析(博主推荐) Flume ...

  6. 将nginx搜集到的日志通过flume转到hive

    背景介绍: Nginx为app打点数据,打点日志每小时滚动一次.目录结构如下 文件中的数据如下( cat -A 2019072414r.log 后的结果,-A为显示隐形的符号,下方^A为指定的分隔符. ...

  7. IDEA编译Flume Sink通不过解决方法

    Build/Rebuild Project之后

  8. Flume监控指标项

    配置监控 1.修改flume-env.sh export JAVA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmx ...

  9. flume 测试 hive sink

    测试flume,将数据送到hive表中,首先建表. create table order_flume( order_id string, user_id string, eval_set string ...

随机推荐

  1. python--json串相关的loads dumps load dump

    #1 json串长的像字典,但不是字典类型,是str类型 #例如:user_info为json串,dict为字典,如果txt文本中标识dict的内容 为json串user_info = '''{&qu ...

  2. 下载隐含的qq音乐

    最终按Ctrl+s .或者点击“下载”即可.格式可能为m4a

  3. [development][lockless][dpdk] 无锁队列

    dpdk: http://dpdk.org/doc/guides/prog_guide/ring_lib.html#ring-library linux: https://lwn.net/Articl ...

  4. [skill][msgpack] 初试msgpack库以及基本使用

    It's like JSON.   but fast and small. http://msgpack.org/index.html 源码: https://github.com/msgpack/m ...

  5. [skill] mmap / fwrite / write linux磁盘读写的分层结构

    转自:http://www.cnblogs.com/zhaoyl/p/5901680.html 看完此文,题目不言自明.转自 http://blog.chinaunix.net/uid-2710571 ...

  6. python fabric实现远程操作和部署示例

    https://www.jb51.net/article/48434.htm 近期接手越来越多的东西,发布和运维的工作相当机械,加上频率还蛮高,导致时间浪费还是优点多.修复bug什么的,测试,提交版本 ...

  7. 关于.htaccess的设置

    RewriteEngine On #设置是否开始rewrite RewriteBase / #设置开始匹配的目录,比如web程序放在/var/www/html/test下,则这个值要设置为" ...

  8. PLSQL分级取数据

    分级取数据 select employee_id,last_name,job_id,manager_id from employees start with employee_id=101 --emp ...

  9. unittest框架assert断言

    Pthon内部自带了一个单元测试的模块,\ pyUnit也就是:unittest 先介绍下unittest的基本使用方法: 1.import unittest2.定义一个继承自unittest.Tes ...

  10. 敏捷开发之Scrum扫盲篇(转)

    现在敏捷开发是越来越火了,人人都在谈敏捷,人人都在学习Scrum和XP... 为了不落后于他人,我也开始学习Scrum.今天主要是对我最近阅读的相关资料,根据自己的理解,用自己的语言来描述Scrum中 ...