KAFKA0.10.0.0使用SASL_PLAINTEXT时无法成功启动

酋长 发表于: 2017-08-31   最后更新时间: 2017-08-31 08:31:06   11,191 游览

/opt/kafka_2.10-0.10.0.0 目录下新增三个文件:

kafka_server_jaas.conf

KafkaServer{
 org.apache.kafka.common.security.plain.PlainLoginModule required
 username="kafka"
 password="kafka-secret"
 user_kafka="kafka-secret"
 user_alice="alice-secret"
};

kafka_client_jaas.conf

KafkaClient {
 org.apache.kafka.common.security.plain.PlainLoginModule required
 username="kafka"
 password="kafka-secret";
};

kafka_zoo_jaas.conf

zookeeper {
 org.apache.kafka.common.security.plain.PlainLoginModule required
 username="kafka"
 password="kafka-secret"
};

conf配置目录里:
server.properties

port=9092
socket.request.max.bytes=104857600
num.io.threads=8
log.dirs=/tmp/kafka-logs
socket.send.buffer.bytes=102400
zookeeper.connect=192.168.176.10:2181
log.retention.check.interval.ms=300000
broker.id=1
log.retention.hours=168
num.network.threads=3
socket.receive.buffer.bytes=102400
num.recovery.threads.per.data.dir=1
zookeeper.connection.timeout.ms=6000
num.partitions=1
log.segment.bytes=1073741824
delete.topic.enable=true

listeners=SASL_PLAINTEXT://192.168.176.10:9092
security.inter.broker.protocol=SASL_PLAINTEXT
sasl.enabled.mechanisms=PLAIN
sasl.mechanism.inter.broker.protocol=PLAIN
authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer
allow.everyone.if.no.acl.found=true

producer.properties 和 consumer.properties 添加

security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN

kafka-server-start.sh 添加

export KAFKA_OPTS="-Djava.security.auth.login.config=/opt/kafka_2.10-0.10.0.0/kafka_server_jaas.conf"

zookeeper-server-start.sh 添加

export KAFKA_OPTS=" -Djava.security.auth.login.config=/opt/kafka_2.10-0.10.0.0/kafka_zoo_jaas.conf"

zookeeper正常启动,但是启动Kafka时报错
./kafka-server-start.sh ../config/server.properties

[2017-08-31 01:08:36,384] FATAL Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
org.apache.kafka.common.KafkaException: Exception while loading Zookeeper JAAS login context 'Client'
    at org.apache.kafka.common.security.JaasUtils.isZkSecurityEnabled(JaasUtils.java:94)
    at kafka.server.KafkaServer.initZk(KafkaServer.scala:278)
    at kafka.server.KafkaServer.startup(KafkaServer.scala:180)
    at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:37)
    at kafka.Kafka$.main(Kafka.scala:67)
    at kafka.Kafka.main(Kafka.scala)
Caused by: java.lang.SecurityException: java.io.IOException: 配置错误: 
    行 7: 应为 [option key]
    at sun.security.provider.ConfigFile$Spi.<init>(ConfigFile.java:137)
    at sun.security.provider.ConfigFile.<init>(ConfigFile.java:102)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at javax.security.auth.login.Configuration$2.run(Configuration.java:255)
    at javax.security.auth.login.Configuration$2.run(Configuration.java:247)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.login.Configuration.getConfiguration(Configuration.java:246)
    at org.apache.kafka.common.security.JaasUtils.isZkSecurityEnabled(JaasUtils.java:91)
    ... 5 more
Caused by: java.io.IOException: 配置错误: 
    行 7: 应为 [option key]
    at sun.security.provider.ConfigFile$Spi.ioException(ConfigFile.java:666)
    at sun.security.provider.ConfigFile$Spi.match(ConfigFile.java:562)
    at sun.security.provider.ConfigFile$Spi.parseLoginEntry(ConfigFile.java:477)
    at sun.security.provider.ConfigFile$Spi.readConfig(ConfigFile.java:427)
    at sun.security.provider.ConfigFile$Spi.init(ConfigFile.java:329)
    at sun.security.provider.ConfigFile$Spi.init(ConfigFile.java:271)
    at sun.security.provider.ConfigFile$Spi.<init>(ConfigFile.java:135)
    ... 16 more
[2017-08-31 01:08:36,413] INFO shutting down (kafka.server.KafkaServer)
[2017-08-31 01:08:36,427] INFO shut down completed (kafka.server.KafkaServer)

问题出在哪里呢?

发表于 2017-08-31
添加评论

搞定了,少了分号。。。汗(⊙﹏⊙)b

半兽人 -> 酋长 7年前

汗。。

老哥哪里少个逗号,我这配置的也是一样的错误

你找到问题了吗

password="kafka-secret" 这里最后加上分号就好了

老哥,我的有分号也一样的报错

博主你好 能不能讲下具体解决呢 和你一样的配置 加了分号 也是报错

你的答案

查看kafka相关的其他问题或提一个您自己的问题