Kafka命令行操作
//启动kafka服务,三台主机分别输入此指令:
kafka-server-start.sh $KAFKA_HOME/config/server.properties &
//以后台的方式启动
nohup kafka-server-start.sh $KAFKA_HOME/config/server.properties &
//查看topic名
kafka-topics.sh --list --zookeeper hadoop-001:2181
//创建topic名
kafka-topics.sh --create --zookeeper hadoop-001:2181 --replication-factor 3 --partitions 1 --topic first
//创建生产者
kafka-console-producer.sh --broker-list hadoop-001:9092,hadoop-002:9092,hadoop-003:9092 --topic first
//创建消费者
kafka-console-consumer.sh --zookeeper hadoop-001:2181 --from-beginning --topic first
1)查看当前服务器中的所有topic
kafka-topics.sh --list --zookeeper hadoop-001:2181
2)创建topic
kafka-topics.sh --create --zookeeper hadoop-001:2181 --replication-factor 3 --partitions 1 --topic first
选项说明:
–topic 定义topic名
–replication-factor 定义副本数
–partitions 定义分区数
3) 删除topic
kafka-topics.sh --delete --zookeeper hadoop-001:2181 --topic first
需要server.properties中设置delete.topic.enable=true否则只是标记删除或者直接重启。
4)发送消息
kafka-console-producer.sh --broker-list hadoop-001:9092 --topic first
hello world
hadoop hadoop
5)消费消息
kafka-console-consumer.sh --zookeeper hadoop-001:2181 --from-beginning --topic first
6)查看某个Topic的详情
kafka-topics.sh --topic first --describe --zookeeper hadoop-002:2181