NiFi的分布式安裝與啟動

1 簡介

NiFi是一個(gè)易用、可靠、功能強(qiáng)大的數(shù)據(jù)處理與分發(fā)系統(tǒng),是Apache的開源項(xiàng)目。只需在web界面中用拖拽的方式定義數(shù)據(jù)處理節(jié)點(diǎn),數(shù)據(jù)處理流程和配置相關(guān)參數(shù),NiFi即可自動完成復(fù)雜的數(shù)據(jù)處理任務(wù),非常方便。

這里介紹NiFi 1.8.0的安裝和啟動方法。

2 安裝

NiFi的安裝使用非常簡單,只需配置好JAVA環(huán)境,將官網(wǎng)上下載的NiFi二進(jìn)制包解壓,然后進(jìn)入bin目錄,執(zhí)行./nifi.sh start,即可啟動NiFi。

當(dāng)然,這種方式運(yùn)行的是單機(jī)版的NiFi,如果要進(jìn)行分布式安裝,還需要進(jìn)行其他一些配置。

分布式的NiFi需要使用Zookeeper作為集群的管理工具,NiFi本身內(nèi)置了Zookeeeper,也可以使用獨(dú)立安裝的Zookeeper。

2.1 使用內(nèi)置Zookeeper

對每一個(gè)節(jié)點(diǎn)完成以下配置(建議在一個(gè)節(jié)點(diǎn)配置好,復(fù)制到其他節(jié)點(diǎn)再稍作修改)

① 修改conf/zookeeper.properties

clientPort=2181
initLimit=10
autopurge.purgeInterval=24
syncLimit=5
tickTime=2000
dataDir=./state/zookeeper
autopurge.snapRetainCount=30

#
# Specifies the servers that are part of this zookeeper ensemble. For
# every NiFi instance running an embedded zookeeper, there needs to be
# a server entry below. For instance:
#
server.1=master:2888:3888
server.2=slave1:2888:3888
server.3=slave2:2888:3888
#

最后三行根據(jù)集群的實(shí)際情況修改

② 在state/zookeeper文件夾下新建myid文件,寫入節(jié)點(diǎn)編號

mkdir state
mkdir state/zookeeper
echo 1 > state/zookeeper/myid

不同節(jié)點(diǎn)寫入的標(biāo)號不同,要與第一步中的server編號對應(yīng)

③ 修改conf/nifi.properties

#是否啟動內(nèi)置的zk
nifi.state.management.embedded.zookeeper.start=true
#配置zk節(jié)點(diǎn)
nifi.zookeeper.connect.string=master:2181,slave1:2181,slave2:2181
#這里配置為非安全性的nifi
nifi.cluster.protocol.is.secure=false
nifi.cluster.is.node=true
nifi.cluster.node.address=master
nifi.cluster.node.protocol.port=11443
nifi.cluster.node.protocol.threads=10
nifi.cluster.node.event.history.size=25
nifi.cluster.node.connection.timeout=5 sec
nifi.cluster.node.read.timeout=5 sec
nifi.cluster.firewall.file=

#各節(jié)點(diǎn)Site2Site協(xié)議接口配置
nifi.remote.input.host=master
nifi.remote.input.secure=false
nifi.remote.input.socket.port=10443
nifi.remote.input.http.enabled=true
nifi.remote.input.http.transaction.ttl=30 sec

#web ui
nifi.web.http.host=master
nifi.web.http.port=8080

其他節(jié)點(diǎn)需要根據(jù)實(shí)際情況修改host為節(jié)點(diǎn)的主機(jī)名(slave1,slave2等)

Slave1:

nifi.remote.input.host=slave1
nifi.web.http.host=slave1
nifi.cluster.node.address=slave1

Slave2:

nifi.remote.input.host=slave2
nifi.web.http.host=slave2
nifi.cluster.node.address=slave2

④ 修改conf/state-management.xml

<cluster-provider>
  <id>zk-provider</id>
  <class>org.apache.nifi.controller.state.providers.zookeeper.ZooKeeperStateProvider</class>
  <property name="Connect String">master:2181,slave1:2181,slave2:2181</property>
  <property name="Root Node">/nifi</property>
  <property name="Session Timeout">10 seconds</property>
  <property name="Access Control">Open</property>
</cluster-provider>

主要是修改Connect String,和第三步中的nifi.zookeeper.connect.string一致。

2.2 使用獨(dú)立的Zookeeper

配置步驟比使用內(nèi)置的Zookeeper方法要簡單,對比來看:

① 無需修改conf/zookeeper.properties,保持默認(rèn)配置即可。
(即無需定義server.1,server.2,server.3等條目)

② 無需在state/zookeeper文件夾下新建myid文件

③ 修改conf/nifi.properties
與使用內(nèi)置的Zookeeper配置基本相同,不同的配置是:

#是否啟動內(nèi)置的zk
nifi.state.management.embedded.zookeeper.start=false

其他配置一致,按獨(dú)立安裝的Zookeeper實(shí)際情況填寫。

④ 修改conf/state-management.xml
與使用內(nèi)置的Zookeeper配置相同,按獨(dú)立安裝的Zookeeper實(shí)際情況填寫。

3 啟動

在每一個(gè)節(jié)點(diǎn)中執(zhí)行命令:

nifi/bin/nifi.sh start

啟動需要一定的時(shí)間,jps查看NiFi進(jìn)程是否成功啟動:

2162 RunNiFi
2178 NiFi
1413 QuorumPeerMain
2330 Jps

從任意一個(gè)節(jié)點(diǎn)訪問http://localhost:8080/nifi即可訪問NiFi主界面。(端口以配置文件中的為準(zhǔn))

成功啟動.png
查看節(jié)點(diǎn).png

4 關(guān)閉

在每一個(gè)節(jié)點(diǎn)中執(zhí)行命令:

nifi/bin/nifi.sh stop

可能遇到的問題

  1. 端口沖突
    若logs/nifi-bootstrap.log中出現(xiàn)“Address already in use”,則說明端口沖突,修改conf/nifi.properties中的nifi.web.http.port。NiFi的Web端口默認(rèn)是8080,很容易與其他應(yīng)用,建議修改。

  2. 集群啟動后,無法打開web頁面
    集群啟動后,有一個(gè)選取主節(jié)點(diǎn)的過程,在此期間可能無法訪問web頁面或者提示與集群斷開連接,等待一會兒后(5-8分鐘)即可恢復(fù)正常。

參考資料

NiFi安裝(單機(jī)+集群)
NIFI1.7.1安裝
官方文檔

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容