Kafka集羣安裝

   1.下載kafka正式版html

http://kafka.apache.org/downloads.htmljava


    2.在Linux下解壓targit

tar -xzfkafka_2.9.2-0.8.1.1.tgzgithub


   3.修改server.propertiesweb

進入kafka根目錄config/server.propertiesapache

主要修改的有4個參數以下:bootstrap

broker.id=0 //broker的標識(正數),集羣內各個broker.id不能重複。api

port=9092 //端口號,單節點內各個port不能重複(爲了方便看最好不一樣節點端口也不要重複)app

log.dir =/tmp //存儲log的地方(數據文件)。工具

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.驗證是否安裝成功

    1. start server

>bin/zookeeper-server-start.sh config/zookeeper.properties

>bin/kafka-server-start.sh config/server.properties

第一行是啓動kafka自身帶動zookeeper,若是集羣有zookeeper能夠忽略。


    1. 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


    1. Send somemessages

> bin/kafka-console-producer.sh --broker-list dn1:9092,dn2:9092,dn3:9092 --topic test1


    1. Start a consumer

>bin/kafka-console-consumer.sh --zookeeper dn1:2181,dn2:2181,dn3:2181 --from-beginning --topic test1

kafka-console-producer.shkafka-console-cousumer.sh只是系統提供的命令行工具。這裏啓動是爲了測試是否能正常生產消費,驗證流程正確性,在實際開發中仍是要自行開發本身的生產者與消費者。


  7.分發到kafka集羣節點

cp kafka安裝文件並修正3中的參數


  1. 啓動各個節點的kafka服務

nohup./kafka-server-start.sh config/server.properties > output2>&1 &



  1. Kafka的具體使用方法請參照官網

http://kafka.apache.org/documentation.html


    8.Web UI 安裝

8.1 Kafka webconsole UI

下載:https://github.com/claudemamo/kafka-web-console


編譯:目前只提供sbt。命令:sbt dist(會生產zip包方便部署和啓動)


解壓

unzip kafka-web-console-2.1.0-SNAPSHOT.zip  

cd kafka-web-console-2.1.0-SNAPSHOT/bin  


第一次啓動時要加個參數:

./kafka-web-console -DapplyEvolutions.default=true   


默認是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) 


查看幫助 和 後臺運行:

./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


官網:

http://quantifind.github.io/KafkaOffsetMonitor/


編譯:提供了jar包,不須要本身編譯

運行命令

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管理界面


下載源碼,運行命令:sbtclean dist生產zip包。

解壓就能夠用。


運行命令:

./kafka-manager-Dconfig.file=../conf/application.conf -Dhttp.port=8080


Web端地址:http://localhost:port/


  1. kafka經常使用命令


建立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分區

./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中元數據,數據文件還需手動刪除。

相關文章
相關標籤/搜索