编程语言
首页 > 编程语言> > ranger和presto源码编译

ranger和presto源码编译

作者:互联网

Presto+Ranger源码编译问题总结

由于最近想要整合prestodb和ranger,故想要对presto内部进一步了解,方便对其添加ranger的插件。

为此,我对presto进行了源码编译,同时对ranger0.7.1(线上用的版本)进行了源码编译。presto是在win10上编译的,ranger在ubuntu16.04上进行编译的,下面讲解下主要的编译流程

一、Presto源码编译

一、环境

WIN10、jdk1.8、presto-0.233、maven-3.8.2

二、步骤

1.修改presto-maven-plugin

Presto使用presto-maven-plugin编译。在Window下编译失败原因是编译过程中类找不到,而且文件路径错了。

这里Presto使用的presto-maven-plugin的版本为0.3,从 GitHub prestodb/presto-maven-plugin 0.3 下载源码。

修改ServiceDescriptorGenerator

String className = classPath.substring(0, classPath.length() - 6).replace('/', '.');

替换成

String className = classPath.substring(0, classPath.length() - 6).replace(File.separatorChar, '.');

因为类名是通过把类路径的文件分隔符替换成.来生成,Windows的分隔符是\,所以把’/'替换成File.separatorChar。

再将presto-maven-plugin,mvn clean install -DskipTests 到本地仓库中。

2. 修改根目录pom.xml

是否安装Python
可能和Python环境有关。文档由sphinx生成,未安装就注释。

<module>presto-docs</module>

是否创建GIT仓库,使用git clone方式下载的
有,就不用管。
没有,需要在的元素中,添加配置

<plugin>       
    <groupId>pl.project13.maven</groupId>       
    <artifactId>git-commit-id-plugin</artifactId>       
    <configuration>           
        <skip>true</skip>       
    </configuration>   
</plugin>

再注释

<Build-Time>${git.build.time}</Build-Time>
<Git-Commit-Id>${git.commit.id}</Git-Commit-Id>
<Implementation-Version>${project.version}-${git.commit.id.abbrev}</Implementation-Version>
3.配置类unix环境

Presto编译过程中会用到Linux中的命令,Git Bash带有一些类Unix的命令。

设置Windows的环境变量Path,加上:%GIT_HOME%\usr\bin,其中GIT_HOME是Git的安装路径,一般默认安装路径为:C:\Program Files\Git。

如果使用了Intellij Idea,配置好环境变量之后,需要重启Intellij Idea才能生效。

4.编译项目
mvn clean install -DskipTests

编译成功了之后,就要进入到presto-main中修改相关配置

三、修改配置

修改presto-main\etc\config.properties

# http端口
http-server.http.port=18080
# 这里在Coordinator中启用了Discovery的嵌入式版本,所以它应该是Coordinator的URI
discovery.uri=http://localhost:18080

# 插件文件夹
plugin.dir=../presto-server/target/presto-server-0.240/presto-server-0.240/plugin
#plugin.bundles=\
#  ../presto-blackhole/pom.xml,\
#  ../presto-memory/pom.xml,\
#  ../presto-jmx/pom.xml,\
#  ../presto-raptor/pom.xml,\
#  ../presto-hive-hadoop2/pom.xml,\
#  ../presto-example-http/pom.xml,\
#  ../presto-kafka/pom.xml, \
#  ../presto-tpch/pom.xml, \
#  ../presto-local-file/pom.xml, \
#  ../presto-mysql/pom.xml,\
#  ../presto-sqlserver/pom.xml, \
#  ../presto-postgresql/pom.xml, \
#  ../presto-tpcds/pom.xml, \
#  ../presto-i18n-functions/pom.xml,\
#  ../presto-function-namespace-managers/pom.xml,\
#  ../presto-druid/pom.xml

修改presto-main\etc\catalog\hive.properties
将hive.properties重命名为hive.properties.bak。启动后默认会加载catalog目录下所有的连接器,本地无hadoop、hive等环境,就会报错导致启动失败。其他自带的catalog,如果没有用到,请修改名称,以免启动带来不必要的麻烦。

一般你可以验证mysql即可。

修改PrestoSystemRequirements.java

注释presto-main模块PrestoSystemRequirements的代码,相关代码片段用IDEA搜索功能查找

failRequirement("Presto requires Linux or Mac OS X (found %s)", osName);

修改文件描述符大小限制(手动改成10000):

