Apache atlas集成CDH管理元数据

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tom_fans/article/details/85506662

先简单说明一下元数据管理的重要性,做数仓的时候,自然就会有很多报表,当你有几百个报表,几千张表的时候,现在有个需求需要修改一个表,然后有人问你,修改这个表会影响哪些报表? 如果你仅仅凭借记忆是完全不可行的,必须要有一个平台来管理数据的数据。

知道了元数据的意义,那么从技术角度要做到什么程度才算是一个好的元数据管理呢? 从我个人的认知,表的元数据必须做到字段级别,也就是说修改了一个字段,你查询元数据 系统就知道,这个字段会 影响谁。这个元数据属于数据库元数据,通常来说是HIVE, HBASE或者 传统数据库, 除此之外,还有报表的元数据,一个报表一般会用到3-4个SQL,大部分是图形展示了,也有表格 ,那么再深入的问一个问题,如果我修改了 某个表的一个字段,请问会影响哪个报表的哪个图表? 如果你能通过元数据系统回答这个问题 ,那么就算做的还不错了。

apache atlas就属于 元数据管理系统,整个原理是通过在HIVE/HBASE等 组件建立 HOOK,如果你不知道什么是HOOK,去谷歌一下,所有在HIVE/HBASE的操作都会通过HOOK发送到KAFKA,然后atlas后台会去接收KAFKA的数据,并分析处理,最后输出到HBASE, 前段通过SOLR进行查询,展示。atlas可以分到字段级别的血缘关系。

按照上面的原理,我们知道,我们要构建atlas需要HBASE, SOLR, KAFKA作为技术栈,来支持元数据系统的构建,接下来我们一步一步来,不要急。建议一定要先看官方文档,再来参考我的文章,因为我不会像官方那么详细。

1. 编译atlas,选择最新版1.1

mvn clean -DskipTests install

很遗憾,这一步会出错,出错的原因是因为 POM.XML文件 有一个包的版本 有问题,至于为什么,我不知道,我 换了一个新版本就编译通过。如果你们编译出错了 ,看是否同一个错误 。我换成3.0.5就正常了。

               <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>findbugs-maven-plugin</artifactId>
                    <version>3.0.5</version>
                </plugin>

接下来 打包:

mvn clean -DskipTests package -Pdist

然后会生成以下目录,带有bin字样的tar包就是我们要的东西。

