gpt4 book ai didi

docker - 如何在Docker中设置Zookeeper dataDir(fig.yml)

转载 作者:行者123 更新时间:2023-12-02 21:28:58 25 4
gpt4 key购买 nike

我已经在Docker的fig.yml文件中配置了Zookeeper和Kafka容器。两个容器都可以正常运行。但是在发送了许多消息之后,我的应用程序/ zk-client挂起了。在检查zookeeper日志时,我看到错误:
Error Path:/brokers Error:KeeperErrorCode = NoNode for /brokers
我的fig.yml如下:

zookeeper:
image: wurstmeister/zookeeper
ports:
- "2181:2181"
environment:
ZK_ADVERTISED_HOST_NAME: xx.xx.x.xxx
ZK_CONNECTION_TIMEOUT_MS: 6000
ZK_SYNC_TIME_MS: 2000
ZK_DATADIR: /path/to/data/zk/data/dir
kafka:
image: wurstmeister/kafka:0.8.2.0
ports:
- "xx.xx.x.xxx:9092:9092"
links:
- zookeeper:zk
environment:
KAFKA_ADVERTISED_HOST_NAME: xx.xx.x.xxx
KAFKA_LOG_DIRS: /home/svc_cis4/dl
volumes:
- /var/run/docker.sock:/var/run/docker.sock

我已经搜索了很长时间,但是还没有解决方案。我也尝试使用ZK_DATADIR在fig.yml中设置数据目录:'/ path / to / zk / data / dir',但这似乎无济于事。任何帮助将不胜感激。

更新
/opt/kafka_2.10-0.8.2.0/config/server.properties的内容:
broker.id=0
port=9092
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
num.partitions=1
num.recovery.threads.per.data.dir=1
log.retention.hours=168
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
log.cleaner.enable=false
zookeeper.connect=localhost:2181
zookeeper.connection.timeout.ms=6000

最佳答案

您遇到的问题与zookeeper的数据目录无关。出现Error Path:/brokers Error:KeeperErrorCode = NoNode for /brokers错误是由于您的应用程序无法在zookeeper的数据中找到任何代理znode。之所以发生这种情况,可能是因为kafka容器无法与Zookeeper正确连接,并且查看wurstmeister的图像,我认为问题可能与KAFKA_ADVERTISED_HOST_NAME变量有关可能是错误的。我不知道是否有理由通过必须传递的env变量来分配该变量,但是从我的 Angular 来看,这不是一个好方法。有多种方法来配置kafka(实际上,无需设置advertised.host.name,您可以将其保留为注释,并且kafka将使用默认主机名,可以使用docker进行设置),但是使用此方法的快速解决方案是编辑start-kafka.sh并重建图片:

#!/bin/bash

if [[ -z "$KAFKA_ADVERTISED_PORT" ]]; then
export KAFKA_ADVERTISED_PORT=$(docker port `hostname` 9092 | sed -r "s/.*:(.*)/\1/g")
fi
if [[ -z "$KAFKA_BROKER_ID" ]]; then
export KAFKA_BROKER_ID=$KAFKA_ADVERTISED_PORT
fi
if [[ -z "$KAFKA_LOG_DIRS" ]]; then
export KAFKA_LOG_DIRS="/kafka/kafka-logs-$KAFKA_BROKER_ID"
fi
if [[ -z "$KAFKA_ZOOKEEPER_CONNECT" ]]; then
export KAFKA_ZOOKEEPER_CONNECT=$(env | grep ZK.*PORT_2181_TCP= | sed -e 's|.*tcp://||' | paste -sd ,)
fi

if [[ -n "$KAFKA_HEAP_OPTS" ]]; then
sed -r -i "s/^(export KAFKA_HEAP_OPTS)=\"(.*)\"/\1=\"$KAFKA_HEAP_OPTS\"/g" $KAFKA_HOME/bin/kafka-server-start.sh
unset KAFKA_HEAP_OPTS
fi

for VAR in `env`
do
if [[ $VAR =~ ^KAFKA_ && ! $VAR =~ ^KAFKA_HOME ]]; then
kafka_name=`echo "$VAR" | sed -r "s/KAFKA_(.*)=.*/\1/g" | tr '[:upper:]' '[:lower:]' | tr _ .`
env_var=`echo "$VAR" | sed -r "s/(.*)=.*/\1/g"`
if egrep -q "(^|^#)$kafka_name=" $KAFKA_HOME/config/server.properties; then
sed -r -i "s@(^|^#)($kafka_name)=(.*)@\2=${!env_var}@g" $KAFKA_HOME/config/server.properties #note that no config values may contain an '@' char
else
echo "$kafka_name=${!env_var}" >> $KAFKA_HOME/config/server.properties
fi
fi
done

###NEW###
IP=$(hostname --ip-address)
sed -i -e "s/^advertised.host.name.*/advertised.host.name=$IP/" $KAFKA_HOME/config/server.properties
###END###

$KAFKA_HOME/bin/kafka-server-start.sh $KAFKA_HOME/config/server.properties

如果这不能解决您的问题,则可以获取更多信息,以在容器内启动 session (例如:kafka的 docker exec -it kafkadocker_kafka_1 /bin/bash和zookeeper的 docker exec -it kafkadocker_zookeeper_1 /bin/bash),并在那里检查kafka日志或zookeeper控制台( /opt/zookeeper-3.4.6/bin/zkCli.sh)

关于docker - 如何在Docker中设置Zookeeper dataDir(fig.yml),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28505192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com