Skip to content

kafka 2.12 安装

sh
 首先 安装  zookeeper     并启动 ./zkServer.sh start

 解压 kafka  的安装包 放到指定位置
 #server.properties
注意修改   zookeeper 地址
日志的地址

 # 启动
 ./kafka-server-start.sh -daemon ../config/server.properties
 #  停止
./kafka-server-stop.sh
#  创建 topic     指定分区 数  副本数
./kafka-topics.sh --create --topic dev --zookeeper localhost:2181 --partitions 1 --replication-factor 1
# 删除  topic 
./kafka-topics.sh --delete --topic dev  --zookeeper localhost:2181
#  查询  tpoic 
./kafka-topics.sh --list --zookeeper localhost:2181
#  topic 扩容
./kafka-topics.sh --alter --topic dev --zookeeper localhost:2181 --partitions 2


##   分区 迁移  
./kafka-topics.sh --create --topic new-topic --zookeeper localhost:2181 --partitions 5 --replication-factor 1
首先,生成一个分区重新分配计划文件:
./kafka-reassign-partitions.sh --zookeeper localhost:2181 --topics-to-move-json-file topics-to-move.json --broker-list "0,1,2" --generate

topics-to-move.json
{"topics": [{"topic": "old-topic"}], "version": 1}

./kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file reassignment.json --execute
./kafka-topics.sh --delete --topic old-topic --zookeeper localhost:2181
##