private static OptionalLong getMaxFileDescriptorCount()
    {
        try {
            MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
            //Object maxFileDescriptorCount = mbeanServer.getAttribute(ObjectName.getInstance(OPERATING_SYSTEM_MXBEAN_NAME), "MaxFileDescriptorCount");
            Object maxFileDescriptorCount = 10000;
            return OptionalLong.of(((Number) maxFileDescriptorCount).longValue());
        }
        catch (Exception e) {
            return OptionalLong.empty();
        }
    }

下面a/b步骤可以根据目的选一个,a步不包含任何插件,可以快速调试接口。b步包含完整插件,有完整的功能:
a、接下来,把PluginManager的插件注释掉,

   /*for (File file : listFiles(installedPluginsDir)) {
            if (file.isDirectory()) {
                loadPlugin(file.getAbsolutePath());
            }
        }

        for (String plugin : plugins) {
            loadPlugin(plugin);
        }*/

把etc/catalog的配置文件全部改名为.properties.bak
b、下载presto-server-0.207.tar.gz文件,解压到任意目录,把这里边的plugin目录作为IDEA工程的plugin目录,需要打开文件PluginManagerConfig.java,做如下修改:

//    private File installedPluginsDir = new File("plugin");
    private File installedPluginsDir = new File("D:\\presto-server-0.207\\plugin");

etc/catalog的配置文件根据需要改名为.properties.bak
最后运行PrestoServer。

四、启动

首先要配置好启动的jvm参数VM options

-Xmx800M -XX:+UseConcMarkSweepGC -XX:+ExplicitGCInvokesConcurrent -XX:+CMSClassUnloadingEnabled -XX:+AggressiveOpts -XX:+HeapDumpOnOutOfMemoryError -XX:ReservedCodeCacheSize=150M -Dsun.security.krb5.debug=true  -Dconfig=etc/config.properties -Dlog.levels-file=etc/log.properties 

然后选择presto-main项目,主类是com.facebook.presto.server.PrestoServer

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-UFZtCKkN-1643349229752)(C:\Users\luohaizhang\AppData\Roaming\Typora\typora-user-images\1643106498641.png)]

五、遇到的问题

1、Cannot resolve symbol 'SqlBaseParser

在运行项目的时候,出现例如在presto-parser模块Cannot resolve symbol 'SqlBaseParser缺少代码的错误,这是因为源码不带anltr4的生成代码。可以在根目录运行生成anltr4代码的命令。

mvn antlr4:antlr4

在执行命令完成后,错误依旧没有消失,我们可以看看项目的结构。File -> Project Structure -> Modules -> presto-parser,将presto-parser的target -> generated-sources ->anltr4设置为Sources

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-WUo7n1a5-1643349229753)(C:\Users\luohaizhang\AppData\Roaming\Typora\typora-user-images\1643106367431.png)]

参考文章:

https://blog.csdn.net/qq_36160730/article/details/109067896

https://www.cnblogs.com/ginponson/p/9500663.html

二、ranger源码编译流程

1. 部署准备

ranger: 进入apach官网下载 http://ranger.apache.org/download.html, 本次使用的是ranger0.7.1 ,地址为https://codeload.github.com/apache/ranger/zip/refs/tags/release-ranger-0.7.1

maven: 进入Apache的maven官网http://maven.apache.org/download.cgi下载, 本次用的是maven3.8.2

python2.7: 因编译及试用中需要Python2.7版本的Python,因此如果为Centos6系统,需要手动升级Python至Python2.7,升级过程可参考历史文章Python升级

MySQL: 需要mysql数据库,如无可用MySQL需要部署一套MySQL,部署方法请参考历史文章MySQL部署

mysql-connector-java: 进入MySQL官网下载 https://dev.mysql.com/downloads/connector/j/5.1.html

Jdk版本: 本次使用的jdk版本是1.8.0_321

具体安装这些组件的过程不再赘述,可以参考下面贴出来的两篇文章。

2.编译

将ranger0.7.1下载好,上传到ubuntu目录,可以放到你用户的家目录下,注意必须要当前账户有权限,否则会遇到很多权限不足的问题;

解压,导入到idea中。或者你不用idea直接解压也ok,idea为了方便看代码,后续做插件修改之类的。

修改ranger根目录的pom.xml文件

 <repository>
            <id>apache.snapshots.https</id>
            <name>Apache Development Snapshot Repository</name>
<!--            <url>https://repository.apache.org/content/repositories/snapshots</url>-->
            <url>https://repo1.maven.org/maven2/</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>apache.public.https</id>
            <name>Apache Development Snapshot Repository</name>
            <url>https://repository.apache.org/content/repositories/public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>

执行mvn命令,打包

mvn clean compile package assembly:assembly install -Dmaven.test.skip=true;

此处将单元测试全部略过,因为有的单元测试有问题会影响编译。

