centos7.6-docker-compose-zookeeper-kafka-集群

-- 安装docker-compose
curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

-- 赋予执行权限
chmod +x /usr/local/bin/docker-compose

-- 拉取镜像
docker pull zookeeper:3.4
docker pull wurstmeister/kafka

-- 编写docker-compose.yaml

-- 启动服务
docker run -d zookeeper

-- 测试zookeeper
telnet 127.0.0.1 12181
docker exec -it zoo1 bash ./bin/zkServer.sh status
docker exec -it zoo2 bash ./bin/zkServer.sh status
docker exec -it zoo3 bash ./bin/zkServer.sh status

-- 测试kafka
telnet 127.0.0.1 19092

-- 链接kafka1容器
docker exec -it kafka1 /bin/bash

-- 创建topic
$KAFKA_HOME/bin/kafka-topics.sh --create --topic test --zookeeper zoo1:2181 --replication-factor 1 --partitions 1

-- 查看topic
$KAFKA_HOME/bin/kafka-topics.sh --zookeeper zoo1:2181 --describe --topic test

-- 发布消息
$KAFKA_HOME/bin/kafka-console-producer.sh --topic=test --broker-list kafka1:9092

-- 接收消息
$KAFKA_HOME/bin/kafka-console-consumer.sh --bootstrap-server kafka1:9092 --from-beginning --topic test
mkdir -p /home/docker_zoo_kafka

cat > /home/docker_zoo_kafka/docker-compose.yml <

 

说明:172.19.160.224是宿主机IP

 

转载于:https://my.oschina.net/qiongtaoli/blog/3089836

你可能感兴趣的:(centos7.6-docker-compose-zookeeper-kafka-集群)