windows:
1.启动zk zkserver
2.启动Kafka .\bin\windows\kafka-server-start.bat .\config\server.properties
3.创建主题 kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic OUT_TOPIC
4. 列出主题
kafka-topic.bat --list --zookeeper localhost:2181
5. 描述主题
kafka-topics.bat -describe -zookeeper localhost:2181 -topic [topic name]
6. 从头读取消息
kafka-console-consumer.bat -zookeeper localhost:2181 -topic [topic name] -from-beginning
7. 查看topic的详细信息
./kafka-topic.sh -zookeeper localhost:2181 -describe -topic [topic name]
8. 启动producter,启动命令如下:
kafka-console-producer.bat --broker-list localhost:9092 --topic streams-plaintext-input
9. 启动consumer,启动命令如下:
kafka-console-consumer.bat --zookeeper localhost:2181 --topic ROW_TOPIC
kafka-console-producer.bat --broker-list localhost:9092 --topic ROW_TOPIC
kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic OUT_TOPIC --from-beginning --formatter kafka.tools.DefaultMessageFormatter --property print.key=true?--property print.value=true?--property key.deserializer=org.apache.kafka.common.serialization.StringDeserializer --property value.deserializer=org.apache.kafka.common.serialization.LongDeserializer
-------------------------------------------------------
linux
1.启动Kafka,其中">>/dev/null"表示将日志信息输出到"黑洞",其中"2>&1"表示将错误信息和前面的日志信息一样,也输出到"黑洞",末尾的"&"表示以后台方式启动kafka:
bin/kafka-server-start.sh config/server.properties >>/dev/null 2>&1 &
启动kafka
bin/kafka-server-start.sh config/server.properties &
2.启动zookeeper
bin/zookeeper-server-start.sh config/zookeeper.properties &
3.停止kafka
bin/kafka-server-stop.sh
4.停止zookeeper
bin/zookeeper-server-stop.sh
5.启动生产者,往"accesslog"这个Topic中发送消息:
bin/kafka-console-producer.sh --topic accesslog --broker-list localhost:9092
6.启动消费者,从"accesslog"这个Topic中消费消息,其中"--from-beginning"为可选参数,表示要从头消费消息:
bin/kafka-console-consumer.sh --topic accesslog --from-beginning --zookeeper localhost:2181
7.创建一个名为"mytopic"的Topic:
bin/kafka-topics.sh --create --topic mytopic --replication-factor 2 --partitions 3 --zookeeper localhost:2181
8.查看"mytopic"这个Topic的详细信息:
bin/kafka-topics.sh --describe --topic mytopic --zookeeper localhost:2181
9.查看所有的Topic列表:
bin/kafka-topics.sh --list --zookeeper localhost:2181
修改
下面命令,增加partion数量,从10个partition增加到20个
bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic demo --partitions 20
(但是减少partition是不允许的。如果执行配置的partition变少,会抛出一个错误,显示partition数量只能增加 )