注意,一定要安装了python2,否则你编译不过ranger-util

成功编译的结果:

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for ranger 0.7.1:
[INFO] 
[INFO] ranger ............................................. SUCCESS [  3.591 s]
[INFO] Jdbc SQL Connector ................................. SUCCESS [  1.632 s]
[INFO] Credential Support ................................. SUCCESS [  0.479 s]
[INFO] Audit Component .................................... SUCCESS [  1.731 s]
[INFO] Common library for Plugins ......................... SUCCESS [  2.892 s]
[INFO] Installer Support Component ........................ SUCCESS [  0.265 s]
[INFO] Credential Builder ................................. SUCCESS [  0.405 s]
[INFO] Embedded Web Server Invoker ........................ SUCCESS [  0.341 s]
[INFO] Key Management Service ............................. SUCCESS [  0.891 s]
[INFO] ranger-plugin-classloader .......................... SUCCESS [  0.198 s]
[INFO] HBase Security Plugin Shim ......................... SUCCESS [  1.319 s]
[INFO] HBase Security Plugin .............................. SUCCESS [  1.280 s]
[INFO] Hdfs Security Plugin ............................... SUCCESS [  4.005 s]
[INFO] Hive Security Plugin ............................... SUCCESS [  2.247 s]
[INFO] Knox Security Plugin ............................... SUCCESS [  0.550 s]
[INFO] Storm Security Plugin .............................. SUCCESS [  0.642 s]
[INFO] YARN Security Plugin ............................... SUCCESS [  0.462 s]
[INFO] Ranger Util ........................................ SUCCESS [  5.051 s]
[INFO] Unix Authentication Client ......................... SUCCESS [  0.330 s]
[INFO] Security Admin Web Application ..................... SUCCESS [ 13.658 s]
[INFO] KAFKA Security Plugin .............................. SUCCESS [  1.504 s]
[INFO] SOLR Security Plugin ............................... SUCCESS [  3.403 s]
[INFO] NiFi Security Plugin ............................... SUCCESS [  0.354 s]
[INFO] Unix User Group Synchronizer ....................... SUCCESS [  1.097 s]
[INFO] Ldap Config Check Tool ............................. SUCCESS [  2.643 s]
[INFO] Unix Authentication Service ........................ SUCCESS [  2.010 s]
[INFO] KMS Security Plugin ................................ SUCCESS [  2.111 s]
[INFO] Tag Synchronizer ................................... SUCCESS [  2.863 s]
[INFO] Hdfs Security Plugin Shim .......................... SUCCESS [  0.515 s]
[INFO] Hive Security Plugin Shim .......................... SUCCESS [  1.543 s]
[INFO] Knox Security Plugin Shim .......................... SUCCESS [  0.665 s]
[INFO] YARN Security Plugin Shim .......................... SUCCESS [  0.543 s]
[INFO] Storm Security Plugin shim ......................... SUCCESS [  0.536 s]
[INFO] KAFKA Security Plugin Shim ......................... SUCCESS [  0.572 s]
[INFO] SOLR Security Plugin Shim .......................... SUCCESS [  0.848 s]
[INFO] Atlas Security Plugin Shim ......................... SUCCESS [  0.332 s]
[INFO] KMS Security Plugin Shim ........................... SUCCESS [  0.577 s]
[INFO] Ranger Hive Utils .................................. SUCCESS [  1.189 s]
[INFO] ranger-examples .................................... SUCCESS [  0.126 s]
[INFO] Ranger Examples - Conditions and ContextEnrichers .. SUCCESS [  0.523 s]
[INFO] Ranger Examples - SampleApp ........................ SUCCESS [  0.844 s]
[INFO] Ranger Examples - Ranger Plugin for SampleApp ...... SUCCESS [  1.209 s]
[INFO] Ranger Tools ....................................... SUCCESS [  1.728 s]
[INFO] Atlas Security Plugin .............................. SUCCESS [  0.976 s]
[INFO] Unix Native Authenticator .......................... SUCCESS [  1.484 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  07:03 min
[INFO] Finished at: 2022-01-28T10:38:15+08:00
[INFO] ------------------------------------------------------------------------

我们可以在根目录的target文件夹下看到生成的tar.gz包。

root@ubuntu:/home/luohaizhang/ideaProjects/ranger/ranger-release-ranger-0.7.1# ls target
antrun                            ranger-0.7.1-hbase-plugin.tar.gz  ranger-0.7.1-kms.tar.gz             ranger-0.7.1-solr-plugin.tar.gz   ranger-0.7.1-usersync.tar.gz
archive-tmp                       ranger-0.7.1-hbase-plugin.zip     ranger-0.7.1-kms.zip                ranger-0.7.1-solr-plugin.zip      ranger-0.7.1-usersync.zip
maven-shared-archive-resources    ranger-0.7.1-hdfs-plugin.tar.gz   ranger-0.7.1-knox-plugin.tar.gz     ranger-0.7.1-src.tar.gz           ranger-0.7.1-yarn-plugin.tar.gz
ranger-0.7.1-admin                ranger-0.7.1-hdfs-plugin.zip      ranger-0.7.1-knox-plugin.zip        ranger-0.7.1-src.zip              ranger-0.7.1-yarn-plugin.zip
ranger-0.7.1-admin.tar.gz         ranger-0.7.1-hive-plugin.tar.gz   ranger-0.7.1-migration-util.tar.gz  ranger-0.7.1-storm-plugin.tar.gz  rat.txt
ranger-0.7.1-admin.zip            ranger-0.7.1-hive-plugin.zip      ranger-0.7.1-migration-util.zip     ranger-0.7.1-storm-plugin.zip     version
ranger-0.7.1-atlas-plugin.tar.gz  ranger-0.7.1-kafka-plugin.tar.gz  ranger-0.7.1-ranger-tools.tar.gz    ranger-0.7.1-tagsync.tar.gz
ranger-0.7.1-atlas-plugin.zip     ranger-0.7.1-kafka-plugin.zip     ranger-0.7.1-ranger-tools.zip       ranger-0.7.1-tagsync.zip

3.安装启动ranger-admin

2.3.1 修改配置文件

#  进入target目录
cd /opt/apache-ranger-1.2.0/target/

#  解压ranger-1.2.0-admin.tar.gz
tar  -zxvf  ranger-1.2.0-admin.tar.gz

# 进入ranger-1.2.0-admin目录
cd  ranger-1.2.0-admin

# 修改 install.properties
vim install.properties


SQL_CONNECTOR_JAR=/usr/share/java/mysql-connector-java-8.0.17.jar   //  修改为准备工作中下载的jar包及路径

db_root_user=root
db_root_password=123456
db_host=192.168.56.105

db_name=ranger
db_user=rangeradmin
db_password=rangeradmin


# 可以注销如下内容
#Source for Audit Store. Currently only solr is supported.
# * audit_store is solr
## audit_store=solr

# * audit_solr_url URL to Solr. E.g. http://<solr_host>:6083/solr/ranger_audits
## audit_solr_urls=
## audit_solr_user=
## audit_solr_password=
## audit_solr_zookeepers=

这里不用solr组件统计了,测试而已

调用脚本./setup.sh 安装

注意,如果中途报如下错误

2019-08-20 08:54:22,460  [I] '/usr/local/java/bin/java' command found
setup.sh:行325: bc: 未找到命令
setup.sh: 第 325 行:[: -eq: 期待一元表达式

即缺少bc命令,安装后即可 。

注意,mysql一定要有访问权限,必须不限制当前机器的host。

最终出现如下结果

2019-08-20 09:00:18,240  [I] --------- Verifying Ranger DB connection ---------
2019-08-20 09:00:18,240  [I] Checking connection..
geradmin' -p '********' -noheader -trim -c \; -query "SELECT version();"
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
2019-08-20 09:00:18,838  [I] Checking connection passed.
2019-08-20 09:00:19,091  [I] DB FLAVOR :MYSQL
2019-08-20 09:00:19,092  [I] --------- Verifying Ranger DB connection ---------
2019-08-20 09:00:19,092  [I] Checking connection..
geradmin' -p '********' -noheader -trim -c \; -query "SELECT version();"
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
2019-08-20 09:00:19,660  [I] Checking connection passed.
Installation of Ranger PolicyManager Web Application is completed.

表示已完成安装。

4 .启动ranger-admin

#  进入ews目录
cd ews 
# 启动服务
./ranger-admin-services.sh  start
/**  正常情况下出现如下结果*/ 
Starting Apache Ranger Admin Service

Apache Ranger Admin Service with pid 236275 has started.

#  查看是否启动
ps -ef|grep ranger
或
netstat -lntp|grep 6080

启动完成后,可以用web端登录验证,默认端口为6080,默认用户名密码均为admin

后续自行验证即可。

如果后面加了新的组件,比如写了presto的plugin,配置好后,编译,同样启动验证即可。

参考文章:

https://www.cnblogs.com/gjc592/p/11383778.html

https://blog.csdn.net/mm_bit/article/details/51208500

标签:INFO,SUCCESS,presto,plugin,0.7,ranger,源码
来源: https://blog.csdn.net/qq_40616823/article/details/122730363