diff --git a/docker/Dockerfile b/docker/Dockerfile index 5ef5a89ce7..3a1b8d89d1 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -21,15 +21,17 @@ MAINTAINER AutoMQ for Apache Kafka dev@automq.com # Set mirrors ARG general_mirror_url="" RUN [ -z "${general_mirror_url}" ] || (sed -i "s/deb.debian.org/${general_mirror_url}/g" /etc/apt/sources.list && sed -i "s|security.debian.org/debian-security|${general_mirror_url}/debian-security|g" /etc/apt/sources.list) -RUN apt update && apt install -y vim systemctl +RUN apt update && apt install -y vim # Do not ask for confirmations when running apt-get, etc. ENV DEBIAN_FRONTEND=noninteractive \ - AWS_DEFAULT_REGION=us-east-1 + AWS_DEFAULT_REGION=us-east-1 \ + KAFKA_JVM_PERFORMANCE_OPTS="-server -XX:+UseZGC -XX:ZCollectionInterval=5" COPY "./kafka_*.tgz" /opt/kafka/kafka.tgz RUN tar -xzvf "/opt/kafka/kafka.tgz" -C /opt/kafka/ --one-top-level=kafka --strip-components 1 && rm "/opt/kafka/kafka.tgz" COPY scripts /opt/kafka/scripts +RUN chmod +x /opt/kafka/scripts/*.sh RUN mkdir -p /data/kafka diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index d87564effb..8c8d4f3d8a 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -52,12 +52,17 @@ services: controller: container_name: "${CONTROLLER_DOCKER_NAME-controller}" hostname: "${CONTROLLER_DOCKER_NAME-controller}" + stop_grace_period: 2m image: automqinc/kafka:1.0.0-rc5 environment: - KAFKA_S3_ACCESS_KEY=test - KAFKA_S3_SECRET_KEY=test - KAFKA_HEAP_OPTS=-Xms1g -Xmx1g -XX:MetaspaceSize=96m - command: bash /opt/kafka/scripts/start.sh up --process.roles controller --node.id 0 --controller.quorum.voters 0@controller:9093 --s3.bucket ko3 --s3.endpoint http://10.6.0.2:4566 --s3.region us-east-1 + command: + - bash + - -c + - | + /opt/kafka/scripts/start.sh up --process.roles controller --node.id 0 --controller.quorum.voters 0@controller:9093 --s3.bucket ko3 --s3.endpoint http://10.6.0.2:4566 --s3.region us-east-1 networks: - afk_net depends_on: @@ -67,6 +72,7 @@ services: broker1: container_name: "${BROKER1_DOCKER_NAME-broker1}" hostname: "${BROKER1_DOCKER_NAME-broker1}" + stop_grace_period: 2m image: automqinc/kafka:1.0.0-rc5 ports: - "9094:9094" @@ -81,7 +87,11 @@ services: - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,EXTERNAL://:9094 - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://broker1:9092,EXTERNAL://localhost:9094 - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT,PLAINTEXT:PLAINTEXT - command: bash /opt/kafka/scripts/start.sh up --process.roles broker --node.id 1 --controller.quorum.voters 0@controller:9093 --s3.bucket ko3 --s3.endpoint http://10.6.0.2:4566 --s3.region us-east-1 + command: + - bash + - -c + - | + /opt/kafka/scripts/start.sh up --process.roles broker --node.id 1 --controller.quorum.voters 0@controller:9093 --s3.bucket ko3 --s3.endpoint http://10.6.0.2:4566 --s3.region us-east-1 networks: - afk_net depends_on: @@ -92,6 +102,7 @@ services: broker2: container_name: "${BROKER2_DOCKER_NAME-broker2}" hostname: "${BROKER2_DOCKER_NAME-broker2}" + stop_grace_period: 2m image: automqinc/kafka:1.0.0-rc5 ports: - "9095:9095" @@ -106,7 +117,11 @@ services: - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,EXTERNAL://:9095 - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://broker2:9092,EXTERNAL://localhost:9095 - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT,PLAINTEXT:PLAINTEXT - command: bash /opt/kafka/scripts/start.sh up --process.roles broker --node.id 2 --controller.quorum.voters 0@controller:9093 --s3.bucket ko3 --s3.endpoint http://10.6.0.2:4566 --s3.region us-east-1 + command: + - bash + - -c + - | + /opt/kafka/scripts/start.sh up --process.roles broker --node.id 2 --controller.quorum.voters 0@controller:9093 --s3.bucket ko3 --s3.endpoint http://10.6.0.2:4566 --s3.region us-east-1 networks: - afk_net depends_on: diff --git a/docker/scripts/kafka.service b/docker/scripts/kafka.service deleted file mode 100644 index 2ce619a335..0000000000 --- a/docker/scripts/kafka.service +++ /dev/null @@ -1,38 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -[Unit] -Description=Kafka -After=network.target - -[Service] -ExecStart=/root/program/kafka/bin/kafka-server-start.sh config/kraft/broker.properties -Environment='KAFKA_HEAP_OPTS=-Xms1g -Xmx1g -XX:MetaspaceSize=96m -XX:MaxDirectMemorySize=1G' -Environment='KAFKA_JVM_PERFORMANCE_OPTS=-server -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -XX:+ParallelRefProcEnabled -XX:+DoEscapeAnalysis -XX:ParallelGCThreads=12 -XX:ConcGCThreads=12 -XX:+DisableExplicitGC -XX:-ResizePLAB -XX:MinMetaspaceFreeRatio=50 -XX:MaxMetaspaceFreeRatio=80 -Djava.awt.headless=true' -Environment='KAFKA_S3_ACCESS_KEY=xxx' -Environment='KAFKA_S3_SECRET_KEY=yyy' -WorkingDirectory=/root/program/kafka -RestartSec=1s -Restart=on-failure -Type=simple -LimitNOFILE=300000 -# Stopping will first send SIGTERM and then wait 60min for kafka to shutdown before sending SIGKILL -TimeoutStopSec=3600 -# Do not record any std. -StandardOutput=null -StandardError=null - -[Install] -WantedBy=multi-user.target diff --git a/docker/scripts/start.sh b/docker/scripts/start.sh index f93df0b56b..b8ea8a686f 100644 --- a/docker/scripts/start.sh +++ b/docker/scripts/start.sh @@ -270,9 +270,6 @@ kafka_up() { setup_value "log.dirs" "${data_path}/kraft-${role}-logs" "${kafka_dir}/config/kraft/${role}.properties" setup_value "s3.wal.path" "${data_path}/wal" "${kafka_dir}/config/kraft/${role}.properties" setup_value "s3.endpoint" "${s3_endpoint}" "${kafka_dir}/config/kraft/${role}.properties" - setup_value "WorkingDirectory" "${kafka_dir}" "${start_dir}/kafka.service" - sed -i "s|Environment='KAFKA_S3_ACCESS_KEY.*$|Environment='KAFKA_S3_ACCESS_KEY=${s3_access_key}'|" "${start_dir}/kafka.service" - sed -i "s|Environment='KAFKA_S3_SECRET_KEY.*$|Environment='KAFKA_S3_SECRET_KEY=${s3_secret_key}'|" "${start_dir}/kafka.service" # turn on auto_balancer turn_on_auto_balancer "${role}" "${kafka_dir}/config/kraft/${role}.properties" done @@ -286,8 +283,6 @@ kafka_up() { else die "kafka_start_up: unknown process role ${process_role}" fi - sed -i "s|Environment='KAFKA_HEAP_OPTS.*$|Environment='KAFKA_HEAP_OPTS=${kafka_heap_opts}'|" "${start_dir}/kafka.service" - setup_value "ExecStart" "${kafka_dir}/bin/kafka-server-start.sh ${kafka_dir}/config/kraft/${process_role}.properties" "${start_dir}/kafka.service" # add this node's info to run.info setup_value "node.id" "${node_id}" "${run_info_file}" @@ -302,17 +297,13 @@ kafka_up() { # override settings from env configure_from_environment_variables "${kafka_dir}/config/kraft/${process_role}.properties" + # Disable the default console logger in favour of KafkaAppender (which provides the exact output) + echo "log4j.appender.stdout.Threshold=OFF" >> "${kafka_dir}/config/log4j.properties" + # format the data path must_do -v "${kafka_dir}/bin/kafka-storage.sh format -g -t ${cluster_id} -c ${kafka_dir}/config/kraft/${process_role}.properties" - must_do -v cp "${start_dir}/kafka.service" "/etc/systemd/system/kafka.service" - must_do -v systemctl daemon-reload - must_do -v systemctl enable kafka - must_do -v systemctl start kafka - - echo "** kafka_up: successfully brought up kafka node with role ${process_role} **" - - tail -f /dev/null + exec "${kafka_dir}/bin/kafka-server-start.sh" "${kafka_dir}/config/kraft/${process_role}.properties" } # Parse command-line arguments