total 548640
-rw-r--r--. 1 root root      5696 Dec 30 12:39 apache-atlas-1.1.0-migration-exporter.zip
drwxr-xr-x. 3 root root      4096 Dec 30 12:39 apache-atlas-1.1.0-migration-exporter
-rw-r--r--. 1 root root  10252779 Dec 30 12:39 apache-atlas-1.1.0-sources.tar.gz
drwxr-xr-x. 3 root root      4096 Dec 30 12:39 apache-atlas-1.1.0-bin
-rw-r--r--. 1 root root 271170401 Dec 30 12:39 apache-atlas-1.1.0-bin.tar.gz
drwxr-xr-x. 3 root root      4096 Dec 30 12:39 apache-atlas-1.1.0-server
-rw-r--r--. 1 root root 177258240 Dec 30 12:39 apache-atlas-1.1.0-server.tar.gz
drwxr-xr-x. 3 root root      4096 Dec 30 12:39 apache-atlas-1.1.0-kafka-hook
-rw-r--r--. 1 root root   9023238 Dec 30 12:39 apache-atlas-1.1.0-kafka-hook.tar.gz
drwxr-xr-x. 3 root root      4096 Dec 30 12:39 apache-atlas-1.1.0-storm-hook
-rw-r--r--. 1 root root  39016518 Dec 30 12:39 apache-atlas-1.1.0-storm-hook.tar.gz
drwxr-xr-x. 3 root root      4096 Dec 30 12:38 apache-atlas-1.1.0-sqoop-hook
-rw-r--r--. 1 root root   8980455 Dec 30 12:38 apache-atlas-1.1.0-sqoop-hook.tar.gz
drwxr-xr-x. 3 root root      4096 Dec 30 12:38 apache-atlas-1.1.0-falcon-hook
-rw-r--r--. 1 root root   9000436 Dec 30 12:38 apache-atlas-1.1.0-falcon-hook.tar.gz
drwxr-xr-x. 3 root root      4096 Dec 30 12:38 apache-atlas-1.1.0-hive-hook
-rw-r--r--. 1 root root  20286530 Dec 30 12:38 apache-atlas-1.1.0-hive-hook.tar.gz
drwxr-xr-x. 3 root root      4096 Dec 30 12:38 apache-atlas-1.1.0-hbase-hook
-rw-r--r--. 1 root root  16626614 Dec 30 12:38 apache-atlas-1.1.0-hbase-hook.tar.gz
drwxr-xr-x. 2 root root      4096 Dec 30 12:38 archive-tmp
-rw-r--r--. 1 root root     96087 Dec 30 12:38 atlas-distro-1.1.0.jar
drwxr-xr-x. 2 root root      4096 Dec 30 12:38 maven-archiver
drwxr-xr-x. 3 root root      4096 Dec 30 12:38 test-classes
drwxr-xr-x. 2 root root      4096 Dec 30 12:38 META-INF
drwxr-xr-x. 3 root root      4096 Dec 30 12:38 maven-shared-archive-resources
drwxr-xr-x. 2 root root      4096 Dec 30 12:38 bin
drwxr-xr-x. 5 root root      4096 Dec 30 12:38 conf
-rw-r--r--. 1 root root      2775 Dec 30 12:38 rat.txt

2. 构建SOLR,KAFKA, HBASE

 实际上CDH本身有KAFKA,HBASE,SOLR等组件,KAFKA, HBASE我都是直接用CDH的,所以不用自己去安装,但是atlas1.1版本对SOLR要求好象是5.0以上,而CDH现在的SOLR还是4+版本 ,迫于无奈,我简单的构建了一个SOLR5.5 standalone。 下载SOLR5.5.1,然后 直接bin/solr start即可。

atlas需要3个索引,我们需要先建立好,之后初始化的时候会在这些索引插入数据:

  $SOLR_BIN/solr create -c vertex_index -d SOLR_CONF -shards #numShards -replicationFactor #replicationFactor
  $SOLR_BIN/solr create -c edge_index -d SOLR_CONF -shards #numShards -replicationFactor #replicationFactor
  $SOLR_BIN/solr create -c fulltext_index -d SOLR_CONF -shards #numShards -replicationFactor #replicationFactor

SOLR_CONF在atlas的conf里面可以找到,默认编译后,所有东西atlas都帮 你准备好了。

3. 修改atlas-application.properties

我用的是solr standalone,所以注释掉solr cloud的配置,  卡夫卡的 配置必须以atlas.kafka为前缀,有一个配置手动添加:

atlas.kafka.max.poll.interval.ms=300000, 默认没有,但是启动服务器收信息会出现ERROR。下面我以HIVE为例子,所以添加了 HIVE HOOK的配置。

#Hbase
atlas.graph.storage.backend=hbase
atlas.graph.storage.hbase.table=apache_atlas_janus

#Solr
#Solr cloud mode properties
#atlas.graph.index.search.solr.mode=cloud
#atlas.graph.index.search.solr.zookeeper-url=
#atlas.graph.index.search.solr.zookeeper-connect-timeout=60000
#atlas.graph.index.search.solr.zookeeper-session-timeout=60000
#atlas.graph.index.search.solr.wait-searcher=true

#Solr http mode properties
atlas.graph.index.search.solr.mode=http
atlas.graph.index.search.solr.http-urls=http://xxxxx:8983/solr

