1 簡介
NiFi是一個易用蛋褥、可靠、功能強大的數(shù)據(jù)處理與分發(fā)系統(tǒng)鳄虱,是Apache的開源項目。只需在web界面中用拖拽的方式定義數(shù)據(jù)處理節(jié)點凭峡,數(shù)據(jù)處理流程和配置相關(guān)參數(shù)拙已,NiFi即可自動完成復(fù)雜的數(shù)據(jù)處理任務(wù),非常方便摧冀。
這里介紹NiFi 1.8.0的安裝和啟動方法倍踪。
2 安裝
NiFi的安裝使用非常簡單系宫,只需配置好JAVA環(huán)境,將官網(wǎng)上下載的NiFi二進制包解壓建车,然后進入bin目錄扩借,執(zhí)行./nifi.sh start
,即可啟動NiFi缤至。
當(dāng)然潮罪,這種方式運行的是單機版的NiFi,如果要進行分布式安裝领斥,還需要進行其他一些配置嫉到。
分布式的NiFi需要使用Zookeeper作為集群的管理工具,NiFi本身內(nèi)置了Zookeeeper月洛,也可以使用獨立安裝的Zookeeper何恶。
2.1 使用內(nèi)置Zookeeper
對每一個節(jié)點完成以下配置(建議在一個節(jié)點配置好,復(fù)制到其他節(jié)點再稍作修改)
① 修改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ù)集群的實際情況修改
② 在state/zookeeper文件夾下新建myid文件嚼黔,寫入節(jié)點編號
mkdir state
mkdir state/zookeeper
echo 1 > state/zookeeper/myid
不同節(jié)點寫入的標號不同细层,要與第一步中的server編號對應(yīng)
③ 修改conf/nifi.properties
#是否啟動內(nèi)置的zk
nifi.state.management.embedded.zookeeper.start=true
#配置zk節(jié)點
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é)點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é)點需要根據(jù)實際情況修改host為節(jié)點的主機名(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 使用獨立的Zookeeper
配置步驟比使用內(nèi)置的Zookeeper方法要簡單,對比來看:
① 無需修改conf/zookeeper.properties爵卒,保持默認配置即可虚缎。
(即無需定義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
其他配置一致陌僵,按獨立安裝的Zookeeper實際情況填寫轴合。
④ 修改conf/state-management.xml
與使用內(nèi)置的Zookeeper配置相同,按獨立安裝的Zookeeper實際情況填寫碗短。
3 啟動
在每一個節(jié)點中執(zhí)行命令:
nifi/bin/nifi.sh start
啟動需要一定的時間受葛,jps
查看NiFi進程是否成功啟動:
2162 RunNiFi
2178 NiFi
1413 QuorumPeerMain
2330 Jps
從任意一個節(jié)點訪問http://localhost:8080/nifi
即可訪問NiFi主界面。(端口以配置文件中的為準)
4 關(guān)閉
在每一個節(jié)點中執(zhí)行命令:
nifi/bin/nifi.sh stop
可能遇到的問題
端口沖突
若logs/nifi-bootstrap.log中出現(xiàn)“Address already in use”偎谁,則說明端口沖突总滩,修改conf/nifi.properties中的nifi.web.http.port。NiFi的Web端口默認是8080巡雨,很容易與其他應(yīng)用闰渔,建議修改。集群啟動后铐望,無法打開web頁面
集群啟動后冈涧,有一個選取主節(jié)點的過程茂附,在此期間可能無法訪問web頁面或者提示與集群斷開連接,等待一會兒后(5-8分鐘)即可恢復(fù)正常督弓。