嗨:我是 kafka 新手,我按照以下步骤在我的 mac 上安装和初始化 kafka:
brew install kafka
我可以看到配置文件是:
/usr/local/etc/kafka/server.properties
/usr/local/etc/kafka/zookeeper.properties
启动kafka
kafka-server-start /usr/local/etc/kafka/server.properties &
创建一个名为“test”的主题
kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
我可以列出来:
kafka-topics --list --zookeeper localhost:2181
在一个终端中启动生产者并输入一些文本:
kafka-console-producer.sh --broker-list localhost:9092 --topic test
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/x/Documents/zk/server1/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/Cellar/kafka/2.0.0/libexec/libs/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
>1st line
>
启动消费者
kafka-console-consumer --bootstrap-server localhost:9092 --topic test --from-beginning
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/x/Documents/zk/server1/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/Cellar/kafka/2.0.0/libexec/libs/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
无论我在生产者终端中输入什么,消费者都不会打印任何内容。如何解决这个问题,我错过了什么吗?
从以下位置下载 apache Kafka: https://www.apache.org/dyn/closer.cgi?path=/kafka/2.0.0/kafka_2.11-2.0.0.tgz
在任意位置解压,然后在所有终端中执行以下命令,这样下面的命令就可以生效,否则可以替换命令中的安装路径并执行。
export kafka=<location-of-unzipped-directory>
$kafka/bin/zookeeper-server-start.sh $kafka/config/zookeeper.properties
$kafka/bin/kafka-server-start.sh $kafka/config/server.properties
$kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
$kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
您可以在 .bashrc 或 .zshrc 中添加以下命令,而不是记住命令
export kafka="/Users/mac-user/standalone/kafka_2.11-2.0.0"
alias startkafka="$kafka/bin/kafka-server-start.sh $kafka/config/server.properties"
alias startzoo="$kafka/bin/zookeeper-server-start.sh $kafka/config/zookeeper.properties"
alias stopkafka="$kafka/bin/kafka-server-stop.sh"
alias stopzoo="$kafka/bin/zookeeper-server-stop.sh"
brew install kafka
完成后,运行这些:
brew services start zookeeper
brew services start kafka
需要先启动zookeeper,然后启动kafka!!!