• Docker 安装Kafka


    第一步:查看本地镜像、检索Kafka镜像和下载Kafka 镜像

    # 查看本地镜像

    docker images

    # 检索Kafka镜像

    docker search kafka

    # 下载Kafka 镜像指定版本

    docker pull wurstmeister/kafka:latest

    1. [root@localhost ~]# docker images
    2. REPOSITORY TAG IMAGE ID CREATED SIZE
    3. nginx latest 0e901e68141f 2 months ago 142MB
    4. mysql 5.7 2a0961b7de03 2 months ago 462MB
    5. minio/minio latest e31e0721a96b 7 months ago 406MB
    6. zookeeper latest 36c607e7b14d 7 months ago 278MB
    7. rabbitmq management 6c3c2a225947 7 months ago 253MB
    8. elasticsearch 7.6.2 f29a1ee41030 2 years ago 791MB
    9. delron/fastdfs latest 8487e86fc6ee 4 years ago 464MB
    10. [root@localhost ~]# docker search kafka
    11. NAME DESCRIPTION STARS OFFICIAL AUTOMATED
    12. bitnami/kafka Apache Kafka is a distributed streaming plat… 520 [OK]
    13. bitnami/kafka-exporter 8
    14. ubuntu/kafka Apache Kafka, a distributed event streaming … 7
    15. bitnami/kafka-trigger-controller Source for this controller is in the kubeles… 5
    16. ibmcom/kafka Docker Image for IBM Cloud Private-CE (Commu… 5
    17. [root@localhost ~]# docker search wurstmeister/kafka
    18. NAME DESCRIPTION STARS OFFICIAL AUTOMATED
    19. wurstmeister/kafka Multi-Broker Apache Kafka Image 1511 [OK]
    20. [root@localhost ~]# docker pull wurstmeister/kafka:latest
    21. latest: Pulling from wurstmeister/kafka
    22. 540db60ca938: Pull complete
    23. f0698009749d: Pull complete
    24. d67ee08425e3: Pull complete
    25. 1a56bfced4ac: Pull complete
    26. dccb9e5a402a: Pull complete
    27. Digest: sha256:4916aa312512d255a6d82bed2dc5fbee29df717fd9efbdfd673fc81c6ce03a5f
    28. Status: Downloaded newer image for wurstmeister/kafka:latest

    第二步:启动Zookeeper

    Docker 安装ZooKeeper 请参考:Docker安装ZooKeeper

    第三步:启动Kafka

    docker run -d --name kafka \
    -p 9092:9092 \
    -e KAFKA_BROKER_ID=0 \
    -e KAFKA_ZOOKEEPER_CONNECT=192.168.43.10:2181 \
    -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.43.10:9092 \
    -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 wurstmeister/kafka 

    1. [root@localhost ~]# docker run -d --name kafka \
    2. > -p 9092:9092 \
    3. > -e KAFKA_BROKER_ID=0 \
    4. > -e KAFKA_ZOOKEEPER_CONNECT=192.168.43.10:2181 \
    5. > -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.43.10:9092 \
    6. > -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 wurstmeister/kafka
    7. 06a66409d7ced3540f02fb0f793a0ece1e103464a17037b1ae855d8f8e9e7b56
    8. [root@localhost ~]# docker ps
    9. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    10. 06a66409d7ce wurstmeister/kafka "start-kafka.sh" 3 minutes ago Up 3 minutes 0.0.0.0:9092->9092/tcp kafka
    11. 1c3d38b948ba zookeeper "/docker-entrypoint.…" 10 hours ago Up 10 hours 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, 8080/tcp zookeeper
    12. 62233dfad35b minio/minio "/usr/bin/docker-ent…" 23 hours ago Up 23 hours minio-server
    13. 4b0032878886 6c3c2a225947 "docker-entrypoint.s…" 5 days ago Up 4 days 4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp rabbitmq

    第五步:验证ZooKeeper 和Kafka 容器状态

    # 进入ZooKeeper 容器内部

    docker exec -it 1c3d38b948ba /bin/bash

    # 运行zkCli 客户端指令

    zkCli.sh -server 192.168.43.10

    1. [root@localhost ~]# docker exec -it 1c3d38b948ba /bin/bash
    2. root@1c3d38b948ba:/apache-zookeeper-3.7.0-bin# pwd
    3. /apache-zookeeper-3.7.0-bin
    4. root@1c3d38b948ba:/apache-zookeeper-3.7.0-bin# cd bin/
    5. root@1c3d38b948ba:/apache-zookeeper-3.7.0-bin/bin# zkCli.sh -server 192.168.43.10:2181
    6. [zk: 192.168.43.10:2181(CONNECTING) 0] ls /
    7. [admin, brokers, cluster, config, consumers, controller, controller_epoch, feature, isr_change_notification, latest_producer_id_block, log_dir_event_notification, zookeeper]
    8. [zk: 192.168.43.10:2181(CONNECTED) 1] ls /zookeeper
    9. [config, quota]
    10. [zk: 192.168.43.10:2181(CONNECTED) 2] quit
    11. WATCHER::
    12. WatchedEvent state:Closed type:None path:null

    # 进入Kafka 容器内部

    docker exec -it 06a66409d7ce /bin/sh

    1. [root@localhost ~]# docker exec -it 06a66409d7ce /bin/sh
    2. / # ps -ef
    3. PID USER TIME COMMAND
    4. 1 root 0:30 /usr/lib/jvm/zulu8-ca/bin/java -Xmx1G -Xms1G -server -XX:+
    5. 520 root 0:00 /bin/sh
    6. 526 root 0:00 ps -ef

    第六步:Kafka 创建Topic 流程步骤

    #进入容器
    docker exec -it ${CONTAINER ID} /bin/bash
    cd /opt/kafka_2.13-2.8.1/bin
    #单机方式:创建一个主题
    bin/kafka-topics.sh --create --zookeeper 192.168.43.10:2181 --replication-factor 1 --partitions 1 --topic mykafka
    #运行一个生产者
    bin/kafka-console-producer.sh --broker-list 192.168.43.10:9092 --topic mykafka
    #运行一个消费者
    bin/kafka-console-consumer.sh --zookeeper 192.168.43.10:2181 --topic mykafka --from-beginning
  • 相关阅读:
    【每日一好题】官方题解看不懂,别怕我教你吊打官方题解:重新格式化电话号码
    中秋海报制作不求人,详细教程来袭
    用EasyV实现地图下钻,快速查看省市区热力值,老板看了都说好!
    Node.js | express 中间件详解(应用级 | 路由级 | 内置(托管静态资源) | 第三方)
    MySQL 常用函数的使用
    Android MediaCodec硬件解码视频播放
    vite 关于 global is not defined 问题
    智能两轮电动车成消费新宠,利尔达电动车软硬件一体解决方案引领“智慧升级”
    跨平台Markdown编辑软件Typora mac中文版功能介绍
    朋友圈如何设置定时发送?
  • 原文地址:https://blog.csdn.net/zhouzhiwengang/article/details/126172296