简体   繁体   English

带有 docker 的 KAFKA:集群离线但容器根据“docker ps -a”启动

[英]KAFKA with docker : cluster offline but container are up according "to docker ps -a"

I'm new with kafka and i'm trying to do something simple.我是 kafka 的新手,我正在尝试做一些简单的事情。

I run kafka with docker. here is my docker-compose:我用 docker 运行 kafka。这是我的 docker-compose:

version: "3.2"
services:
  zookeeper:
    image: wurstmeister/zookeeper
    ports:
      - "2181"

  kafka:
    image: wurstmeister/kafka
    depends_on:
      - zookeeper
    ports:
      - "9092-9094:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: 127.0.0.1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

  kafkaui:
    image: provectuslabs/kafka-ui
    depends_on:
      - kafka
      - zookeeper
    ports:
      - "8080:8080"
    environment:
      KAFKA_CLUSTERS_0_NAME: local
      KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: "kafka:9092"

As you can see, I put the My IP as 127.0.0.1 for KAFKA_ADVERTISED_HOST_NAMEE如您所见,我将 My IP 作为KAFKA_ADVERTISED_HOST_NAMEE的 127.0.0.1

then i do: docker-compose up -d and i check with docker ps -a and I see this screenshot enter image description here然后我这样做: docker-compose up -d我检查with docker ps -a我看到这个截图在这里输入图像描述

Then I raise the number of broker: docker-compose up --scale kafka=3 -d I check with docker ps -a and I see this screeshot: enter image description here然后我增加经纪人的数量: docker-compose up --scale kafka=3 -d我检查docker ps -a我看到这个截图:在此处输入图像描述

on my browser, i go to: http://127.0.0.1:8080 and I see that I have 1 cluster offline, see screenshot: enter image description here在我的浏览器上,我 go 到: http://127.0.0.1:8080我看到我有 1 个集群离线,看截图:在此处输入图像描述

why???为什么??? I have an old computer: linux mint 21, 4 Gb RAM, intel Core i3我有一台旧电脑:linux mint 21、4 Gb RAM、intel Core i3

Do I need more RAM?我需要更多内存吗?

RAM is not the problem内存不是问题

It's offline because it cannot connect.它处于离线状态,因为它无法连接。 KAFKA_ADVERTISED_HOST_NAME: 127.0.0.1 + ports: 9092:9092 means it only accept connections from the external host, not other containers. KAFKA_ADVERTISED_HOST_NAME: 127.0.0.1 + ports: 9092:9092意味着它只接受来自外部主机的连接,而不是其他容器。 You will not be able to scale the container with that variable set, as it needs to be kafka , but it also cannot be hardcoded to kafka when you scale beyond one broker (in other words, each container needs a unique hostname).您将无法使用该变量集扩展容器,因为它必须是kafka ,但是当您扩展到一个代理之外时,它也不能硬编码为kafka (换句话说,每个容器都需要一个唯一的主机名)。 This page covers more details . 此页面包含更多详细信息 But, one solution is using KAFKA_LISTENERS: PLAINTEXT://:9092 instead, and remove ports from Compose unless you really need connectivity outside of Docker.但是,一种解决方案是改用KAFKA_LISTENERS: PLAINTEXT://:9092 ,并从 Compose 中删除ports ,除非您确实需要 Docker 之外的连接。

There is no real benefit to running more than one broker on the same host, anyway.无论如何,在同一台主机上运行多个代理并没有真正的好处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM