1. 启动指令.
nohup ./kafka-server-start.sh ../config/server.properties &
2. topic 管理指令
2.1 查看topic
./kafka-topics.sh --bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092 --list
2.2 创建topic
./kafka-topics.sh --bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092 --create --topic test-topic --replication-factor 3 --partitions 3
2.3查看topic 详细信息
./kafka-topics.sh --bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092 --describe --topic test-topic
2.4 修改topic日志存储时长(单位: ms).
kafka-configs.sh --bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092 --entity-type topics --entity-name test-topic --alter --add-config retention.ms=86400000
2.5 修改topic 分区数据
./kafka-topics.sh --bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092 -alter --partitions 4 --topic test-topic
2.6 修改topic 副本数,不推荐使用,建议重新创建topic .
vim increase-replication-factor.json
{
"version":1,
"partitions":[{"topic":"test-topic","partition":0,"replicas":[0,1]},
{"topic":"three","partition":1,"replicas":[0,1]},
{"topic":"three","partition":2,"replicas":[1,0]},
{"topic":"three","partition":3,"replicas":[1,0]}]
}
执行副本存储计划
./kafka-reassign-partitions.sh --bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092 --reassignment-json-file increase-replication-factor.json --execute
验证副本存储计划
./kafka-reassign-partitions.sh --
bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092 --reassignment-json-file increase-replication-factor.json --verify
3. 生产者和消费者
3.1 生产者
./kafka-console-producer.sh --bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092 --topic test-topic
3.2 消费者
3.2.1 从创建topic开始消费
./kafka-console-consumer.sh --bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092 --topic test-topic --from-beginning
3.2.2从最新数据开始消费.
./kafka-console-consumer.sh --bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092 --topic test-topic
3.3 消费者
./kafka-console-producer.sh --bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092 --topic test-topic
4. topic 压测
4.1 生产者压测:
./kafka-producer-perf-test.sh --topic test-topic --record-size 1024 --num-records 1000000 --throughput -1 --producer-props bootstrap.servers=hdp1:9092,hdp2:9092,hdp3:9092 batch.size=4096 linger.ms=0
4.2 消费者压测:
./kafka-consumer-perf-test.sh --bootstrap-server hdp1:9092,hdp2:9092,hdp3:9092 --topic test-topic --messages 1000000 --consumer.config ../config/consumer.properties