环境:
- centos7
- 安装docker docker-compose
- 关闭防火墙
下载镜像包:
docker pull docker.io/wurstmeister/kafka
docker pull docker.io/wurstmeister/zookeeper
编写docker-compose.yml
version: '2'
services:
download_zookeeper_1:
image: wurstmeister/zookeeper
ports:
- "2181:2181"
download_kafka_1:
image: wurstmeister/kafka
ports:
- "9092"
environment:
KAFKA_ADVERTISED_HOST_NAME: 192.168.88.15
KAFKA_ZOOKEEPER_CONNECT: download_zookeeper_1:2181
volumes:
- /var/run/docker.sock:/var/run/docker.sock
启动:
docker-compose up -d
查看日志是否成功:
docker logs download_download_zookeeper_1_1
docker logs download_download_kafka_1_1
测试:
#创建主题
bin/kafka-topics.sh --create --topic test --zookeeper download_download_zookeeper_1_1:2181 --replication-factor 1 --partitions 1
#生成数据
bin/kafka-console-producer.sh --topic=test --broker-list download_download_kafka_1_1:9092
#消费数据
bin/kafka-console-consumer.sh --bootstrap-server download_download_kafka_1_1:9092 --from-beginning --topic test
over!
网友评论