1、增加kafka分區
./kafka-topics.sh --zookeeper 192.168.2.70 --alter --topic us_forward --partitions 24
2、查看kafka的topic
./kafka-topics.sh --zookeeper 192.168.2.70 --list
3、查看單個topic的分區,也可以不加topic
./kafka-topics.sh --zookeeper 192.168.2.70 --describe --topic us_general
Topic: us_general Partition: 0 Leader: 117 Replicas: 117 Isr: 117
Topic: us_general Partition: 1 Leader: 117 Replicas: 117 Isr: 117
4、查看kafka各個組的偏移量
./kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zookeeper 192.168.110.165:2181 -group test_groupid
5、啓動kafka
bin/kafka-server-start.sh config/server.properties &
6、創建topic
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 2 --partitions 24 --topic topic_test
7、發送消息
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic page_visits
8、消費消息
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic page_visits --from-beginning
9、刪除topic
bin/kafka-topics.sh --zookeeper zk_host:port --delete --topic my_topic_name
10、重新平衡分區和領導者
./kafka-preferred-replica-election.sh --zookeeper 192.168.2.70
11、擴展集羣
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
12、增加副本數
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