如何在容器外部调整/编辑/添加/更改 kafka docker 容器参数 [英] How to tune/edit/add/change the kafka docker container parameters outside from the container
问题描述
我们有如下的 kafka docker 容器(在 Linux redhat 7.5 上)
We have kafka docker container as the following ( on Linux redhat 7.5 )
我们根据 - https://docs.confluent.io/5.0.0/installation/docker/docs/installation/single-node-client.html
docker-compose ps
Name Command State Ports
-------------------------------------------------------------------------------------------------------------------
kafka-single-node_kafka_1 /etc/confluent/docker/run Up 0.0.0.0:9092->9092/tcp
<小时>
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0.0.0.0:8081->8081/tcp kafka-single-node_schemaregistry_1
de584963bb5a confluentinc/cp-kafka:latest "/etc/confluent/dock…" 6 hours ago Up 6 hours 0.0.0.0:9092->9092/tcp kafka-single-node_kafka_1
关于 - docker-compose.yml
about - docker-compose.yml
pwd
/home/cp-docker-images/examples/kafka-single-node
more docker-compose.yml
kafka:
image: confluentinc/cp-kafka:latest
depends_on:
- zookeeper
ports:
- 9092:9092
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
我们想要控制 kafka docker 容器配置 - /etc/kafka/server.properties
从容器外部,(或从操作系统本身)
We want to control the kafka docker container configuration - /etc/kafka/server.properties
outside from the container , ( or from the OS itself )
假设我想在 server.properties
(kafka 容器)中添加一些参数或更改一些参数
Let say I want to add some parameters or to change some parameters in server.properties
( of the kafka container )
那么为什么要在 kafka 容器外部进行配置的最佳方式是什么
在下面的示例中,我将展示如何访问 docker kafka 容器内的 server.properties
In the following example I show how to access the server.properties
, inside The docker kafka container
docker exec -it de584963bb5a bash
现在我们可以访问/读取文件 - server.properties
Now we can access/read the file - server.properties
root@de584963bb5a:/# more /etc/kafka/server.properties
# 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.
# see kafka.server.KafkaConfig for additional details and defaults
############################# Server Basics #############################
# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0
############################# Socket Server Settings #############################
# The address the socket server listens on. It will get the value returned from
# java.net.InetAddress.getCanonicalHostName() if not configured.
# FORMAT:
# listeners = listener_name://host_name:port
# EXAMPLE:
# listeners = PLAINTEXT://your.host.name:9092
#listeners=PLAINTEXT://:9092
.
.
.
##################### Confluent Proactive Support ######################
# If set to true, and confluent-support-metrics package is installed
# then the feature to collect and report support metrics
# ("Metrics") is enabled. If set to false, the feature is disabled.
#
confluent.support.metrics.enable=true
# The customer ID under which support metrics will be collected and
# reported.
#
# When the customer ID is set to "anonymous" (the default), then only a
# reduced set of metrics is being collected and reported.
#
# Confluent customers
# -------------------
# If you are a Confluent customer, then you should replace the default
# value with your actual Confluent customer ID. Doing so will ensure
# that additional support metrics will be collected and reported.
#
confluent.support.customer.id=anonymous
############################# Group Coordinator Settings #############################
# The following configuration specifies the time, in milliseconds, that the GroupCoordinator will delay the initial consumer rebalance.
# The rebalance will be further delayed by the value of group.initial.rebalance.delay.ms as new members join the group, up to a maximum of max.poll.interval.ms.
# The default value for this is 3 seconds.
# We override this to 0 here as it makes for a better out-of-the-box experience for development and testing.
# However, in production environments the default value of 3 seconds is more suitable as this will help to avoid unnecessary, and potentially expensive, rebalances during application startu
p.
group.initial.rebalance.delay.ms=0
推荐答案
我们想控制kafka docker容器配置——容器外的/etc/kafka/server.properties
We want to control the kafka docker container configuration - /etc/kafka/server.properties outside from the container
我会避免从主机挂载 server.properties 文件,因为容器内的每个设置都可以通过环境变量进行配置,例如 KAFKA_(variable)
- https://docs.confluent.io/current/installation/docker/config-reference.html#confluent-kafka-configuration
I would avoid mounting a server.properties file from the host since every setting within the container can be configured by environment variables like KAFKA_(variable)
- https://docs.confluent.io/current/installation/docker/config-reference.html#confluent-kafka-configuration
相反,您可以使用 env_file
作为撰写文件 并将所有变量移动到那里
Rather, you can use env_file
for the compose file and move all your variables there
kafka:
image: confluentinc/cp-kafka:latest
depends_on:
- zookeeper
ports:
- 9092:9092
env_file:
- broker1.env
broker1.env
broker1.env
KAFKA_BROKER_ID=1
KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1
您可以使用此模式添加任何代理配置 - https://kafka.apache.org/documentation/#brokerconfigs
And you can add any broker config with this pattern - https://kafka.apache.org/documentation/#brokerconfigs
这篇关于如何在容器外部调整/编辑/添加/更改 kafka docker 容器参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!