kafka by docker-compose
目录
Kafka的一些命令(Docker),kafka by docker-compose,kafka in docker 通过docker-compose管理。
一、Kafka-docker
git clone https://github.com/wurstmeister/kafka-docker
二、编辑kafka监听地址
1 2 |
# vim docker-compose.yml KAFKA_ADVERTISED_HOST_NAME: 公网IP |
三、kafka 查看topic
1 |
docker exec -ti kafka-docker_kafka_1 /opt/kafka/bin/kafka-topics.sh --list --zookeeper zookeeper:2181 |
四、kafka 创建topic
1 |
docker exec -ti kafka-docker_kafka_1 /opt/kafka/bin/kafka-topics.sh -create -zookeeper zookeeper:2181 --replication-factor 1 --partitions 1 --topic cppla |
五、kafka查看topic的副本和分区
1 |
docker exec -ti kafka-docker_kafka_1 /opt/kafka/bin/kafka-topics.sh --describe --zookeeper=zookeeper:2181 --topic cppla |
六、kafka生产消息
1 2 3 |
容器网络:docker exec -ti kafka-docker_kafka_1 /opt/kafka/bin/kafka-console-producer.sh --broker-list kafka-docker_kafka_1:9092 --topic cppla 机器内网:docker exec -ti kafka-docker_kafka_1 /opt/kafka/bin/kafka-console-producer.sh --broker-list 10.0.4.11:32768 --topic cppla 机器公网:docker exec -ti kafka-docker_kafka_1 /opt/kafka/bin/kafka-console-producer.sh --broker-list 43.154.xxx.xx:32768 --topic cppla |
七、kafka消费消息
1 2 3 |
容器网络:docker exec -ti kafka-docker_kafka_1 /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server kafka-docker_kafka_1:9092 --topic cppla --from-beginning 机器内网:docker exec -ti kafka-docker_kafka_1 /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server 10.0.4.11:32768 --topic cppla --from-beginning 机器公网:docker exec -ti kafka-docker_kafka_1 /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server 43.154.xxx.xx:32768 --topic cppla --from-beginning |