docker-compose搭建kafka集群

搭建一个2节点的kafka集群

注意:以下192.168.50.147改成你自己的ip地址

version: '3'

services:
  zookeeper:
    image: 'wurstmeister/zookeeper'
    container_name: zookeeper
    ports:
      - "2181:2181"
      
  kafka1:
    image: 'wurstmeister/kafka'
    container_name: kafka1
    ports:
      - "9092:9092"
    environment:
      KAFKA_BROKER_ID: 101
      KAFKA_ZOOKEEPER_CONNECT: 192.168.50.147:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.50.147:9092
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
      TZ: "Asia/Shanghai"

  kafka2:
    image: 'wurstmeister/kafka'
    container_name: kafka2
    ports:
      - "9093:9093"
    environment:
      KAFKA_BROKER_ID: 102
      KAFKA_ZOOKEEPER_CONNECT: 192.168.50.147:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.50.147:9093
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9093
      TZ: "Asia/Shanghai"

      
  kafka-map:
    image: 'dushixiang/kafka-map'
    container_name: kafka-map
    ports:
      - "8089:8080"
    environment:
      DEFAULT_USERNAME: admin
      DEFAULT_PASSWORD: admin
  

如果用kafka-manager,则用以下代码

  kafka-manager:
    image: 'sheepkiller/kafka-manager'
    container_name: kafka-manager
    ports:
      - "9000:9000"
    environment:
      ZK_HOSTS: 192.168.50.147:2181

看结果:

http://192.168.50.147:8089/#/login
这个界面出来了就好了。
用户名,密码都是admin

docker-compose搭建kafka集群_第1张图片

添加集群

docker-compose搭建kafka集群_第2张图片

你可能感兴趣的:(docker,kafka,容器)