1. 安装zookeeper
查找镜像:
docker search zookeeper
拉取镜像:
docker pull wurstmeister/zookeeper
创建并启动zookeeper容器
docker run -d --name zookeeper -p 2181:2181 wurstmeister/zookeeper
2.安装kafka
查找镜像
docker search kafka
拉取镜像:
docker pull wurstmeister/kafka
创建并启动kafka容器,连接到上一步创建的zookeeper
docker run -d --name kafka --publish 9092:9092 --link zookeeper --env KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 --env KAFKA_ADVERTISED_HOST_NAME=localhost --env KAFKA_ADVERTISED_PORT=9092 wurstmeister/kafka
3.操作
1.如何进入kafka终端命令行:
C:\Users\2019051634>docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a4855e784c7e wurstmeister/kafka “start-kafka.sh” 17 minutes ago Up 17 minutes 0.0.0.0:9092->9092/tcp kafka
30fd2cdbc0a7 wurstmeister/zookeeper “/bin/sh -c '/usr/sb…” 22 minutes ago Up 22 minutes 22/tcp, 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp zookeeper
docker exec -it kafka /bin/sh
2.创建 topic
kafka-topics.sh --zookeeper 172.17.0.2:2181 --create --topic king --replication-factor 1 --partitions 8
3.查看 topic
kafka-topics.sh --zookeeper 172.17.0.2:2181 --list
5.修改topic分区数
/ # kafka-topics.sh --zookeeper 172.17.0.2:2181 --alter --topic my-topic --partitions 2
6.删除topic
/ # kafka-topics.sh --zookeeper 172.17.0.2:2181 --delete --topic my-topic
7.查看日志文件目录
在/kafka/kafka-logs-a4855e784c7e 下面
或者使用 这个命令
kafka-topics.sh --zookeeper 172.17.0.2:2181 --describe
8.查看zookeeper或者kafka的网络地址
docker inspect kafka
"Networks": { "bridge": { "IPAMConfig": null, "Links": null, "Aliases": null, "NetworkID": "54f04dc09d0c17e06c22a082486f7c1aac3c526780da739c95e907d47b29628a", "EndpointID": "5d7d353710b97530a025860f8471d14682a862d62e0f3923ef0e13cf04cb93d0", "Gateway": "172.17.0.1", "IPAddress": "172.17.0.3", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "02:42:ac:11:00:03", "DriverOpts": null } }
9.终端生产数据
/ # kafka-console-producer.sh --broker-list 172.17.0.3:9092 --topic king
james
mark
king
10.终端消费数据
kafka-console-consumer.sh --bootstrap-server 172.17.0.3:9092 --topic king --from-beginning
11.查看配置文件:
find / -name *server.properties*
bash-5.1# find / -name server.properties
/opt/kafka_2.13-2.8.1/config/server.properties
大功告成!!