关于kafka:kafka初探

57次阅读

共计 2521 个字符,预计需要花费 7 分钟才能阅读完成。

version: "3.3"

services:
  zookeeper-server:
    image: zookeeper:3.7
    volumes:
      # zookeeper 快照数据
      - "zookeeper_data:/data"
      # zookeeper 事务日志
      - "zookeeper_datalog:/datalog"
    ports:
      # 对 client 提供服务
      - "3181:2181"
    restart: always
  zookeeper-ui:
    image: juris/zkui:latest
    ports:
      # zookeeper-ui 的 http 端口,拜访 http:// 主机 ip: 主机映射端口 (如 3180)
      - "3180:9090"
    environment:
      # zk-server 地址和端口 (配置服务名: 容器端口)
      ZK_SERVER: "zookeeper-server:2181"
      # admin 明码
      USER_SET: '{"users":[{"username":"admin","password":"admin","role":"ADMIN"}]}'
    restart: always
    depends_on:
      - zookeeper-server

  kafka-server:
    image: bitnami/kafka:3.4.0
    ports:
      # kafka 客户端连贯端口:毋庸身份认证
      - "3092:9092"
      # kafka 客户端连贯端口:须要身份认证
      - "3093:9093"
    volumes:
      # kafka 数据卷
      - "kafka_data:/bitnami/kafka"
      # 启用 SASL_PLAINTEXT 身份认证
      - "./kafka-config/kafka_jaas.conf:/opt/bitnami/kafka/config/kafka_jaas.conf"
      # 上面是两个身份认证须要的库文件 jackson-all-1.8.4.jar & VSaslLoginModule-1.0.jar
      - "./kafka-libs/jackson-all-1.8.4.jar:/opt/bitnami/kafka/libs/jackson-all-1.8.4.jar"
      - "./kafka-libs/VSaslLoginModule-1.0.jar:/opt/bitnami/kafka/libs/VSaslLoginModule-1.0.jar"
    environment:
      # 具体的环境变量参考:https://github.com/bitnami/containers/tree/main/bitnami/kafka,所有 server.properties 中的配置能够转化成:KAFKA_CFG_,例如:KAFKA_CFG_BACKGROUND_THREADS 等价于 background.threads
      # zookeeper 地址: 端口 (配置服务名: 容器端口)
      KAFKA_CFG_ZOOKEEPER_CONNECT: "zookeeper-server:2181"
      # 容许客户端 免明码登录、明文通信
      ALLOW_PLAINTEXT_LISTENER: "yes"
      # kafka 监听端口 9092 为免登录端口,9093 须要身份认证
      KAFKA_CFG_LISTENERS: "PLAINTEXT://:9092,SASL_PLAINTEXT://:9093"
      # 本服务供内部拜访的地址
      KAFKA_CFG_ADVERTISED_LISTENERS: "PLAINTEXT://10.1.27.89:3092,SASL_PLAINTEXT://10.1.27.89:3093"
      # 猜想:批示 kafka 节点之间的拜访应用哪种协定 --> 对应后面的 ADVERTISED_LISTENERS 参数
      KAFKA_CFG_SECURITY_INTER_BROKER_PROTOCOL: "PLAINTEXT"
      # 猜想:和 SECURITY_INTER_BROKER_PROTOCOL 一个含意
      KAFKA_CFG_SASL_MECHANISM_INTER_BROKER_PROTOCOL: "PLAIN"
      # 猜想:和 SECURITY_INTER_BROKER_PROTOCOL 一个含意
      KAFKA_CFG_SASL_ENABLED_MECHANISMS: "PLAIN"
      # SASL_PLAINTEXT 协定指定的身份认证回调
      KAFKA_CFG_LISTENER_NAME_SASL_PLAINTEXT_PLAIN_SASL_SERVER_CALLBACK_HANDLER_CLASS: "com.toone.v3.platform.kafka.server.login.VSaslServerCallbackHandler"
      # kafka 集群中本节点的标识
      KAFKA_BROKER_ID: "1"
      
      #内存设置
      KAFKA_HEAP_OPTS: "-Xms1024m -Xmx2048m"
    restart: always
    depends_on:
      - zookeeper-server
  kafka-ui:
    # 参见:https://www.kafkamagic.com/start/
    image: digitsy/kafka-magic:latest
    ports:
      # 拜访 kafka 治理界面:http:// 主机 ip: 主机映射端口 (如 3080)
      - "3080:80"
    volumes:
      # 长久化 kafka 集群配置
      - "./kafka_ui_config:/config"
    environment:
      KMAGIC_ALLOW_TOPIC_DELETE: "true"
      KMAGIC_ALLOW_SCHEMA_DELETE: "true"
      KMAGIC_CONFIG_STORE_TYPE: "file"
      KMAGIC_CONFIG_STORE_CONNECTION: "Data Source=/config/KafkaMagicConfig.db;"
      KMAGIC_CONFIG_ENCRYPTION_KEY: "ENTER_YOUR_KEY_HERE"
    restart: always
volumes:
  zookeeper_data:
  zookeeper_datalog:
  kafka_data:

正文完
 0