您好,登錄后才能下訂單哦!
這篇文章主要講解了“Kafka集群的安裝過程”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“Kafka集群的安裝過程”吧!
1.下載kafka正式版
http://kafka.apache.org/downloads.html
2.在Linux下解壓tar包
tar -xzfkafka_2.9.2-0.8.1.1.tgz
3.修改server.properties
進(jìn)入kafka根目錄config/server.properties
主要修改的有4個參數(shù)如下:
broker.id=0 //broker的標(biāo)識(正數(shù)),集群內(nèi)各個broker.id不能重復(fù)。
port=9092 //端口號,單節(jié)點(diǎn)內(nèi)各個port不能重復(fù)(為了方便看最好不同節(jié)點(diǎn)端口也不要重復(fù))。
log.dir =/tmp //存儲log的地方(數(shù)據(jù)文件)。
zookeeper.connect= dn1:2181,dn2:2181,dn3:2181
4.配置producer.properties
# list of brokers used for bootstrapping knowledge about the rest of the cluster
# format: host1:port1,host2:port2 ...
metadata.broker.list=dn1:9092,dn2:9092,dn3:9092
5.配置consumer.properties
# Zookeeper connection string
# comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002"
zookeeper.connect=dn1:2181,dn2:2181,dn3:2181
6.驗證是否安裝成功
start server
>bin/zookeeper-server-start.sh config/zookeeper.properties
>bin/kafka-server-start.sh config/server.properties
第一行是啟動kafka自身帶動zookeeper,如果集群有zookeeper可以忽略。
Create a topic
>bin/kafka-topics.sh --zookeeper dn1:2181,dn2:2181,dn3:2181 --topic test1 --replication-factor 3 --partitions 1 --create
>bin/kafka-topics.sh --zookeeper dn1:2181,dn2:2181,dn3:2181 --topic test1 --describe
Send somemessages
> bin/kafka-console-producer.sh --broker-list dn1:9092,dn2:9092,dn3:9092 --topic test1
Start a consumer
>bin/kafka-console-consumer.sh --zookeeper dn1:2181,dn2:2181,dn3:2181 --from-beginning --topic test1
kafka-console-producer.sh和kafka-console-cousumer.sh只是系統(tǒng)提供的命令行工具。這里啟動是為了測試是否能正常生產(chǎn)消費(fèi),驗證流程正確性,在實(shí)際開發(fā)中還是要自行開發(fā)自己的生產(chǎn)者與消費(fèi)者。
7.分發(fā)到kafka集群節(jié)點(diǎn)
cp kafka安裝文件并修正3中的參數(shù)
啟動各個節(jié)點(diǎn)的kafka服務(wù)
nohup./kafka-server-start.sh config/server.properties > output2>&1 &
Kafka的具體使用方法請參照官網(wǎng)
http://kafka.apache.org/documentation.html
8.Web UI 安裝
8.1 Kafka webconsole UI
下載:https://github.com/claudemamo/kafka-web-console
編譯:目前只提供sbt。命令:sbt dist(會生產(chǎn)zip包方便部署和啟動)
解壓
unzip kafka-web-console-2.1.0-SNAPSHOT.zip
cd kafka-web-console-2.1.0-SNAPSHOT/bin
第一次啟動時要加個參數(shù):
./kafka-web-console -DapplyEvolutions.default=true
默認(rèn)是9000端口,如需修改啟動如下:
./kafka-web-console -DapplyEvolutions.default=true-Dhttp.port=19000
不然會報錯:
[warn] play - Run with -DapplyEvolutions.default=true if you want to run them automatically (be careful)
Oops, cannot start the server.
@6k1jkg3be: Database 'default' needs evolution!
at play.api.db.evolutions.EvolutionsPlugin
anonfun$onStart$1anonfun$apply$1.apply$mcV$sp(Evolutions.scala:484)
查看幫助 和 后臺運(yùn)行:
./kafka-web-console -h
nohup ./kafka-web-console >/dev/null 2>&1 &
Web端地址:http://localhost:9000/
建議:這個第三方WEBUI比較直觀,而且簡單方便使用。
8.2KafkaOffsetMonitor UI
下載包
https://github.com/quantifind/KafkaOffsetMonitor/releases/tag/v0.2.0
官網(wǎng):
http://quantifind.github.io/KafkaOffsetMonitor/
編譯:提供了jar包,不需要自己編譯
運(yùn)行命令
java –cpKafkaOffsetMonitor-assembly-0.2.0.jar \
com.quantifind.kafka.offsetapp.OffsetGetterWeb\
--zk zk-01,zk-02 \
--port 8080 \
--refresh 5.minutes \
--retain 1.day
Web端地址:http://localhost:port/
8.3kafkaManager UI
下載https://github.com/yahoo/kafka-manager
Yahoo的出的kafka管理界面
下載源碼,運(yùn)行命令:sbtclean dist生產(chǎn)zip包。
解壓就可以用。
運(yùn)行命令:
./kafka-manager-Dconfig.file=../conf/application.conf -Dhttp.port=8080
Web端地址:http://localhost:port/
kafka常用命令
創(chuàng)建topic
/kafka-topics.sh --create --zookeeper 192.168.153.128:2181 --replication-factor 1--partitions 1 --topic test123
查看topic信息
./kafka-topics.sh --describe --topic test123 --zookeeper 192.168.153.128:2181
修改topic分區(qū)
./kafka-topics.sh --alter --topic test123 --partitions 2 --zookeeper 192.168.153.128:2181
刪除topic
./kafka-run-class.shkafka.admin.DeleteTopicCommand --topic test1 --zookeeper192.168.35.122:2181,192.168.35.123:2181
只是刪除了zookeeper中元數(shù)據(jù),數(shù)據(jù)文件還需手動刪除。
感謝各位的閱讀,以上就是“Kafka集群的安裝過程”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對Kafka集群的安裝過程這一問題有了更深刻的體會,具體使用情況還需要大家實(shí)踐驗證。這里是億速云,小編將為大家推送更多相關(guān)知識點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。