docker-compose wurstmeister / kafka无法解析KAFKA_OPTS

时间:2018-04-11 11:22:25

标签: docker apache-kafka docker-compose jaas sasl

我有一个基本的docker-compose文件,用于wurstmeister / kafka

我正在尝试将其配置为使用SASL_PLAIN和SSL 但是,无论我尝试指定我的jaas文件的方式有多少,我都会收到此错误

这是我得到的错误

[2018-04-11 10:34:34,545] FATAL [KafkaServer id=1001] Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
java.lang.IllegalArgumentException: Could not find a 'KafkaServer' or 'sasl_ssl.KafkaServer' entry in the JAAS configuration. System property 'java.security.auth.login.config' is not set

这些是我所拥有的变种。最后一个是我指定我的jaas文件的地方

environment:
  KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
  KAFKA_HOST_NAME: 10.10.10.1
  KAFKA_PORT: 9092
  KAFKA_ADVERTISED_PORT: 9093
  KAFKA_ADVERTISED_HOST_NAME: 10.10.10.1
  KAFKA_LISTENERS: PLAINTEXT://:9092,SASL_SSL://:9093
  KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://10.10.10.1:9092,SASL_SSL://10.10.10.1:9093
  KAFKA_SECURITY_INTER_BROKER_PROTOCOL: SASL_SSL
  KAFKA_SASL_ENABLED_MECHANISMS: PLAIN
  SASL_MECHANISM_INTER_BROKER_PROTOCOL: PLAIN
  KAFKA_SASL_MECHANISM_INTER_BROKER_PROTOCOL: PLAIN
  KAFKA_SSL_TRUSTSTORE_LOCATION: /kafka.server.truststore.jks
  KAFKA_SSL_TRUSTSTORE_PASSWORD: password
  KAFKA_SSL_KEYSTORE_LOCATION: /kafka.server.keystore.jks
  KAFKA_SSL_KEYSTORE_PASSWORD: password
  KAFKA_SSL_KEY_PASSWORD: password
  KAFKA_OPTS: '-Djava.security.auth.login.config=/path/kafka_server_jaas.conf'

当我尝试检查泊坞窗日志时,我看到了

/usr/bin/start-kafka.sh: line 96: KAFKA_OPTS=-Djava.security.auth.login.config: bad substitution

非常感谢任何帮助!

2 个答案:

答案 0 :(得分:1)

等于' ='在最后一个值内引起了这个问题 KAFKA_OPTS:' -Djava.security.auth.login.config = / path / kafka_server_jaas.conf'
这是我调试后得到的。

+ for VAR in $(env)
+ [[ KAFKA_OPTS=- 
Djava.security.auth.login.config=/path/kafka_server_jaas.conf =~ ^KAFKA_ ]]
+ [[ ! KAFKA_OPTS=- 
Djava.security.auth.login.config=/path/kafka_server_jaas.conf =~ 
^KAFKA_HOME ]]
++ echo KAFKA_OPTS=- 
Djava.security.auth.login.config=/path/kafka_server_jaas.conf
++ sed -r 's/KAFKA_(.*)=.*/\1/g'
++ tr '[:upper:]' '[:lower:]'
++ tr _ .
+ kafka_name=opts=-djava.security.auth.login.config
++ echo KAFKA_OPTS=- 
Djava.security.auth.login.config=/path/kafka_server_jaas.conf
++ sed -r 's/(.*)=.*/\1/g'
+ env_var=KAFKA_OPTS=-Djava.security.auth.login.config
+ grep -E -q '(^|^#)opts=-djava.security.auth.login.config=' 
/opt/kafka/config/server.properties
start-kafka.sh: line 96: KAFKA_OPTS=-Djava.security.auth.login.config: bad 
substitution

这是执行此操作的代码段。

88  for VAR in $(env)
89  do
90    if [[ $VAR =~ ^KAFKA_ && ! $VAR =~ ^KAFKA_HOME ]]; then
91      kafka_name=$(echo "$VAR" | sed -r 's/KAFKA_(.*)=.*/\1/g' | tr '[:upper:]' '[:lower:]' | tr _ .)
92      env_var=$(echo "$VAR" | sed -r 's/(.*)=.*/\1/g')
93      if grep -E -q '(^|^#)'"$kafka_name=" "$KAFKA_HOME/config/server.properties"; then
94          sed -r -i 's@(^|^#)('"$kafka_name"')=(.*)@\2='"${!env_var}"'@g' "$KAFKA_HOME/config/server.properties" #note that no config values may contain an '@' char
95      else
96          echo "$kafka_name=${!env_var}" >> "$KAFKA_HOME/config/server.properties"
97      fi
98    fi
99
100    if [[ $VAR =~ ^LOG4J_ ]]; then
101      log4j_name=$(echo "$VAR" | sed -r 's/(LOG4J_.*)=.*/\1/g' | tr '[:upper:]' '[:lower:]' | tr _ .)
102      log4j_env=$(echo "$VAR" | sed -r 's/(.*)=.*/\1/g')
103      if grep -E -q '(^|^#)'"$log4j_name=" "$KAFKA_HOME/config/log4j.properties"; then
104          sed -r -i 's@(^|^#)('"$log4j_name"')=(.*)@\2='"${!log4j_env}"'@g' "$KAFKA_HOME/config/log4j.properties" #note that no config values may contain an'@' char
105      else
106          echo "$log4j_name=${!log4j_env}" >> "$KAFKA_HOME/config/log4j.properties"
107      fi
108    fi
109  done

答案 1 :(得分:0)

更新:他们修复了它,现在合并了!

https://github.com/wurstmeister/kafka-docker/pull/321

现在wurstmeister / kafka已经打开了一个错误,但他们已经找到了一个解决方法,如下所示

  

我相信他是更大的命名空间碰撞问题的一部分   影响多个元素,如Kubernetes部署等(以及   与其他KAFKA_服务设置一样)。

     

鉴于您正在引用外部文件/kafka_server_jaas.conf,   我假设你可以添加/安装额外的文件;一个   解决方法是指定一个CUSTOM_INIT_SCRIPT环境var   应该是类似于的脚本:

#!/bin/bash
export KAFKA_OPTS="-Djava.security.auth.login.config=/kafka_server_jaas.conf"
This is executed after the substitution part that is failing.
  

这可能是内联完成的,但目前存在一个错误   我们如何处理环境,我们需要指定输入   分隔符使这个工作正常。

希望这有效!