docker部署kafka集群

    科技2024-10-01  23

    docker部署kafka集群

    安装docker-compose

    sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose

    拉取镜像

    # zookeeper镜像 docker pull zookeeper # kafka-manager镜像 docker pull sheepkiller/kafka-manager # kafka镜像 docker pull wurstmeister/kafka

    创建docker-compose.yml文件

    注意将192.168.1.193替换自己的ip

    version: '2' services: # zookeeper注册中心 zookeeper: image: zookeeper ports: - "2181:2181" # kafka管理后台 kafka-manager: image: sheepkiller/kafka-manager environment: ZK_HOSTS: 192.168.1.193:2181 APPLICATION_SECRET: "GX" ports: - "9000:9000" expose: - "9000" kafka0: image: wurstmeister/kafka build: . ports: - "9092:9092" environment: KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092 KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.1.193:9092 KAFKA_BROKER_ID: 0 KAFKA_CREATE_TOPICS: "test:1:1" KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 kafka1: image: wurstmeister/kafka build: . ports: - "9093:9093" environment: KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9093 KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.1.193:9093 KAFKA_BROKER_ID: 1 KAFKA_CREATE_TOPICS: "test:1:1" KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 kafka2: image: wurstmeister/kafka build: . ports: - "9094:9094" environment: KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9094 KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.1.193:9094 KAFKA_BROKER_ID: 2 KAFKA_CREATE_TOPICS: "test:1:1" KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181

    启动kafka

    进入docker-compose.yml所在目录,执行命令

    docker-compose up -d

    这样就启动成功了

    访问kafka-manager

    http://[自己的ip]:9000 添加集群

    Cluster Name:自定义名称Cluster Zookeeper Hosts:zookeeper的ip和端口 然后点击下面的save按钮
    Processed: 0.011, SQL: 8