当前位置:   article > 正文

kafka3.7 集群 docker部署 springboot_docker pull apache/kafka:3.7.0

docker pull apache/kafka:3.7.0

前提

你需要知道docker使用、springboot整合kafka

拉取kafka3.7镜像

docker pull apache/kafka:3.7.0

创建数据卷映射

创建以下两个目录(演示使用两个kafka节点)用于日志存储

  1. /logs/kafka/kafka-node1
  2. /logs/kafka/kafka-node2
  3. #设置文件权限
  4. sudo chmod 777 /logs/kafka/*

编写kafka-compose.yml

  1. version: '3'
  2. services:
  3. kafka-node1:
  4. image: apache/kafka:3.7.0
  5. container_name: kafka-node1
  6. networks:
  7. - kafka-cluster
  8. ports:
  9. - "9191:9092"
  10. - "9192:9093"
  11. volumes:
  12. - /logs/kafka/kafka-node1:/tmp/kafka-logs
  13. environment:
  14. KAFKA_PROCESS_ROLES: "broker,controller"
  15. KAFKA_NODE_ID: "1"
  16. KAFKA_CONTROLLER_QUORUM_VOTERS: "1@kafka-node1:9093,2@kafka-node2:9093"
  17. KAFKA_LISTENERS: "PLAINTEXT://0.0.0.0:9092,CONTROLLER://0.0.0.0:9093"
  18. KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://192.168.86.99:9191"
  19. KAFKA_CONTROLLER_LISTENER_NAMES: "CONTROLLER"
  20. KAFKA_INTER_BROKER_LISTENER_NAME: "PLAINTEXT"
  21. KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: "1"
  22. KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: "1"
  23. KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: "1"
  24. kafka-node2:
  25. image: apache/kafka:3.7.0
  26. container_name: kafka-node2
  27. networks:
  28. - kafka-cluster
  29. ports:
  30. - "9193:9092"
  31. - "9194:9093"
  32. volumes:
  33. - /logs/kafka/kafka-node2:/tmp/kafka-logs
  34. environment:
  35. KAFKA_PROCESS_ROLES: "broker,controller"
  36. KAFKA_NODE_ID: "2"
  37. KAFKA_CONTROLLER_QUORUM_VOTERS: "1@kafka-node1:9093,2@kafka-node2:9093"
  38. KAFKA_LISTENERS: "PLAINTEXT://0.0.0.0:9092,CONTROLLER://0.0.0.0:9093"
  39. KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://192.168.86.99:9193"
  40. KAFKA_CONTROLLER_LISTENER_NAMES: "CONTROLLER"
  41. KAFKA_INTER_BROKER_LISTENER_NAME: "PLAINTEXT"
  42. KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: "1"
  43. KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: "1"
  44. KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: "1"
  45. networks:
  46. kafka-cluster:
  47. driver: bridge
  48. volumes:
  49. kraft-data1:
  50. driver: local
  51. kraft-data2:
  52. driver: local

运行

docker-compose -f kafka-compose.yml up -d

  1. docker network ls
  2. docker network inspect kafka_kafka-cluster

会自动创建网络

使用springboot测试

创建一个topic,副本为2个。

  1. @Configuration
  2. public class KafkaConfig {
  3. @Bean
  4. public NewTopic newTopic() {
  5. return new NewTopic("topic-consumer-partition", 10, (short) 2);
  6. }
  7. }

向topic发送信息,查看结果,两个节点都有备份。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/444765
推荐阅读
相关标签
  

闽ICP备14008679号