docker安装kafka

6 篇文章 0 订阅

单机版

window下

新建一个文件 kafka-alone.yml,文件内容如下:

version: '2'

services:
  zk:
    image: zookeeper:3.6
    container_name: zk_c0
    ports:
      - 2181:2181
      
  kafka:
    image: wurstmeister/kafka:2.12-2.5.0
    hostname: kafka-alone
    container_name: kafka_c0
    ports:
    - 9092:9092
    environment:
      KAFKA_ADVERTISED_HOST_NAME: localhost
      KAFKA_ADVERTISED_PORT: 9092
      KAFKA_ZOOKEEPER_CONNECT: zk:2181
    volumes:
    - D:/mount/kafka/logs:/kafka

D:/mount/kafka/logs 是挂载的目录,提前创建好即可

运行命令:

docker compose -f kafka-alone.yml create

linux下

修改一个挂载目录即可

集群版

新建一个文件 kafka-cloud.yml,文件内容如下:

version: '2'

services:
  zk1:
    image: zookeeper:3.6
    restart: always
    container_name: zk_c1
    ports:
      - 2181:2181
    environment:
      ZOO_MY_ID: 1
      ZOO_SERVERS: server.1=zk1:2888:3888 server.2=zk2:4888:5888 server.3=zk3:6888:7888
  zk2:
    image: zookeeper:3.6
    restart: always
    container_name: zk_c2
    ports:
      - 2182:2181
    environment:
      ZOO_MY_ID: 2
      ZOO_SERVERS: server.1=zk1:2888:3888 server.2=zk2:4888:5888 server.3=zk3:6888:7888
  zk3:
    image: zookeeper:3.6
    restart: always
    container_name: zk_c3
    ports:
      - 2183:2181
    environment:
      ZOO_MY_ID: 3
      ZOO_SERVERS: server.1=zk1:2888:3888 server.2=zk2:4888:5888 server.3=zk3:6888:7888
      
  kafka1:
    image: wurstmeister/kafka:2.12-2.5.0
    restart: always
    hostname: kafka1
    container_name: kafka1
    ports:
    - 9092:9092
    environment:
      KAFKA_ADVERTISED_HOST_NAME: kafka1
      KAFKA_ADVERTISED_PORT: 9092
      KAFKA_ZOOKEEPER_CONNECT: zk1:2181,zk2:2181,zk3:2181
    volumes:
    - /opt/kfkluster/kafka1/logs:/kafka
    external_links:
    - zk1
    - zk2
    - zk3

  kafka2:
    image: wurstmeister/kafka:2.12-2.5.0
    restart: always
    hostname: kafka2
    container_name: kafka2
    ports:
    - 9093:9093
    environment:
      KAFKA_ADVERTISED_HOST_NAME: kafka2
      KAFKA_ADVERTISED_PORT: 9093
      KAFKA_ZOOKEEPER_CONNECT: zk1:2181,zk2:2181,zk3:2181
    volumes:
    - /opt/kfkluster/kafka2/logs:/kafka
    external_links:
    - zk1
    - zk2
    - zk3

  kafka3:
    image: wurstmeister/kafka:2.12-2.5.0
    restart: always
    hostname: kafka3
    container_name: kafka3
    ports:
    - 9094:9094
    environment:
      KAFKA_ADVERTISED_HOST_NAME: kafka3
      KAFKA_ADVERTISED_PORT: 9094
      KAFKA_ZOOKEEPER_CONNECT: zk1:2181,zk2:2181,zk3:2181
    volumes:
    - /opt/kfkluster/kafka3/logs:/kafka
    external_links:
    - zk1
    - zk2
    - zk3

运行命令:

docker compose -f kafka-cloud.yml create

#下载Kafka可视化工具

Kafka Tool

具体使用步骤参考:https://www.cnblogs.com/frankdeng/p/9452982.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值