docker/docker-compose kafka單機
阿新 • • 發佈:2021-01-19
技術標籤:mq
docker版本
ZK: docker run -d --name zookeeper -p 2181:2181 \ -e ALLOW_ANONYMOUS_LOGIN=yes bitnami/zookeeper:latest kafka: docker run -d --restart always --link zookeeper --name kafka -p 9092:9092 \ -v /home/data/kafka:/bitnami/kafka \ -e KAFKA_BROKER_ID=1 \ -e KAFKA_LISTENERS=PLAINTEXT://:9092 \ -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092 \ -e KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 \ -e ALLOW_PLAINTEXT_LISTENER=yes \ --user root \ bitnami/kafka:latest
docker-compose版本
version: "3" services: zookeeper: image: 'bitnami/zookeeper:latest' container_name: zookeeper restart: always networks: - kafka_net ports: - '2181:2181' environment: - ALLOW_ANONYMOUS_LOGIN=yes kafka: image: 'bitnami/kafka:latest' container_name: kafka user: root restart: always networks: - kafka_net ports: - '9092:9092' volumes: - /home/data/kafka:/bitnami/kafka # - /etc/kafka/config:/opt/bitnami/kafka/config environment: - KAFKA_BROKER_ID=1 - KAFKA_LISTENERS=PLAINTEXT://:9092 - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092 - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 - ALLOW_PLAINTEXT_LISTENER=yes depends_on: - zookeeper networks: kafka_net: driver: bridge
測試
docker-compose -f kafka-zk-docker-compose.yml up -d
docker exec -it kafka /bin/bash
kafka-topics.sh --zookeeper zookeeper:2181 --describe --topic gpsData
幾個注意點
①如果啟動報錯檔案建立許可權不足,可使用root使用者
②啟動報錯(叢集ID與meta.properties(server.properties裡的log.dirs目錄下)裡的叢集ID不一致):The Cluster ID RTovJYwSRkSIIfgQI84Fzw doesn't match stored clusterId Some(bSfECuywSNKE75QHAMDCvw) in meta.properties. The broker is trying to join the wrong cluster. Configured zookeeper.connect may be wrong.,解決方式1:刪除meta.properties或整個log.dirs目錄(丟資料),修改meta.properties的cluster.id與報錯資訊一致
更多參考