#########  Notification Configs  #########
atlas.notification.embedded=false
atlas.kafka.data=${sys:atlas.home}/data/kafka
atlas.kafka.zookeeper.connect=xxxx:2181,xxxxx:2181,xxxx:2181
atlas.kafka.bootstrap.servers=xxxx:9092,xxx:9092,xxxx:9092,xxxxx:9092
atlas.kafka.zookeeper.session.timeout.ms=400
atlas.kafka.zookeeper.connection.timeout.ms=200
atlas.kafka.zookeeper.sync.time.ms=20
atlas.kafka.auto.commit.interval.ms=1000
atlas.kafka.hook.group.id=atlas

atlas.kafka.enable.auto.commit=false
atlas.kafka.auto.offset.reset=earliest
atlas.kafka.session.timeout.ms=30000
atlas.kafka.offsets.topic.replication.factor=1
atlas.kafka.poll.timeout.ms=1000
atlas.kafka.max.poll.interval.ms=300000

#Hive
atlas.hook.hive.synchronous=false
atlas.hook.hive.numRetries=3
atlas.hook.hive.queueSize=10000
atlas.cluster.name=primary

4. 添加HIVE参数,由于atlas使用的是JDK1.8,所以确保你的HADOOP环境,或者说HIVE的JDK也是1.8,否者会报错

5. 启动atlas , 这个玩意使用的还是python2+, 如果你的python是3+, 建议单独安装2+,再启动,否者会报python的错误。

python2.6 bin/atlas_start.py

很遗憾,这个地方会报错,报错信息为can't load configuration,官方文档让我们把atlas的配置文件放到HIVE的配置目录下,事实上atlas根本就读不到这个配置,因此需要额外操作,把配置加入到HOOK目录下的atlas-plugin-classloader-1.1.0.jar 这个包:

zip -u atlas-plugin-classloader-1.1.0.jar  atlas-application.properties 

再次重启atlas, 打开日志,你会看到atlas正在初始化,会在HBASE,SOLR插入初始化数据,如果不报错的话,大概1-2分钟就OK了。

在这里 要提一下,因为要和HIVE/HBASE集成,很多人会直接在HADOOP服务器找一台机器来安装atlas,这是因为导入初始元数据的时候,会要求 你指定HIVE/HADOOP目录,如果你用别的机器,你根本就没有什么HIVE/HADOOP目录,我的做法是 ,先在HIVE机器上做,做完之后关闭服务,在别的机器用相同的配置启动 服务即可。

6. 通过import_hive.sql 导入初始化HIVE元数据

atlas安装并启动完之后,这个时候系统还是空空如也,atlas是 通过HOOK去监听你的HIVE语句,所以一般我们会通过atlas的import_hive.sh先把HIVE里的表,数据库等信息全部导入到atlas, 之后如果表有操作,通过接收KAFKA的数据再进行处理。

按照官方文档的命令:

<atlas package>/hook-bin/import-hive.sh

很遗憾,这个地方还是会报错,报错 有2个原因:

1)默认hook的lib包不在import-hive.sh的环境变量里,需要手动指定,我是这么干的:

export ATLASCPPATH=/opt/atlas/server/webapp/atlas/WEB-INF/lib/*

2) hive hook目录下的 jersey-json-1.19.jar 这个包太老了,换成1.9的版本就 OK了。

mv jersey-json-1.19.jar jersey-json-1.19.jar_bak

再把1.9的拷贝进去 就可以。

3) 设置HIVE_HOME目录,我是CDH,设置/opt./cloudera/parcels/lib/hive  即可.

看你的数据库或者表是否多,我的导入大概持续了5-10分钟。

7. 登入atlas:http://xxxxxxxx:21000  admin/admin

之前提过,atlas支持字段级别,但是 要求是 HIVE 1.2.1之后的版本 ,这个可以参考官方文档,我的HIVE是 1.1,所以只能支持到表级别了。

猜你喜欢

转载自blog.csdn.net/tom_fans/article/details/85506662