root连接kafka
时间: 2023-10-08 22:05:04 浏览: 100
kafka安装 docker安装kafka zookeeper
要连接Kafka,您需要安装Kafka客户端和Zookeeper客户端。您可以通过以下步骤在root用户下连接Kafka:
1. 安装Kafka和Zookeeper客户端:
```
sudo apt update
sudo apt install default-jre
wget https://downloads.apache.org/kafka/2.8.0/kafka_2.13-2.8.0.tgz
tar xzf kafka_2.13-2.8.0.tgz
cd kafka_2.13-2.8.0
wget https://downloads.apache.org/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0-bin.tar.gz
tar xzf apache-zookeeper-3.7.0-bin.tar.gz
```
2. 启动Zookeeper:
```
cd apache-zookeeper-3.7.0-bin/
bin/zkServer.sh start
```
3. 启动Kafka:
```
cd kafka_2.13-2.8.0
bin/kafka-server-start.sh config/server.properties
```
4. 创建一个主题:
```
bin/kafka-topics.sh --create --topic my-topic --bootstrap-server localhost:9092
```
5. 发送消息到主题:
```
bin/kafka-console-producer.sh --topic my-topic --bootstrap-server localhost:9092
```
6. 在新的终端中,消费消息:
```
bin/kafka-console-consumer.sh --topic my-topic --from-beginning --bootstrap-server localhost:9092
```
现在,您已经成功地连接到Kafka并可以发送和接收消息了。
阅读全文