使用HadoopDruidIndexer向Druid集群中加载批量数据-Batch Data Ingestion

使用HadoopDruidIndexer向Druid集群中加载批量数据-Batch Data Ingestion

 Druid  lxw1234@qq.com  3年前 (2015-11-19)  9780℃  2评论

关键字:druid,HadoopDruidIndexer,Batch Data Ingestion

有两种方式将批量数据加载到Druid集群中,使用Indexing Service或者HadoopDruidIndexer。

本文介绍如何使用HadoopDruidIndexer向Druid集群中加载批量数据。

如何选择批量数据的加载方式

Indexing Service作为Druid集群的一部分,运行在多个节点上,可以完成一些不同类型的Indexing任务,Indexing Service里面包含了元数据存储和管理的功能,启动后,外部系统可以以编程方式来与之互相协作,完成周期性的Indexing任务。

HadoopDruidIndexer通过运行Hadoop job来完成segments的分隔和索引,如果已经有Hadoop平台,大量数据的Indexing任务,通过HadoopDruidIndexer来完成会更加效率。

使用HadoopDruidIndexer加载批量数据

使用HadoopDruidIndexer加载批量数据时,会启动MapReduce任务,将数据生成segments文件,存放在HDFS上,同时向Druid metastore中写入segments元数据。

Coordinator Node监控元数据中有新增的segments,会将指令写入Zookeeper,而Historical Node监控到Zookeeper中的指令之后,从HDFS上下载segments文件到本地。

之后,该批量数据便可从Druid中查询。

特别注意:由于DeepStorage使用了HDFS,因此_common配置文件common.runtime.properties中的druid.extensions.coordinates需要加入:io.druid.extensions:druid-hdfs-storage,特别是Historical Node和Coordinator Node需要使用这个,如果之前没有加,这两个服务需要重启。

另外,在运行过程中如果有Hadoop相关的类找不到,则需要将相关jar包加入CLASSPATH。

我这里采用了简单粗暴的做法:在启动Historical Node和Coordinator Node时候,将HADOOP_CLASSPATH全部加入,即在run_historical.sh和run_coordinator.sh中增加:DRUID_CP=”${DRUID_CP}:`hadoop classpath`”

注:运行这两个Node的机器上装有Hadoop Client,并配置好了环境变量。

HadoopDruidIndexer配置文件

需要编写一个spec文件,用于配置数据源及相关信息。

我的源数据存储在HDFS/hivedata/warehouse/liuxiaowen.db/lxw_drui_testdata/目录下,数据有三个字段,timestamp、cookieid、ip

vi hadoopindex.spec

 
  1. {
  2. "dataSchema": {
  3. "dataSource": "lxw1234",
  4. "parser": {
  5. "type": "string",
  6. "parseSpec": {
  7. "format": "csv",
  8. "timestampSpec": {
  9. "column": "timestamp",
  10. "format" : "yyyy-MM-dd HH:mm:ss"
  11. },
  12. "dimensionsSpec": {
  13. "dimensions": [
  14. "cookieid",
  15. "ip"
  16. ],
  17. "dimensionExclusions": [],
  18. "spatialDimensions": []
  19. },
  20. "listDelimiter" : ",",
  21. "columns" : ["timestamp","cookieid","ip"]
  22. }
  23. },
  24. "metricsSpec": [
  25. {
  26. "type": "count",
  27. "name": "count"
  28. }
  29. ],
  30. "granularitySpec": {
  31. "type": "uniform",
  32. "segmentGranularity": "DAY",
  33. "queryGranularity": "NONE",
  34. "intervals" : ["2015-11-01/2015-12-01"]
  35. }
  36. },
  37. "ioConfig": {
  38. "type": "hadoop",
  39. "inputSpec" : {
  40. "type" : "static",
  41. "paths" : "hdfs://cdh5/hivedata/warehouse/liuxiaowen.db/lxw_drui_testdata/000000_0,hdfs://cdh5/hivedata/warehouse/liuxiaowen.db/lxw_drui_testdata/000001_0"
  42. },
  43. "metadataUpdateSpec" : {
  44. "type":"mysql",
  45. "connectURI" : "jdbc:mysql:\/\/127.0.0.102:3306\/druid",
  46. "password" : "druid",
  47. "segmentTable" : "druid_segments",
  48. "user" : "druid"
  49. },
  50. "segmentOutputPath" : "hdfs:\/\/cdh5\/tmp\/data\/index\/output"
  51. },
  52. "tuningConfig" : {
  53. "type" : "hadoop",
  54. "workingPath": "\/tmp\/druid",
  55. "partitionsSpec" : {
  56. "type" : "dimension",
  57. "partitionDimension" : null,
  58. "targetPartitionSize" : 5000000,
  59. "maxPartitionSize" : 7500000,
  60. "assumeGrouped" : false,
  61. "numShards" : -1
  62. },
  63. "shardSpecs" : { },
  64. "leaveIntermediate" : false,
  65. "cleanupOnFailure" : true,
  66. "overwriteFiles" : false,
  67. "ignoreInvalidRows" : false,
  68. "jobProperties" : { },
  69. "combineText" : false,
  70. "persistInHeap" : false,
  71. "ingestOffheap" : false,
  72. "bufferSize" : 134217728,
  73. "aggregationBufferRatio" : 0.5,
  74. "rowFlushBoundary" : 300000
  75. }
  76. }

运行HadoopDruidIndexer MapReduce任务

使用下面的命令,运行HadoopDruidIndexer MapReduce任务:

 
  1. java -Xmx256m -Duser.timezone=GMT+8 -Dfile.encoding=UTF-8 -classpath /home/liuxiaowen/druid-0.8.1/config/_common/common.runtime.properties:\
  2. /home/liuxiaowen/druid-0.8.1/lib/*:/etc/hadoop/conf \
  3. io.druid.cli.Main index hadoop /home/liuxiaowen/druid-0.8.1/hadoopindex.spec

MapReduce完成后,将新的segments写入元数据MySQL:

druid.io

druid.io

Coordinator Node从元数据中发现新的segments,给Historaical发送Load指令:

druid.io

Historical Node监测到指令,Load新的segments:

druid.io

查询加载的数据

编写查询配置文件,按天统计记录数:

vi timeseries2.json

 
  1. {
  2. "queryType": "timeseries",
  3. "dataSource": "lxw1234",
  4. "intervals": [ "2015-11-15/2015-11-18" ],
  5. "granularity": "day",
  6. "aggregations": [
  7. {"type": "longSum", "fieldName": "count", "name": "total_count"}
  8. ]
  9. }

执行查询(这里指定的是Broker Node的地址):

 
  1. curl -X POST 'http://node2:8092/druid/v2/?pretty' -H 'content-type: application/json' -d @tieries2.json

druid.io

有一个问题,还是时间格式的问题,显示的仍然是UTC时间,待解决。

接下来将学习Druid提供的各种查询类型。

您可以关注 lxw的大数据田地 ,或者 加入邮件列表 ,随时接收博客更新的通知邮件。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值