返回到文章

采纳

编辑于

Kafka配置完SASL后,Kafka可以启动,但是broker无法使用

kafka

zk集群有三台,Kafka集群有两台,分别为192.168.1.163和162,kafka版本为 kafka_2.12-1.1.0.tgz,想要配置安全验证

server.properties文件中配置了

listeners=SASL_PLAINTEXT://192.168.1.163:9092
security.inter.broker.protocol=SASL_PLAINTEXT
sasl.mechanism.inter.broker.protocol=PLAIN
sasl.enabled.mechanisms=PLAIN
authorizer.class.name = kafka.security.auth.SimpleAclAuthorizer
super.users=User:admin;User:alice

config目录下配置了kafka_server_jaas和kafka_client_jaas文件,内容分别问

KafkaServer {
    org.apache.kafka.common.security.plain.PlainLoginModule required
    username="admin"
    password="admin"
    user_admin="admin"
    user_alice="alice";
};

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

kafka-run-class.sh文件中末尾添加和修改了

KAFKA_SASL_OPTS='-Djava.security.auth.login.config=/usr/local/kafka_2.12-1.1.0/config/kafka_server_jaas.conf'
# Launch mode
if [ "x$DAEMON_MODE" = "xtrue" ]; then
  nohup $JAVA $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS $KAFKA_GC_LOG_OPTS $KAFKA_SASL_OPTS $KAFKA_JMX_OPTS $KAFKA_LOG4J_OPTS -cp $CLASSPATH $KAFKA_OPTS "$@" > "$CONSOLE_OUTPUT_FILE" 2>&1 < /dev/null &
else
  exec $JAVA $KAFKA_HEAP_OPTS $KAFKA_JVM_PERFORMANCE_OPTS $KAFKA_GC_LOG_OPTS $KAFKA_SASL_OPTS $KAFKA_JMX_OPTS $KAFKA_LOG4J_OPTS -cp $CLASSPATH $KAFKA_OPTS "$@"
fi

这些,就是添了个环境变量

kafka-console-producer.sh和kafka-console-consumer.sh 文件中,分别添加了

System.setProperty("java.security.auth.login.config", "../config/kafka_client_jaas.conf");
props.put("security.protocol", "SASL_PLAINTEXT");
props.put("sasl.mechanism", "PLAIN");

这些参数

运行的时候,可以创建topic,但是当用

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test

命令连接时,会发生

WARN [Producer clientId=console-producer] Connection to node -1 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

的错误

用python代码连接的话也会报kafka.errors.NoBrokersAvailable: NoBrokersAvailable的错误,

请问这是什么原因啊,十分感谢