Docker-compose部署kafka

Docker-compose部署kafka

1. 配置docker-compose.yml

version: '3'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    ports:
      - "2181:2181"
  kafka:
    image: wurstmeister/kafka
    depends_on: [ zookeeper ]
    ports:
      - "9092:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: 172.22.44.182
      KAFKA_CREATE_TOPICS: "test:1:1"
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
    volumes:
      - /data/product/zj_bigdata/data/kafka/docker.sock:/var/run/docker.sock

2. 在docker-compose.yml文件目录下进行服务打包

docker-compose build

3. 启动服务

docker-compose up -d

4. 启动测试

4.1 进入kafka容器

docker exec -it kafka_kafka_1 bash

4.2 创建topic

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

4.3 生产者

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

4.4 消费者

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

4.5 kafka集群管理界面

docker run -itd --name=kafka-manager -p 9000:9000 -e ZK_HOSTS="172.22.44.182:2181" sheepkiller/kafka-manager

4.6 访问界面

http://172.22.44.182:9000

你可能感兴趣的:(大数据,Kafka,Docker,kafka,docker)