From: Kai Moritz Date: Tue, 17 Oct 2023 15:53:20 +0000 (+0200) Subject: Setup-Verbesserungen aus grundlagen/docker übernommen X-Git-Tag: producer/simple-producer--fire+forget---2023-10-signal X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=2a96b6f1605beae9be387bc756289345bcffb6ed;p=demos%2Fkafka%2Ftraining Setup-Verbesserungen aus grundlagen/docker übernommen --- diff --git a/README.sh b/README.sh index b11792d..da053d7 100755 --- a/README.sh +++ b/README.sh @@ -23,8 +23,7 @@ else docker image ls $IMAGE fi -echo "Waiting for the Kafka-Cluster to become ready..." -docker-compose -f docker/docker-compose.yml run --rm cli cub kafka-ready -b kafka:9092 3 60 > /dev/null 2>&1 || exit 1 +docker-compose -f docker/docker-compose.yml up --remove-orphans setup || exit 1 docker-compose -f docker/docker-compose.yml up -t0 -d cli sleep 1 diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 4d385c6..d58b18f 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,39 +1,63 @@ version: '3.2' services: + zookeeper: + image: confluentinc/cp-zookeeper:7.5.1 + environment: + ZOOKEEPER_CLIENT_PORT: 2181 + ports: + - 2181:2181 + volumes: + - zookeeper-data:/var/lib/zookeeper/data + - zookeeper-log:/var/lib/zookeeper/log kafka-1: - image: bitnami/kafka:3.4 + image: confluentinc/cp-kafka:7.5.1 environment: - KAFKA_ENABLE_KRAFT: 'yes' - KAFKA_KRAFT_CLUSTER_ID: r7dMBY60T16TrNCGeXniLw - KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER - KAFKA_CFG_LISTENERS: CONTROLLER://:9093, BROKER://:9092, LOCALHOST://:9081 - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: BROKER:PLAINTEXT, CONTROLLER:PLAINTEXT, LOCALHOST:PLAINTEXT - KAFKA_CFG_ADVERTISED_LISTENERS: BROKER://kafka-1:9092, LOCALHOST://localhost:9081 - KAFKA_CFG_NODE_ID: 1 - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 1@kafka-1:9093, 2@kafka-2:9093, 3@kafka-3:9093 - ALLOW_PLAINTEXT_LISTENER: 'yes' - KAFKA_CFG_INTER_BROKER_LISTENER_NAME: BROKER - KAFKA_CFG_OFFSETS_TOPIC_REPLICATION_FACTOR: 3 - KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: "false" + KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 + KAFKA_LISTENERS: BROKER://:9092, LOCALHOST://:9081 + KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: BROKER:PLAINTEXT, LOCALHOST:PLAINTEXT + KAFKA_ADVERTISED_LISTENERS: BROKER://kafka-1:9092, LOCALHOST://localhost:9081 + KAFKA_BROKER_ID: 1 + KAFKA_INTER_BROKER_LISTENER_NAME: BROKER + KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 3 + KAFKA_AUTO_CREATE_TOPICS_ENABLE: "false" + KAFKA_AUTHORIZER_CLASS_NAME: kafka.security.authorizer.AclAuthorizer + KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: "true" + KAFKA_OPTS: + -javaagent:/usr/share/java/cp-base-new/jmx_prometheus_javaagent-0.18.0.jar=0.0.0.0:80:/etc/jmx-exporter.yml + -Dcom.sun.management.jmxremote=true + -Dcom.sun.management.jmxremote.port=9101 + -Dcom.sun.management.jmxremote.authenticate=false + volumes: + - ./jmx-exporter.yml:/etc/jmx-exporter.yml:ro + - kafka-1-data:/var/lib/kafka/data ports: - 9081:9081 + stop_grace_period: 120s + depends_on: + - zookeeper kafka-2: - image: bitnami/kafka:3.4 + image: confluentinc/cp-kafka:7.5.1 environment: - KAFKA_ENABLE_KRAFT: 'yes' - KAFKA_KRAFT_CLUSTER_ID: r7dMBY60T16TrNCGeXniLw - KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER - KAFKA_CFG_LISTENERS: CONTROLLER://:9093, BROKER://:9092, LOCALHOST://:9082 - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: BROKER:PLAINTEXT, CONTROLLER:PLAINTEXT, LOCALHOST:PLAINTEXT - KAFKA_CFG_ADVERTISED_LISTENERS: BROKER://kafka-2:9092, LOCALHOST://localhost:9082 - KAFKA_CFG_NODE_ID: 2 - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 1@kafka-1:9093, 2@kafka-2:9093, 3@kafka-3:9093 - ALLOW_PLAINTEXT_LISTENER: 'yes' - KAFKA_CFG_INTER_BROKER_LISTENER_NAME: BROKER - KAFKA_CFG_OFFSETS_TOPIC_REPLICATION_FACTOR: 3 - KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: "false" + KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 + KAFKA_LISTENERS: BROKER://:9092, LOCALHOST://:9082 + KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: BROKER:PLAINTEXT, LOCALHOST:PLAINTEXT + KAFKA_ADVERTISED_LISTENERS: BROKER://kafka-2:9092, LOCALHOST://localhost:9082 + KAFKA_BROKER_ID: 2 + KAFKA_INTER_BROKER_LISTENER_NAME: BROKER + KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 3 + KAFKA_AUTO_CREATE_TOPICS_ENABLE: "false" + KAFKA_AUTHORIZER_CLASS_NAME: kafka.security.authorizer.AclAuthorizer + KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: "true" + KAFKA_OPTS: + -javaagent:/usr/share/java/cp-base-new/jmx_prometheus_javaagent-0.18.0.jar=0.0.0.0:80:/etc/jmx-exporter.yml + -Dcom.sun.management.jmxremote=true + -Dcom.sun.management.jmxremote.port=9101 + -Dcom.sun.management.jmxremote.authenticate=false + volumes: + - ./jmx-exporter.yml:/etc/jmx-exporter.yml:ro + - kafka-2-data:/var/lib/kafka/data ports: - 9092:9082 - 9082:9082 @@ -41,42 +65,131 @@ services: default: aliases: - kafka + stop_grace_period: 120s + depends_on: + - zookeeper kafka-3: - image: bitnami/kafka:3.4 + image: confluentinc/cp-kafka:7.5.1 environment: - KAFKA_ENABLE_KRAFT: 'yes' - KAFKA_KRAFT_CLUSTER_ID: r7dMBY60T16TrNCGeXniLw - KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER - KAFKA_CFG_LISTENERS: CONTROLLER://:9093, BROKER://:9092, LOCALHOST://:9083 - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: BROKER:PLAINTEXT, CONTROLLER:PLAINTEXT, LOCALHOST:PLAINTEXT - KAFKA_CFG_ADVERTISED_LISTENERS: BROKER://kafka-3:9092, LOCALHOST://localhost:9083 - KAFKA_CFG_NODE_ID: 3 - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 1@kafka-1:9093, 2@kafka-2:9093, 3@kafka-3:9093 - ALLOW_PLAINTEXT_LISTENER: 'yes' - KAFKA_CFG_INTER_BROKER_LISTENER_NAME: BROKER - KAFKA_CFG_OFFSETS_TOPIC_REPLICATION_FACTOR: 3 - KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: "false" + KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 + KAFKA_LISTENERS: BROKER://:9092, LOCALHOST://:9083 + KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: BROKER:PLAINTEXT, LOCALHOST:PLAINTEXT + KAFKA_ADVERTISED_LISTENERS: BROKER://kafka-3:9092, LOCALHOST://localhost:9083 + KAFKA_BROKER_ID: 3 + KAFKA_INTER_BROKER_LISTENER_NAME: BROKER + KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 3 + KAFKA_AUTO_CREATE_TOPICS_ENABLE: "false" + KAFKA_AUTHORIZER_CLASS_NAME: kafka.security.authorizer.AclAuthorizer + KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: "true" + KAFKA_OPTS: + -javaagent:/usr/share/java/cp-base-new/jmx_prometheus_javaagent-0.18.0.jar=0.0.0.0:80:/etc/jmx-exporter.yml + -Dcom.sun.management.jmxremote=true + -Dcom.sun.management.jmxremote.port=9101 + -Dcom.sun.management.jmxremote.authenticate=false + volumes: + - ./jmx-exporter.yml:/etc/jmx-exporter.yml:ro + - kafka-3-data:/var/lib/kafka/data ports: - 9083:9083 + stop_grace_period: 120s + depends_on: + - zookeeper + + schema-registry: + image: confluentinc/cp-schema-registry:7.5.1 + environment: + SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: kafka-1:9092,kafka-2:9092,kafka-3:9092 + SCHEMA_REGISTRY_HOST_NAME: schema-registry + SCHEMA_REGISTRY_LISTENERS: http://0.0.0.0:8085 + SCHEMA_REGISTRY_LOG4J_ROOT_LOGLEVEL: INFO + ports: + - 8085:8085 + depends_on: + - kafka-1 + - kafka-2 + - kafka-3 + connect: + image: confluentinc/cp-kafka-connect:7.5.1 + environment: + CONNECT_BOOTSTRAP_SERVERS: kafka-1:9092,kafka-2:9092,kafka-3:9092 + CONNECT_REST_PORT: 8083 + CONNECT_REST_LISTENERS: http://0.0.0.0:8083 + CONNECT_REST_ADVERTISED_HOST_NAME: connect + CONNECT_CONFIG_STORAGE_TOPIC: __connect-config + CONNECT_OFFSET_STORAGE_TOPIC: __connect-offsets + CONNECT_STATUS_STORAGE_TOPIC: __connect-status + CONNECT_GROUP_ID: kafka-connect + CONNECT_KEY_CONVERTER_SCHEMAS_ENABLE: "true" + CONNECT_KEY_CONVERTER: io.confluent.connect.avro.AvroConverter + CONNECT_KEY_CONVERTER_SCHEMA_REGISTRY_URL: http://schema-registry:8085 + CONNECT_VALUE_CONVERTER_SCHEMAS_ENABLE: "true" + CONNECT_VALUE_CONVERTER: io.confluent.connect.avro.AvroConverter + CONNECT_VALUE_CONVERTER_SCHEMA_REGISTRY_URL: http://schema-registry:8085 + CONNECT_INTERNAL_KEY_CONVERTER: org.apache.kafka.connect.json.JsonConverter + CONNECT_INTERNAL_VALUE_CONVERTER: org.apache.kafka.connect.json.JsonConverter + CONNECT_OFFSET_STORAGE_REPLICATION_FACTOR: 1 + CONNECT_CONFIG_STORAGE_REPLICATION_FACTOR: 1 + CONNECT_STATUS_STORAGE_REPLICATION_FACTOR: 1 + CONNECT_PLUGIN_PATH: /usr/share/java/ + ports: + - 8083:8083 + depends_on: + - schema-registry - setup: + cli: image: juplo/toolbox - command: > - bash -c " - kafka-topics --bootstrap-server kafka:9092 --delete --if-exists --topic test - kafka-topics --bootstrap-server kafka:9092 --create --topic test --partitions 2 --replication-factor 3 --config min.insync.replicas=2 - echo Das Topic \'test\' wurde erfolgreich angelegt: - kafka-topics --bootstrap-server kafka:9092 --describe --topic test - echo \'docker-compose restart -t0 setup\' löscht das Topic und legt es neu an - sleep infinity - " + command: sleep infinity + stop_grace_period: 0s depends_on: - kafka-1 - kafka-2 - kafka-3 + setup: + image: juplo/toolbox + command: + - bash + - -c + - | + cub kafka-ready -b kafka-1:9092,kafka-2:9092,kafka-3:9092 3 60 > /dev/null 2>&1 || exit 1 + if [ -e INITIALIZED ] + then + echo -n Bereits konfiguriert: + cat INITIALIZED + kafka-topics --bootstrap-server kafka:9092 --describe --topic test + else + kafka-topics --bootstrap-server kafka:9092 \ + --delete \ + --if-exists \ + --topic test + kafka-topics --bootstrap-server kafka:9092 \ + --create \ + --topic test \ + --partitions 2 \ + --replication-factor 3 \ + --config min.insync.replicas=2 \ + && echo Das Topic \'test\' wurde erfolgreich angelegt: \ + && kafka-topics --bootstrap-server kafka:9092 --describe --topic test \ + && date > INITIALIZED + fi + stop_grace_period: 0s + depends_on: + - cli + + zoonavigator: + image: elkozmon/zoonavigator:1.1.2 + ports: + - "8000:80" + environment: + HTTP_PORT: 80 + CONNECTION_JUPLO_NAME: juplo + CONNECTION_JUPLO_CONN: zookeeper:2181 + AUTO_CONNECT_CONNECTION_ID: JUPLO + depends_on: + - zookeeper + akhq: image: tchiotludo/akhq:0.23.0 ports: @@ -88,17 +201,23 @@ services: docker-kafka-server: properties: bootstrap.servers: "kafka:9092" + schema-registry: + url: "http://schema-registry:8085" + connect: + - name: "connect" + url: "http://connect:8083" depends_on: - kafka-1 - kafka-2 - kafka-3 - cli: - image: juplo/toolbox - command: sleep infinity - depends_on: - - setup - producer: image: juplo/fire-forget:1.0-SNAPSHOT command: kafka:9092 test producer + +volumes: + zookeeper-data: + zookeeper-log: + kafka-1-data: + kafka-2-data: + kafka-3-data: diff --git a/docker/jmx-exporter.yml b/docker/jmx-exporter.yml new file mode 100644 index 0000000..fde0e7e --- /dev/null +++ b/docker/jmx-exporter.yml @@ -0,0 +1,70 @@ +lowercaseOutputName: true +lowercaseOutputLabelNames: true +rules: + # Special cases and very specific rules + - pattern : kafka.server<>Value + name: kafka_server_$1_$2 + type: GAUGE + labels: + clientId: "$3" + topic: "$4" + partition: "$5" + - pattern : kafka.server<>Value + name: kafka_server_$1_$2 + type: GAUGE + labels: + clientId: "$3" + broker: "$4:$5" + + - pattern : kafka.server<>OneMinuteRate + name: kafka_server_kafkarequesthandlerpool_requesthandleravgidlepercent_total + type: GAUGE + + - pattern: kafka.server<>connections + name: kafka_server_socketservermetrics_connections + type: GAUGE + labels: + client_software_name: "$1" + client_software_version: "$2" + listener: "$3" + network_processor: "$4" + + - pattern : 'kafka.server<>(.+):' + name: kafka_server_socketservermetrics_$3 + type: GAUGE + labels: + listener: "$1" + network_processor: "$2" + + # Count and Value + - pattern: kafka.(.+)<>(Count|Value) + name: kafka_$1_$2_$3 + labels: + "$4": "$5" + "$6": "$7" + - pattern: kafka.(.+)<>(Count|Value) + name: kafka_$1_$2_$3 + labels: + "$4": "$5" + - pattern: kafka.(.+)<>(Count|Value) + name: kafka_$1_$2_$3 + + # Percentile + - pattern: kafka.(.+)<>(\d+)thPercentile + name: kafka_$1_$2_$3 + type: GAUGE + labels: + "$4": "$5" + "$6": "$7" + quantile: "0.$8" + - pattern: kafka.(.+)<>(\d+)thPercentile + name: kafka_$1_$2_$3 + type: GAUGE + labels: + "$4": "$5" + quantile: "0.$6" + - pattern: kafka.(.+)<>(\d+)thPercentile + name: kafka_$1_$2_$3 + type: GAUGE + labels: + quantile: "0.$4"