docker 部署kafka集群

docker run 部署

shell 复制代码
docker run -d --name zookeeper --restart always -p 2181:2181 wurstmeister/zookeeper

docker run -d --name kafka1 --restart always -p 9094:9092 \
  -e KAFKA_ADVERTISED_HOST_NAME=182.54.14.45 \
  -e KAFKA_ZOOKEEPER_CONNECT=182.54.14.45:2181 \
  -e KAFKA_BROKER_ID=1 \
  -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://182.54.14.45:9094 \
  -e KAFKA_LISTENERS=PLAINTEXT://:9092 \
  -v /var/run/docker.sock:/var/run/docker.sock \
  wurstmeister/kafka:0.10.2.1

docker run -d --name kafka2 --restart always -p 9093:9092 \
  -e KAFKA_ADVERTISED_HOST_NAME=182.54.14.45 \
  -e KAFKA_ZOOKEEPER_CONNECT=182.54.14.45:2181 \
  -e KAFKA_BROKER_ID=2 \
  -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://182.54.14.45:9093 \
  -e KAFKA_LISTENERS=PLAINTEXT://:9092 \
  -v /var/run/docker.sock:/var/run/docker.sock \
  wurstmeister/kafka:0.10.2.1

docker-compose.yml 部署

shell 复制代码
version: '3'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    container_name: zookeeper
    ports:
      - "2181:2181"

  kafka1:
    image: wurstmeister/kafka
    ports:
      - "9092:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: localhost
      KAFKA_CREATE_TOPICS: "topic1:1:1,topic2:1:1"
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_BROKER_ID: 1
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
    container_name: kafka1
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

  kafka2:
    image: wurstmeister/kafka
    ports:
      - "9093:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: localhost
      KAFKA_CREATE_TOPICS: "topic3:1:1,topic4:1:1"
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_BROKER_ID: 2
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9093
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9093
    container_name: kafka2
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
相关推荐
海鸥811 小时前
podman和与docker的比较 及podman使用
docker·容器·podman
GreenMountainEcho7 小时前
Kubernetes 入门篇之 Node 安装与部署
云原生·容器·kubernetes
zyk_5208 小时前
Docker desktop如何汉化
运维·docker·容器
韭菜盖饭8 小时前
解决Docker端口映射后外网无法访问的问题
运维·docker·容器
jingjingjing11119 小时前
笔记:docker安装(ubuntu 20.04)
笔记·docker·容器
qq_3392822310 小时前
docker之network
运维·docker·容器
alden_ygq10 小时前
k8s statefulset pod重启顺序
云原生·容器·kubernetes
愿你天黑有灯下雨有伞12 小时前
Docker 安装 Elasticsearch 教程
运维·elasticsearch·docker
@郭小茶12 小时前
windows部署docker
windows·docker·容器
云上艺旅13 小时前
K8S学习之基础七十二:Ingress基于Https代理pod
学习·云原生·容器·https·kubernetes