docker-compose 搭建单机kafka

docker-compose
新建docker-compose.yml

version: '3'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    container_name: zookeeper
    ports:
      - "2181:2181"
  kafka:
    image: wurstmeister/kafka
    ports:
      - "9092:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: 192.168.1.202
      KAFKA_CREATE_TOPICS: TestComposeTopic:2:1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_BROKER_ID: 1
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.1.202:9092
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
    container_name: kafka01
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

执行下面命令动态启动kafka+zookeeper
docker-compose -f docker-compose.yml up
#查看自己的kakfa+zookeeper 正常启动
docker ps
![在这里插入图片描述](https://img-blog.csdnimg.cn/c59c2f5484b142cdb0982b8876a25e0d.png#pic_center)

终端1

#进入kafka容器
docker exec -it kafka01 /bin/bash
#进入kafka 命令行
cd /opt/kafka_2.13-2.8.1/bin/
#开启生产者
kafka-console-producer.sh  --broker-list 192.168.3.109:9092 --topic TestComposeTopic

![在这里插入图片描述](https://img-blog.csdnimg.cn/82fead6065ca4480a55ac7dce7d13483.png#pic_center)

终端2

#进入kafka容器
exec -it kafka01 /bin/bash
#进入kafka 命令行
cd /opt/kafka_2.13-2.8.1/bin/
#开启消费者
kafka-console-consumer.sh --bootstrap-server 192.168.3.109:9092 --topic TestComposeTopic --from-beginning
![在这里插入图片描述](https://img-blog.csdnimg.cn/0d80cd76bc9e4e458c29fc541a203cb7.png#pic_center)




你可能感兴趣的:(工具,kafka)