赞
踩
在kafka安装的目录下执行
bin/kafka-server-start.sh -daemon config/server.properties
(注意server.properties 的目录和当前所在目录)
以下是通过脚本启动kafka集群
#!/bin/bash
case $1 in
"start")
for i in 192.168.37.131 192.168.37.132 192.168.37.133 192.168.37.134
do
echo "-----启动 $i kafka------"
ssh $i "/var/dalong/kafka/bin/kafka-server-start.sh -daemon /var/dalong/kafka/config/server.properties"
done
;;
"start")
for i in 192.168.37.131 192.168.37.132 192.168.37.133 192.168.37.134
do
echo "-----停止 $i kafka------"
ssh $i "/var/dalong/kafka/bin/kafka-server-stop.sh "
done
;;
esac
连接上kafka
列出
bin/kafka-topics.sh --bootstrap-server 192.168.37.133:9092 --list
创建
bin/kafka-topics.sh --bootstrap-server 192.168.37.133:9092 --topic first --create --partitions 1 --replication-factor 3
bin/kafka-topics.sh --bootstrap-server 192.168.37.133:9092 --topic first --describe
消息生产:
kafka-console-producer.sh --bootstrap-server 192.168.37.132:9092 --topic first
消息消费:
kafka-console-consumer.sh --bootstrap-server 192.168.37.132:9092 --topic first
历史消息
kafka-console-consumer.sh --bootstrap-server 192.168.37.132:9092 --topic first --from-beginning
查看消息组信息
kafka-consumer-groups.sh --bootstrap-server 192.168.37.131:9092 --list
查看分组详情
kafka-consumer-groups.sh --bootstrap-server 192.168.37.131:9092 --describe --group XXDD3
退役节点 节点数据转移
{
"topics":[
{"topic":"six"}
],
"version":1
}
kafka-reassign-partitions.sh --bootstrap-server 192.168.37.133:9092 --topics-to-move.json --broker-list "0,2" --generate
-
- [root@k8s-master01 datas]# kafka-reassign-partitions.sh --bootstrap-server 192.168.37.133:9092 --topics-to-move-json-file topics-to-move.json --broker-list "0,2" --generate
- Current partition replica assignment
- {"version":1,"partitions":[{"topic":"six","partition":0,"replicas":[0,1],"log_dirs":["any","any"]},{"topic":"six","partition":1,"replicas":[2,0],"log_dirs":["any","any"]},{"topic":"six","partition":2,"replicas":[1,2],"log_dirs":["any","any"]}]}
-
- Proposed partition reassignment configuration
- {"version":1,"partitions":[{"topic":"six","partition":0,"replicas":[0,2],"log_dirs":["any","any"]},{"topic":"six","partition":1,"replicas":[2,0],"log_dirs":["any","any"]},{"topic":"six","partition":2,"replicas":[0,2],"log_dirs":["any","any"]}]}
-
将以下内容保存为文件 命名为increase-replication-factor.json
{"version":1,"partitions":[{"topic":"six","partition":0,"replicas":[0,2],"log_dirs":["any","any"]},{"topic":"six","partition":1,"replicas":[2,0],"log_dirs":["any","any"]},{"topic":"six","partition":2,"replicas":[0,2],"log_dirs":["any","any"]}]}
再执行计划
kafka-reassign-partitions.sh --bootstrap-server 192.168.37.133:9092 --reassignment-json-file increase-replication-factor.json --execute
执行计划前分区情况
执行计划后分区情况
kafka启动报错
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。