【发布时间】:2019-03-26 05:16:14
【问题描述】:
问题
我正在尝试在 docker 中运行单个 Kafka 实例。我可以创建主题,但不能从中消费或生产。当我尝试我的 Kafka 代理时,会记录一条错误消息。
kafka_1 | [2019-03-24 16:45:05,263] ERROR [KafkaApi-5] Number of alive brokers '0' does not meet the required replication factor '1' for the offsets topic (configured via 'offsets.topic.replication.factor'). This error can be ignored if the cluster is starting up and not all brokers are up yet. (kafka.server.KafkaApis)
我不明白Number of alive brokers '0' 位,因为它是一个 Kafka 代理,它正在记录这个,所以肯定至少有一个代理(本身)?
我正在使用默认的server.properties 文件,并进行了以下更改:
listeners=PLAINTEXT://0.0.0.0:9092
advertised.listeners=PLAINTEXT://192.168.0.109:9092
zookeeper.connect=zookeeper:2181
192.168.0.109 是我的主机 IP。
文件
码头工人撰写
version: '3.4'
services:
zookeeper:
build:
context: ./
dockerfile: zookeeper.dockerfile
network: host
image: zookeeper
ports:
- "2181:2181"
kafka:
build:
context: ./
dockerfile: kafka.dockerfile
network: host
image: kafka
ports:
- "9092:9092"
kafka.dockerfile
FROM alpine:3.7
# Set the name for a non-priliaged user
ENV APPUSER=appuser
# Install dependnacies
RUN apk add bash
RUN apk add openjdk8-jre
# Add a non-privilaged user and change into it's home directory
RUN adduser -D $APPUSER
WORKDIR /home/$APPUSER
# Download kafka and set its owner to $APPUSER
RUN wget https://www-eu.apache.org/dist/kafka/2.1.0/kafka_2.11-2.1.0.tgz
RUN chown $APPUSER kafka_2.11-2.1.0.tgz
# Change to the non-privilaged user
USER $APPUSER
# Extract kafka
RUN tar -xzf kafka_2.11-2.1.0.tgz
# copy custom server.properties into image
COPY ./server.properties ./
# Set working directory to kafka dir
WORKDIR /home/$APPUSER/kafka_2.11-2.1.0
# start kafka with customer server.properties file
CMD ["bin/kafka-server-start.sh", "../server.properties"]
zookeeper.dockerfile
FROM alpine:3.7
# Set the name for a non-priliaged user
ENV APPUSER=appuser
# Install dependnacies
RUN apk add bash
RUN apk add openjdk8-jre
# Add a non-privilaged user and change into it's home directory
RUN adduser -D $APPUSER
WORKDIR /home/$APPUSER
# Download kafka and set its owner to $APPUSER
RUN wget https://www-eu.apache.org/dist/kafka/2.1.0/kafka_2.11-2.1.0.tgz
RUN chown $APPUSER kafka_2.11-2.1.0.tgz
# Change to the non-privilaged user
USER $APPUSER
# Extract kafka
RUN tar -xzf kafka_2.11-2.1.0.tgz
# Set working directory to kafka dir
WORKDIR /home/$APPUSER/kafka_2.11-2.1.0
# Run zookeeper
CMD ["bin/zookeeper-server-start.sh", "config/zookeeper.properties"]
【问题讨论】:
-
当它们已经预先构建时,您是否有理由制作自己的 Kafka 和 ZK docker 镜像? hub.docker.com/r/confluentinc
-
作为学习练习。虽然我认为我在使用预构建图像时实际上遇到了类似的错误。
-
只是一个建议,但可能从预先构建的图像开始,因为网络和 Kafka 配置可能很繁琐。一旦你完成了这项工作,就可以开始 DIY 图像了。
-
按照您的建议使用我的设置和预先构建的图像似乎突出了问题。如果我使用
advertised.listeners=PLAINTEXT://localhost:9092而不是advertised.listeners=PLAINTEXT://192.168.0.109:9092一切正常。知道为什么吗? -
原来是我的防火墙设置!
标签: docker apache-kafka