目錄:
maven環境搭建
maven 下載:https://maven.apache.org/download.cgi ,你也可以使用wget + url 下載。
命令:wget http://mirrors.advancedhosters.com/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
我下載的是3.6.3的版本,目前要求JDK 1.7或更高版本才能執行。
解壓縮:命令:tar zvxf apache-maven-3.6.3-bin.tar.gz
安裝:
這里我先生成了maven-install文件夾,apache-maven-3.6.3文件夾放在此文件夾中,現在修改maven鏡像。進入maven的conf文件夾(在bin同級目錄下),使用 vim settings.xml 編輯文本,輸入反斜杠‘/’,搜索mirrors,按enter定位。設置如下代碼:
<mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror>
參考文獻:Linux安裝maven
配置環境變量:
我先建立了apache-maven-3.6.3的軟連接,命令:ln -s apache-maven-3.6.3 maven
配置環境變量:sudo vim /etc/profile
添加如下代碼:
#maven export MAVEN_HOME=/home/elfin/maven-install/maven export PATH=$PATH:$MAVEN_HOME/bin
刷新配置:source /etc/profile
驗證maven安裝是否成功:mvn -v
可以看見已經安裝成功了,返回了maven的版本以及Java的版本。
IDEA環境搭建
下載安裝包,地址:https://download-cf.jetbrains.com/idea/ideaIC-2020.1.tar.gz
解壓縮:tar zvxf idealC-2020.1.tar.gz
創建桌面快捷方式:
命令1:touch idea.desktop 生成桌面文件
命令2:vim idea.desktop 添加代碼:
[Desktop Entry]
Name=IntelliJ IDEA
Comment=IntelliJ IDEA
Exec=/home/elfin/idea-install/idea-IC-201.6668.121/bin/idea.sh
Icon=/home/elfin/idea-install/idea-IC-201.6668.121/bin/idea.png
Terminal=false
Type=Application
Categories=Developer;
其中Exec指向你的啟動文件,Icon指向圖片。
命令3:chmod u+x idea.desktop 賦予權限
圖標不正常顯示:雙擊桌面快捷方式,選擇信任,圖標就正常顯示了。
flink開發環境搭建
創建flink項目
方式一:curl https://flink.apache.org/q/quickstart.sh | bash -s 1.9.2
你可以打開腳本文件:https://flink.apache.org/q/quickstart.sh 代碼如下:
#!/usr/bin/env bash ################################################################################ # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ################################################################################ PACKAGE=quickstart mvn archetype:generate \ -DarchetypeGroupId=org.apache.flink \ -DarchetypeArtifactId=flink-quickstart-java \ -DarchetypeVersion=${1:-1.10.0} \ -DgroupId=org.myorg.quickstart \ -DartifactId=$PACKAGE \ -Dversion=0.1 \ -Dpackage=org.myorg.quickstart \ -DinteractiveMode=false # # Give some guidance # echo -e "\\n\\n" echo -e "\\tA sample quickstart Flink Job has been created." echo -e "\\tSwitch into the directory using" echo -e "\\t\\t cd $PACKAGE" echo -e "\\tImport the project there using your favorite IDE (Import it as a maven project)" echo -e "\\tBuild a jar inside the directory using" echo -e "\\t\\t mvn clean package" echo -e "\\tYou will find the runnable jar in $PACKAGE/target" echo -e "\\tConsult our website if you have any troubles: http://flink.apache.org/community.html#mailing-lists" echo -e "\\n\\n"
命令使用詳情:第一次使用會下載很多包,下載時間較長,需要稍加等待。
這里面已經默認為你配置好了,但是有時我們想要自己配置,那么我們可以使用方式二。
方式二:注意 \ 是終端換行符號,以下代碼不能直接復制,因為格式的緣故,可能會出問題。
$ mvn archetype:generate \
-DarchetypeGroupId=org.apache.flink \
-DarchetypeArtifactId=flink-quickstart-java \
-DarchetypeVersion=1.9.2
當然可以直接一行寫出所有的命令行參數:
mvn archetype:generate -DarchetypeGroupId=org.apache.flink -DarchetypeArtifactId=flink-quickstart-java -DarchetypeVersion=1.9.2 -DarchetypeCatalog=internal
最后一個參數如果不加,你的創建過程可能會非常非常漫長,當然你可以下載相關文件到本地,然后令此參數為local。
創建成功。我們嘗試用命令:mvn archetype:generate -DarchetypeGroupId=org.apache.flink -DarchetypeArtifactId=flink-quickstart-java -DarchetypeVersion=1.9.2 -DarchetypeCatalog=local 創建,同樣也成功了。
IDEA-flink開發環境
IDEA導入已經創建的環境:打開IDEA之后open對應的項目,在terminal里輸入:mvn clean package 打包項目(編譯項目),clean是清除之前的打包。
核心依賴
打包時,核心依賴不會進行打包,因為核心依賴要盡可能小,避免沖突,一般運行環境都有這些包。核心依賴包含coordination、networking、checkpoints、failover、APIs、operations、resource management等必須的依賴。
應用依賴
核心依賴、應用依賴等都在porm.xml文件里可以進行配置。
groupId標簽:一般我們設置為域名的順序倒置,如org.flink
artifactId標簽:可以理解為項目名
version標簽:項目版本號,默認為:1.0-SNAPSHOT
packaging標簽:我這里是jar包,因為使用Java開發
repositories標簽:配置數倉信息,你可以配置公司的信息
dependencies標簽:依賴,包含標簽<scope>provided</scope>的是核心依賴,所以不是核心依賴就不要寫這個子標簽,不然打包時這個依賴不會配置。應用依賴使用的子標簽是:<scope>runtime</scope>,注意與核心依賴的區分。
build標簽:是打包編譯時要配置的插件