同样基于docker-compose安装,Docker快速部署nginx中有讲到,不在重述
1. 编写docker-compose.yml
个人习惯放在/opt/下,如/opt/kafka, /opt/nginx, docker-compose.yml如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| version: '3' services: zookeeper: image: 大专栏 Docker快速安装kafkalass="string">wurstmeister/zookeeper ports: - "2181:2181" kafka: image: wurstmeister/kafka ports: - "9092:9092" environment: KAFKA_ADVERTISED_HOST_NAME: 192.168.153.152 KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 volumes: - /var/run/docker.sock:/var/run/docker.sock
|
2. 启动kafka
docker-compose up -d
Creating kafka_kafka_1 … done
Creating kafka_zookeeper_1 … done
3. 消息生产消费验证
1 2 3 4 5 6 7 8 9 10 11 12
| docker exec -it kafka_kafka_1 /bin/bash
kafka-topics.sh --create --topic test --zookeeper kafka_zookeeper_1:2181 --replication-factor 1 --partitions 1
kafka-topics.sh --list --zookeeper kafka_zookeeper_1:2181
kafka-console-producer.sh --topic=test --broker-list kafka_kafka_1:9092
kafka-console-consumer.sh --bootstrap-server kafka_kafka_1:9092 --from-beginning --topic test
|
如果正常的话,发布的消息能够接收到,开始愉悦的kafka之旅吧~~~