欢迎光临
我们一直在努力

使用 Docker 安装 Kafka 测试环境

1、下载镜像

1.1 zookeeper

-> docker pull wurstmeister/zookeeper
Using default tag: latest
latest: Pulling from wurstmeister/zookeeper
Digest: sha256:7a7fd44a72104bfbd24a77844bad5fabc86485b036f988ea927d1780782a6680
Status: Image is up to date for wurstmeister/zookeeper:latest
docker.io/wurstmeister/zookeeper:latest

1.2 kafka

-> docker pull wurstmeister/kafka
Using default tag: latest
latest: Pulling from wurstmeister/kafka
Digest: sha256:dabb003ac62ae8a47f69a47bbe04bdf4507e926f4d461f7b4b2ed4d8d9167ae2
Status: Image is up to date for wurstmeister/kafka:latest
docker.io/wurstmeister/kafka:latest
-> docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
wurstmeister/kafka         latest              55d8b709494e        3 weeks ago         432MB
wurstmeister/zookeeper     latest              3f43f72cb283        14 months ago       510MB

2、启动容器

2.1 启动zookeeper容器

-> docker run -d --name zookeeper -p 2181:2181 -t wurstmeister/zookeeper

2.2 启动kafka容器

-> docker run -d --name kafka --publish 9092:9092 --link zookeeper --env KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 --env KAFKA_ADVERTISED_HOST_NAME=10.235.173.16 --env KAFKA_ADVERTISED_PORT=9092  wurstmeister/kafka:latest

10.235.173.16 是docker内网IP

-> docker ps
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                                                NAMES
75f2ce770727        wurstmeister/kafka:latest   "start-kafka.sh"         About an hour ago   Up About an hour    0.0.0.0:9092->9092/tcp                               kafka
7e93e254d792        wurstmeister/zookeeper      "/bin/sh -c '/usr/sb…"   About an hour ago   Up About an hour    22/tcp, 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp   zookeeper

3、测试Kafka

3.1 创建 topic

-> docker exec -it kafka bash
bash-4.4# kafka-topics.sh --zookeeper 172.17.0.2:2181 --create --topic ithothub --partitions 10 --replication-factor 1
Created topic ithothub.
bash-4.4# kafka-topics.sh --zookeeper 172.17.0.2:2181 --list
ithothub
  • –zookeeper 172.17.0.2:2181  # 是zookeeper 容器IP
  • –create –topic ithothub    #  topic
  • –partitions 10   # 分区
  • –replication-factor 1  # 副本
bash-4.4# kafka-topics.sh --describe --bootstrap-server 127.0.0.1:9092 --topic ithothub
Topic: ithothub	PartitionCount: 10	ReplicationFactor: 1	Configs: segment.bytes=1073741824
  Topic: ithothub	Partition: 0	Leader: 1001	Replicas: 1001	Isr: 1001
  Topic: ithothub	Partition: 1	Leader: 1001	Replicas: 1001	Isr: 1001
  Topic: ithothub	Partition: 2	Leader: 1001	Replicas: 1001	Isr: 1001
  Topic: ithothub	Partition: 3	Leader: 1001	Replicas: 1001	Isr: 1001
  Topic: ithothub	Partition: 4	Leader: 1001	Replicas: 1001	Isr: 1001
  Topic: ithothub	Partition: 5	Leader: 1001	Replicas: 1001	Isr: 1001
  Topic: ithothub	Partition: 6	Leader: 1001	Replicas: 1001	Isr: 1001
  Topic: ithothub	Partition: 7	Leader: 1001	Replicas: 1001	Isr: 1001
  Topic: ithothub	Partition: 8	Leader: 1001	Replicas: 1001	Isr: 1001
  Topic: ithothub	Partition: 9	Leader: 1001	Replicas: 1001	Isr: 1001
赞(2) 打赏
转载请注明来源:IT技术资讯 » 使用 Docker 安装 Kafka 测试环境

评论 抢沙发

评论前必须登录!

 

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