Apache Atlas 环境搭建以及案例设计
文章目录
1. 环境搭建
相关配置
- JDK: jdk_1.8.0_333
- Maven: 3.6.3
- Atlas: 2.1.0
目录结构
/home
└── bigdata
├── app
│ ├── atlas
│ └── maven
└── software
├── apache-atlas-2.1.0-sources.tar.gz
├── apache-atlas-sources-2.1.0
└── apache-maven-3.6.3-bin.tar.gz
/atlas
├── apache-atlas-2.1.0
│ └── data
└── embedded-2.1.0
├── bin
├── conf
├── data
├── DISCLAIMER.txt
├── hbase
├── LICENSE
├── logs
├── models
├── NOTICE
├── server
├── solr
└── tools
本次环境搭建使用阿里云服务器,CentOS7.9版本,并未部署集群,为单机版搭建过程
(1) JDK
有相关资料使用自带的openJDK-1.8.0且版本号小于151,会引发一些错误,故使用oracleJDK
下载地址: https://www.oracle.com/java/technologies/javase/javase8u211-later-archive-downloads.html
下载64位JDK,使用rpm安装或者解压tar包安装
本次使用解压安装,压缩包上传至 /usr/java 目录下执行
tar -zxvf jdk-8u333-linux-x64.tar.gz
添加环境变量
vim /etc/profile
添加
export JAVA_HOME=/usr/java/jdk1.8.0_333
export JRE_HOME=$JAVA_HOME/jre
source /etc/profile
使其生效
(2) Maven
进入 /bigdata/software 执行
wget https://mirrors.bfsu.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
得到maven的压缩包后解压,将目录移动到/bigdata/app下,改名为maven
进入/etc/profile添加环境变量
export MAVEN_HOME=/home/bigdata/app/maven
export MAVEN=$MAVEN_HOME/bin
source /etc/profile
使其生效
mvn -version
查看安装成功
进入maven目录下添加镜像
vim /conf/settings.xml
添加
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>https://repo1.maven.org/maven2/</url>
</mirror>
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name></name>
<url>https://repo2.maven.org/maven2/</url>
</mirror>
注意不要添加在注释里面,后亦可添加阿里云,华为云镜像。但是在之后编译过程中所依赖的某些包可能在阿里maven仓库中下载不到,或者依赖版本不匹配等,故建议repo1,repo2 作为首选。
(3) Apache Atlas 源码下载,编译
下载之后上传至 /bigdata/software目录下,执行
export MAVEN_OPTS="-Xms1g -Xmx2g"
调整JVM占用内存
mvn clean -DskipTests package -Pdist,embedded-hbase-solr
使用内嵌的hbaseh以及solr进行编译
可能导致编译报错的原因有
Maven版本过低,尽量使用3.6版本以上
若使用本地Wiindow下IDEA编译,则需要再设置中远程Jar仓库中添加repo1,repo2 的地址
构建成功的软件保存在 /apache-atlas-sources-2.1.0/distro/target 下
解压 apache-atlas-2.1.0-server.tar.gz, 并执行
mv apache-atlas-2.1.0 /home/bigdata/app/atlas
将文件移动到atlas文件夹下
(本次并将其改名为,embedded-2.1.0,亦可不变)
(4) Apache Atlas 启动
进入/home/bigdata/app/atlas/embedded-2.1.0目录
执行 vim /conf/atlas-env.sh
文末更改如下,并保存退出
export MANAGE_LOCAL_HBASE=true
export MANAGE_LOCAL_SOLR=true
若此时执行 bin/atlas_start.py
启动Atlas
执行 jps -m
查看进行的Java进程,发现Hbase 和 Solr 并没有正常启动
故手动启动,执行
hbase/bin/start-hbase.sh
启动hbase
solr/bin/solr start -c -z 127.0.0.1:2181 -p 8983 -force
启动solr
再执行jps -m
查看进程
则hbase 和 solr 启动正常
创建solr索引
solr/bin/solr create -c fulltext_index -force -d conf/solr/
solr/bin/solr create -c edge_index -force -d conf/solr/
solr/bin/solr create -c vertex_index -force -d conf/solr/
最后执行bin/atlas_start.py
,并需要等待若干分钟启动成功
注意下次启动时可直接启动Atlas,无需再手动启动hbase, solr
浏览器访问ip:21000
,若拒绝访问,则查看防火墙是否关闭,若为服务器启动,则查看安全组入方向是否配置
停止:bin/atlas_stop.py
可能导致启动报错的原因有
solr 报错 zookeeper 依赖相关的错误,必须先启动hbase 再启动solr, 因为启动hbase时会启动内置的zk
启动hbase或者atlas时报错 jvm 相关错误则查看 JAVA_HOME 是否配置
2. 案例设计
首先回顾一下Apache Atlas
Atlas作为Hadoop生态中解决元数据治理的一种重要手段,提供了数据分类,数据血缘,数据安全等功能,并且采用了Hbase存储元数据,Solr实现索引系统。另外Atlas支持与Hive,Sqoop等元数据源的集成,还可以选择使用Kafka的消息接口与Atlas集成等。本次采用AtlasClientV2 调用REST API实现对元数据的管理。
Atlas 数据类型
Type:定义了元数据对象一个或多个属性的集合,类似于面向对象编程转中的类
Entity:实体是类型的特定值或实例,类似于面向对象编程中类的一个对象(实例)
Lineage:数据血缘,表示数据之间的传递关系
(1) 引入依赖
首先在pom.xml中 添加
<dependency>
<groupId>org.apache.atlas</groupId>
<artifactId>atlas-client-common</artifactId>
<version>2.1.0</version>
</denpendency>
<dependency>
<groupId>org.apache.atlas</groupId>
<artifactId>>atlas-client-v2</artifactId>
<version>2.1.0</version>
</denpendency>
另外,需要在 resources 目录下创建 atlas-application.properities 文件,并添加
atlas.rest.address=http://ip:21000
本次进行一个较为简单的案例设计,旨在实现对类型(Type) 实体(Entity) 血缘(Lineage) 关系的创建,查询等操作。
(2) 类型,实体的创建
HashSet<String> superTypes = new HashSet<>();
// DB 与 table 实体均为 DataSet 的扩展
superTypes.add(AtlasBaseTypeDef.ATLAS_TYPE_DATASET);
AtlasTypesDef major = new AtlasTypesDef();
AtlasEntityDef DB = new AtlasEntityDef(); // DB 实体
DB.setName("DB_major");
DB.setServiceType("major");
DB.setSuperTypes(superTypes);
DB.setTypeVersion("1.1");
AtlasEntityDef SE_table = new AtlasEntityDef();
SE_table.setName("SE_table");
SE_table.setServiceType("major");
SE_table.setSuperTypes(superTypes);
SE_table.setTypeVersion("1.1");
AtlasEntityDef EIE_table = new AtlasEntityDef();
EIE_table.setName("EIE_table");
EIE_table.setServiceType("major");
EIE_table.setSuperTypes(superTypes);
EIE_table.setTypeVersion("1.1");
SearchFilter filter = new SearchFilter();
filter.setParam("name", "DB_major");
AtlasTypesDef all = client.getAllTypeDefs(filter);
if (all.getEntityDefs().isEmpty()){
client.createAtlasTypeDefs(major);
}
成功创建后可看到major 下创建的三个类型
接下来创建名为 majorDB 的实体
AtlasEntity majorDB = new AtlasEntity();
majorDB.setTypeName("DB_major");
Map<String, Object> attributes = new HashMap<>();
attributes.put("qualifiedName", "majorDB");
attributes.put("name", "majorDB");
attributes.put("description", "create majorDB");
majorDB.setAttributes(attributes);
Map<String, String> queryAttributes = new HashMap<>();
queryAttributes.put("qualifiedName", "majorDB");
String DBguid = null;
// 查询 DB 的 guid
try { // 有这个实体的情况
AtlasEntity.AtlasEntityWithExtInfo extInfo = client.getEntityByAttribute("DB_major", queryAttributes);
DBguid = extInfo.getEntity().getGuid();
}catch (AtlasServiceException e){ // 无实体的情况
if (ClientResponse.Status.NOT_FOUND.equals(e.getStatus())){
AtlasEntity.AtlasEntityWithExtInfo extInfo = new AtlasEntity.AtlasEntityWithExtInfo(majorDB);
EntityMutationResponse response = null;
try { // 创建实体
response = client.createEntity(extInfo);
} catch (AtlasServiceException ex) {
ex.printStackTrace();
}
DBguid = response.getGuidAssignments().values().toArray(new String[]{})[0];
}
}
System.out.println("DB guid: " + DBguid);
同理可创建实体 tableEIE tableSE2 tableSE3和 tableSE
(3) 血缘关系
AtlasEntity lineage = new AtlasEntity();
// process 类型
lineage.setTypeName(AtlasBaseTypeDef.ATLAS_TYPE_PROCESS);
attributes.put("qualifiedName", "test_process");
attributes.put("name", "test_process");
attributes.put("description", "2 的数据来自 3");
attributes.put("inputs", getLineAgeInfo(tableSE3));
attributes.put("outputs", getLineAgeInfo(tableSE2));
lineage.setAttributes(attributes);
System.out.println(lineage.toString());
try {
client.getEntityByAttribute(AtlasBaseTypeDef.ATLAS_TYPE_PROCESS, queryAttributes);
} catch (AtlasServiceException e) {
if (ClientResponse.Status.NOT_FOUND.equals(e.getStatus())) {
// 创建 Lineage
AtlasEntity.AtlasEntityWithExtInfo extInfo1 = new AtlasEntity.AtlasEntityWithExtInfo(lineage);
try {
client.createEntity(extInfo1);
} catch (AtlasServiceException ex) {
ex.printStackTrace();
}
}
}
血缘关系实体的类型为process , 运行即可生成如下血缘关系
参考文章:
Apache Atlas – Building & Installing Apache Atlas
Apache Atlas精讲:由浅入深,从概念,原理,使用,到自定义数据模型,生成血缘关系,带你玩转Atlas_小螺旋丸的博客-CSDN博客_apache atlas