Docker 安装 kafka

Docker 安装 kafka

  • 1 Docker 创建 network
    • 1 docker network 命令
    • 2 docker network 创建
  • 2 Docker 下载 image
  • 3 Doker 安装 container
    • 1 安装 zookeeper
    • 2 验证 zookeeper
    • 3 安装 kafka
    • 4 验证 kafka
    • 3 kafka-map

1 Docker 创建 network

1 docker network 命令

# 创建网络 test
docker network create test
# 将mysql容器或其他容器加入到test网络
docker network connect test mysql
# 查看全部网络
docker network ls
# 删除网络test
docker network rm test
# 将mysql容器或其他容器从test网络钟移除
docker network disconnect test mysql
# 查看网络内部信息
docker network inspect test

2 docker network 创建

C:\Windows\System32>docker network create kafka
142a549e3e3fe0974fe7eaa8ef239304b60459f2e43ecb76db4bd81c63fc7b78

C:\Windows\System32>

2 Docker 下载 image

dockers pull bitnami/kafka
dockers pull bitnami/zookeeper
dockers pull dushixiang/kafka-map
C:\Windows\System32>docker images
REPOSITORY             TAG       IMAGE ID       CREATED         SIZE
bitnami/kafka          latest    97b3440e5598   21 hours ago    551MB
bitnami/zookeeper      latest    714253cd23db   43 hours ago    509MB
dushixiang/kafka-map   latest    b711e1fb5c60   15 months ago   295MB

3 Doker 安装 container

1 安装 zookeeper

PS C:\Users\Administrator\Desktop> docker run -d --name zookeeper --network kafka -p 2181:2181 --privileged=true --restart always -e TZ="Asia/Shanghai" -e ALLOW_ANONYMOUS_LOGIN=yes bitnami/zookeeper:latest
f6f4fbf5106406c49501bf0784852ea5d31bcc76b3c84854e64fddecc150ee94
PS C:\Users\Administrator\Desktop>
PS C:\Users\Administrator\Desktop> docker ps
CONTAINER ID   IMAGE                      COMMAND                  CREATED              STATUS              PORTS                                                  NAMES
f6f4fbf51064   bitnami/zookeeper:latest   "/opt/bitnami/script…"   About a minute ago   Up About a minute   2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, 8080/tcp   zookeeper

2 验证 zookeeper

可以使用以下工具来连接 Zookeeper
1 PrettyZoo
2 ZooKeeper Assistant
Docker 安装 kafka_第1张图片

3 安装 kafka

PS C:\Users\Administrator> docker run -d --name kafka --restart=always --network kafka -p 9092:9092 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 -e ALLOW_PLAINTEXT_LISTENER=yes -e KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181 -e KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://192.168.1.92:9092 bitnami/kafka:latest
a271677bc9d119df53fc5a7c4443e071179ab340c845f9e48e5a20b0e3f72f4c
PS C:\Users\Administrator> docker ps
CONTAINER ID   IMAGE                      COMMAND                  CREATED          STATUS          PORTS                                                  NAMES
a271677bc9d1   bitnami/kafka:latest       "/opt/bitnami/script…"   21 seconds ago   Up 20 seconds   0.0.0.0:9092->9092/tcp                                 kafka
c3293bb650f7   bitnami/zookeeper:latest   "/opt/bitnami/script…"   8 minutes ago    Up 8 minutes    2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, 8080/tcp   zookeeper

4 验证 kafka

进入 kafka

PS C:\Users\Administrator> docker exec -it kafka /bin/sh

创建 topic

$ kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test
Created topic test.

查看 topic

$ kafka-topics.sh --describe --bootstrap-server localhost:9092 --topic test
Topic: test     TopicId: Ymx-mlyVREumia-pNm4PBA PartitionCount: 1       ReplicationFactor: 1    Configs:
        Topic: test     Partition: 0    Leader: 1001    Replicas: 1001  Isr: 1001

可以使用以下工具来连接 kafka
Kafka Assistant
Docker 安装 kafka_第2张图片

3 kafka-map

C:\Windows\System32>docker run -d --name kafka-map --network kafka -p 9001:8080 -e DEFAULT_USERNAME=admin -e DEFAULT_PASSWORD=admin --restart always dushixiang/kafka-map:latest
bd6a61167625e3135c52e56df232aabcc4bcde026807a4dbe1bdfcb3b9a1f72b

Docker 安装 kafka_第3张图片

你可能感兴趣的:(SpringBoot-2.X,kafka,docker,分布式,zookeeper,kafka,map)