docs: update kafka/setup

This commit is contained in:
Administrator 2022-01-18 13:58:50 +00:00 committed by John Smith
parent 034974f35e
commit 837bb77e5b

View File

@ -2,13 +2,109 @@
title: 安装
description:
published: true
date: 2022-01-18T13:27:38.792Z
date: 2022-01-18T13:58:48.981Z
tags: kafka
editor: markdown
dateCreated: 2022-01-18T13:27:38.792Z
---
### 下载Kafka
# 下载Kafka
[传送门](https://kafka.apache.org/documentation/)
# 修改配置
## 修改 zookeeper 配置
打开 `config/zookeeper.properties` 配置文件
修改配置
```properties
clientPort=2181
```
## 修改 kafka 配置
打开 `config/server.properties` 配置文件
取消注释并修改配置
```properties
listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://host:9092
```
# 启动
进入 `bin/` 目录
## 启动 zookeeper
直接启动
```bash
$ ./zookeeper-server-start.sh ../config/zookeeper.properties
```
后台启动并将日志输入到指定文件
```bash
$ nohup ./zookeeper-server-start.sh ../config/zookeeper.properties > ../logs/zookeeper.log 2>&1 &
```
## 启动 kafka
直接启动
```bash
$ ./kafka-server-start.sh ../config/server.properties
```
后台启动并将日志输入到指定文件
```bash
$ nohup ./kafka-server-start.sh ../config/server.properties > ../logs/kafka.log 2>&1 &
```
# 测试
进入 `bin/` 目录
## 添加 topic
```bash
$ ./kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic kafkatest
```
## 启动 producer
```bash
$ ./kafka-console-producer.sh --broker-list localhost:9092 --topic kafkatest
```
## 启动 consumer
```bash
$ ./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic kafkatest --from-beginning
```
## 测试消息
在 producer 中输入内容并回车,查看 consumer 输出内容是否相同
# 停止
进入 `bin/` 目录
## 停止 kafka
```bash
$ ./kafka-server-stop.sh
```
## 停止 zookeeper
```bash
$ ./zookeeper-server-stop.sh
```