您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關Flink怎么用,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
Flink運行支持 Linux、蘋果、Windows 主流平臺。不過最好還是使用 Linux。下面給出安裝前的準備:
安裝 Jdk1.7.X 或者以上的版本
在 Flink 官網下載對應 Hadoop 預編譯版本
將預編譯版本解壓,進入解壓縮文件,為了方便,后文統一稱此目錄為:FLINK_HOME。
單機嘗試非常簡單,直接執行命令:
Linux用戶: sh bin/start-local.sh
Windows用戶,在命令窗戶輸入:bin\start-local.bat
等待其出現如下提示之后:
D:\Java\flink\flink-0.10.1>bin\start-local.bat Starting Flink job manager. Webinterface by default on http://localhost:8081/. Don't close this batch window. Stop job manager by pressing Ctrl+C.
在瀏覽器中輸入:http://localhost:8081/,Flink默認監聽8081端口,防止其他進程占用此端口。此時出現下面的管理界面:
可以發現這個界面和 Spark 的管理界面的邏輯差不多,主要是管理正在運行的Job,已經完成的 Job,以及Task 管理和 Job 管理,Task 應該是管理 Job 的,以后再仔細分析里面的邏輯。
下面迫不及待先來跑一個分布式系統最經典的例子:WordCount,下面以 FLINK_HOME 的 README.txt 文件作為示例文件,測試 WordCount 程序,在 Windows 上面運行代碼以及運行過程如下圖:
D:\Java\flink\flink-0.10.1>bin\flink.bat run .\examples\WordCount.jar file:/D:/Java/flink/flink-0.10.1/README.txt file:/D:/Java/flink/flink-0.10.1/wordcount-result.txt log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.li b.MutableMetricsFactory). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. 01/15/2016 16:30:51 Job execution switched to status RUNNING. 01/15/2016 16:30:51 CHAIN DataSource (at getTextDataSet(WordCount.java:142) (org.apache.flink.api.java.io.TextInputFormat)) -> FlatMap (FlatMap at main(WordCount.java:69)) -> Combine(SUM(1), at main(WordCount.java:72)(1/1) switched to SCHEDULED 01/15/2016 16:30:51 CHAIN DataSource (at getTextDataSet(WordCount.java:142) (org.apache.flink.api.java.io.TextInputFormat)) -> FlatMap (FlatMap at main(WordCount.java:69)) -> Combine(SUM(1), at main(WordCount.java:72)(1/1) switched to DEPLOYING 01/15/2016 16:30:52 CHAIN DataSource (at getTextDataSet(WordCount.java:142) (org.apache.flink.api.java.io.TextInputFormat)) -> FlatMap (FlatMap at main(WordCount.java:69)) -> Combine(SUM(1), at main(WordCount.java:72)(1/1) switched to RUNNING 01/15/2016 16:30:52 Reduce (SUM(1), at main(WordCount.java:72)(1/1) switched to SCHEDULED 01/15/2016 16:30:52 Reduce (SUM(1), at main(WordCount.java:72)(1/1) switched to DEPLOYING 01/15/2016 16:30:52 CHAIN DataSource (at getTextDataSet(WordCount.java:142) (org.apache.flink.api.java.io.TextInputFormat)) -> FlatMap (FlatMap at main(WordCount.java:69)) -> Combine(SUM(1), at main(WordCount.java:72)(1/1) switched to FINISHED 01/15/2016 16:30:52 Reduce (SUM(1), at main(WordCount.java:72)(1/1) switched to RUNNING 01/15/2016 16:30:53 DataSink (CsvOutputFormat (path: file:/D:/Java/flink/flink-0.10.1/wordcount-result.txt, delimiter: ))(1/1) switched to SCHEDULED 01/15/2016 16:30:53 DataSink (CsvOutputFormat (path: file:/D:/Java/flink/flink-0.10.1/wordcount-result.txt, delimiter: ))(1/1) switched to DEPLOYING 01/15/2016 16:30:53 Reduce (SUM(1), at main(WordCount.java:72)(1/1) switched to FINISHED 01/15/2016 16:30:53 DataSink (CsvOutputFormat (path: file:/D:/Java/flink/flink-0.10.1/wordcount-result.txt, delimiter: ))(1/1) switched to RUNNING 01/15/2016 16:30:53 DataSink (CsvOutputFormat (path: file:/D:/Java/flink/flink-0.10.1/wordcount-result.txt, delimiter: ))(1/1) switched to FINISHED 01/15/2016 16:30:53 Job execution switched to status FINISHED.
可以看到輸出日志非常詳細,很方便就清楚整個運行流程,得到輸出文件 wordcount-result.txt 前面10條內容如下 :
1 1 13 1 5d002 1 740 1 about 1 account 1 administration 1 algorithms 1 and 7 another 1 any 2
關于“Flink怎么用”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。