在 Ubuntu 上,Kafka 本身的配置主要集中在 Kafka 安装目录下的 config 目录。下面是常见情况和路径说明:
如果你是通过 官方 TGZ 包 安装的(最常见):
cd /opt/kafka
# 或
cd ~/kafka
配置目录通常是:
/opt/kafka/config/
主要配置文件:
| 文件 | 作用 |
|---|---|
server.properties |
Kafka Broker 核心配置 ✅ |
producer.properties |
生产者配置 |
consumer.properties |
消费者配置 |
zookeeper.properties |
Zookeeper 配置(旧版本) |
server.properties |
KRaft 模式下的 broker 配置(新版本) |
✅ 最常见的配置都在 server.properties
# broker id
broker.id=0
# 监听地址(重要)
listeners=PLAINTEXT://localhost:9092
# 日志存储目录
log.dirs=/tmp/kafka-logs
# Zookeeper(旧版本)
zookeeper.connect=localhost:2181
# KRaft 模式(Kafka 3.x+)
process.roles=broker,controller
node.id=1
controller.quorum.voters=1@localhost:9093
如果你是通过 systemd 启动 Kafka:
sudo systemctl status kafka
服务文件通常在:
/etc/systemd/system/kafka.service
其中会指定:
ExecStart=/opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties
✅ 修改配置后需重启:
sudo systemctl restart kafka
/opt/kafka/config/zookeeper.properties
常见配置:
dataDir=/var/lib/zookeeper
clientPort=2181
有时 Kafka 启动会读取:
~/.bashrc
/etc/profile
export KAFKA_HOME=/opt/kafka
export PATH=$KAFKA_HOME/bin:$PATH
ps aux | grep kafka
你会看到类似:
kafka-server-start.sh /opt/kafka/config/server.properties
✅ 这就是当前 Kafka 使用的配置文件路径。
Ubuntu 上 Kafka 的核心配置在:
<kafka安装目录>/config/server.properties
如果你愿意,可以告诉我:
我可以给你一份 生产级配置示例 ✅