docke-compose.yml
docker-compose.yaml
version: '3' services: zookeeper: image: wurstmeister/zookeeper container_name: zookeeper # always restart restart: always ports: - 2181 : 2181 kafka: image: wurstmeister/kafka container_name: kafka ports: - 9092 : 9092 # host ip environment: KAFKA_ADVERTISED_HOST_NAME: 宿主机IP KAFKA_ZOOKEEPER_CONNECT: zookeeper : 2181 KAFKA_ADVERTISED_LISTENERS: PLAINTEXT : //宿主机IP : 9092 ## 修改:宿主机IP KAFKA_ADVERTISED_PORT: 9092 KAFKA_BROKER_ID: 1 KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 depends_on: - zookeeper # always restart restart: always volumes: - ./docker .sock: /var/run/docker.sock kafka-manager: image: sheepkiller/kafka-manager ## 镜像:开源的web管理kafka集群的界面 environment: ZK_HOSTS: 宿主机IP ## 修改:宿主机IP ports: - "9000:9000" |
---|
启动:
docker-compose up -d
测试:
登陆:docker exec -it kafka bash
创建topic:
kafka-topics.sh --create --topic test --zookeeper zookeeper:2181 --replication-factor 1 --partitions 1
查看topic:
kafka-topics.sh --zookeeper zookeeper:2181 --describe --topic test
生产消息:
kafka-console-producer.sh --topic=test --broker-list kafka:9092
消费消息:
kafka-console-consumer.sh --bootstrap-server kafka:9092 --from-beginning --topic test
按照上面的测试没有问题的话,就证明搭建成功