一、增長kafka分區json
./kafka-topics.sh --zookeeper 192.168.2.70 --alter --topic us_forward --partitions 24ide
二、查看kafka的topicspa
./kafka-topics.sh --zookeeper 192.168.2.70 --listserver
三、查看單個topic的分區,也能夠不加topickafka
./kafka-topics.sh --zookeeper 192.168.2.70 --describe --topic us_generalit
Topic: us_general Partition: 0 Leader: 117 Replicas: 117 Isr: 117io
Topic: us_general Partition: 1 Leader: 117 Replicas: 117 Isr: 117console
四、查看kafka各個組的偏移量class
./kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zookeeper 192.168.110.165:2181 -group test_groupidtest
五、啓動kafka
bin/kafka-server-start.sh config/server.properties &
六、建立topic
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 2 --partitions 24 --topic topic_test
七、發送消息
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic page_visits
八、消費消息
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic page_visits --from-beginning
九、刪除topic
bin/kafka-topics.sh --zookeeper zk_host:port --delete --topic my_topic_name
十、從新平衡分區和領導者
./kafka-preferred-replica-election.sh --zookeeper 192.168.2.70
十一、擴展集羣
1)、先把要轉移的topic寫成json格式topics-to-move.json
{"topics": [
{"topic": "SYNC_DATABASE_UPDATE"},
{"topic": "SYNC_REALTIME_ALARM"},
{"topic": "SYNC_STATION_INFO"},
{"topic": "SYNC_VEHICLE_REG"},
{"topic": "ds_ctrlreq"},
{"topic": "us_ctrlrsp"},
{"topic": "us_forward"},
{"topic": "us_general"},
{"topic": "us_packet"}
],
"version":1
}
2)、用腳本生成一個自動分區的計劃
./kafka-reassign-partitions.sh --zookeeper 192.168.2.70 --generate --topics-to-move-json-file topics-to-move.json --broker-list 1,2,3
3)、把生成的建議分區保存成json topics-to-move-execute.json
4)、執行分區計劃
/kafka-reassign-partitions.sh --zookeeper 192.168.2.70 --reassignment-json-file topics-to-move-execute.json --execute
5)、檢查集羣擴展是否完成
/kafka-reassign-partitions.sh --zookeeper 192.168.2.70 --reassignment-json-file topics-to-move-execute.json --verify
十二、增長副本數
1)、編寫擴展文件,能夠利用擴展集羣的方式導出如今的分佈而後作修改
{ "version":1,
"partitions":[{"topic":"foo","partition":0,"replicas":[5,6,7]}]
}
2)、執行分區計劃
/kafka-reassign-partitions.sh --zookeeper 192.168.2.70 --reassignment-json-file topics-to-move-execute.json --execute
3)、檢查集羣擴展是否完成
/kafka-reassign-partitions.sh --zookeeper 192.168.2.70 --reassignment-json-file topics-to-move-execute.json --verify