当前位置:   article > 正文

docker部署kafka 单节点_docker 部署单节点kafka

docker 部署单节点kafka

镜像拉取

docker pull wurstmeister/zookeeper
docker pull wurstmeister/kafka
  • 1
  • 2

定义docker-compose.yml

version: '3'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    ports:
      - "2181:2181"
  kafka:
    image: wurstmeister/kafka:2.12-2.0.1
    depends_on: [ zookeeper ]
    ports:
      - "9092:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: 192.168.10.185
      # KAFKA_CREATE_TOPICS: "test:1:1"
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
    volumes:
      - "./kafka/kafka_compose/docker.sock:/var/run/docker.sock"
      - "./kafka/kafka_compose/data/:/kafka"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

或者

version: '3'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    ports:
      - "2181:2181"
  kafka:
    image: wurstmeister/kafka:2.12-2.0.1
    depends_on: [ zookeeper ]
    ports:
      - "9092:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: 192.168.10.185
      # KAFKA_CREATE_TOPICS: "test:1:1"
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
    volumes:
      - "./kafka/kafka_compose/docker.sock:/var/run/docker.sock"
      - "./kafka/kafka_compose/data/:/kafka"  
  kafka-manager:  
    image: sheepkiller/kafka-manager
    environment:
        ZK_HOSTS: 192.168.10.185
    ports:  
      - "9001:9000"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

[注] 192.168.10.185是本机(vm)地址。

启动服务

docker-compose up -d
  • 1

启动测试

记住启动的启动名称,kafka为 kafka_kafka_1 ,zookeeper 为 kafka_zookeeper_1 .
如果docker-compose正常启动,此时docker ps会看到以上两个容器。进入kafka容器。

docker exec -it kafka_kafka_1 bash
  • 1

创建一个topic:

$KAFKA_HOME/bin/kafka-topics.sh --create --topic test --partitions 4 --zookeeper kafka_zookeeper_1:2181 --replication-factor 1
  • 1

发布信息:

$KAFKA_HOME/bin/kafka-console-producer.sh --topic=test --broker-list kafka_kafka_1:9092
  • 1

接收消息

$KAFKA_HOME/bin/kafka-console-consumer.sh --bootstrap-server kafka_kafka_1:9092 --from-beginning --topic test
  • 1

kafka集群管理界面

docker run -itd --name=kafka-manager -p 9001:9000 -e ZK_HOSTS="192.168.10.185:2181" sheepkiller/kafka-manager
  • 1

[注] 新建Cluster的时候,Cluster Zookeeper Hosts 为 zookeeper的地址端口,如:192.168.10.185:2181。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/651950
推荐阅读
相关标签
  

闽ICP备14008679号