源码编译安装flink
前置条件:
JDK8
Maven3
(jdk 和 maven 请自行搜索,谢谢!)
通过下载Flink源码进行编译,不是使用直接下载二进制包
Flink GitHub 地址
在releases中找到自己需要的版本。我用的是1.9.0版本:1.9.0
<code>tar -zxvf flink-release-1.9.0.tar.gz [-C 可以指定需要放置的目录] </code>

如要在其他第三方厂家使用flink 打包,例如要在cdh ,Hortonworks 平台上使用,我们需要指定hadoop 版本进行打包。那么要先对flink 的前置依赖 flink-shaded-hadoop-2 进行打包,再进行编译。
1、在解压出来的flink源码目录下新建一个目录,从git上获取flink-shaded 的源码
<code>git clone https://github.com/apache/flink-shaded.git </code>
根据自己缺少的版本切换对应的代码分支,这里我缺少的是7.0版本的flink-shaded-hadoop-2
<code>git checkout release-7.0 </code>
修改flink-shaded项目中的pom.xml 这里修改是为了加入cdh 等中央仓库,否则编译对应版本可能找不到cdh 相关的包。
在pom.xml文件中的添加
<code><profile> <id>vendor-repos</id> <activation> <property> <name>vendor-repos</name> </property> </activation> <!-- Add vendor maven repositories --> <repositories> <!-- Cloudera --> <repository> <id>cloudera-releases</id> <url>https://repository.cloudera.com/artifactory/cloudera-repos</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> <!-- Hortonworks --> <repository> <id>HDPReleases</id> <name>HDP Releases</name> <url>https://repo.hortonworks.com/content/repositories/releases/</url> <snapshots><enabled>false</enabled></snapshots> <releases><enabled>true</enabled></releases> </repository> <repository> <id>HortonworksJettyHadoop</id> <name>HDP Jetty</name> <url>https://repo.hortonworks.com/content/repositories/jetty-hadoop</url> <snapshots><enabled>false</enabled></snapshots> <releases><enabled>true</enabled></releases> </repository> <!-- MapR --> <repository> <id>mapr-releases</id> <url>https://repository.mapr.com/maven/</url> <snapshots><enabled>false</enabled></snapshots> <releases><enabled>true</enabled></releases> </repository> </repositories> </profile> </code>
然后选择自己需要的CDH版本进行编译 flink-shaded-hadoop-2【要进去包含pom文件的那一层去执行下面的命令去编译哦!】
<code>mvn clean install -DskipTests -Drat.skip=true -Pvendor-repos -Dhadoop.version=2.6.0-cdh5.15.1 </code>
如果您能看到下图代表flink-shaded-hadoop-2编译ok了。【但是Flink咱们还没开始编译呢】

接下来就是拿FLink开刀了
为什么要加上Dfast:To speed up the build you can skip tests, QA plugins, and JavaDocs
<code>mvn clean install -DskipTests -Pvendor-repos -Dfast -Dhadoop.version=2.6.0-cdh5.15.1 </code>

第一次编译是需要花费很长时间的,因为需要去中央仓库下载flink源码中所有的依赖包,请耐心等待呀!
如果大家有什么好的学习意见欢迎交流呀,谢谢大家!
需要梦想丶 发布了10 篇原创文章 · 获赞 3 · 访问量 124 私信 关注【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!