顺序是Broker是停止的,然后修改配置文件,创建用户,之后启动Broker。
我是单台环境 2.2.0
Broker server.properties 除了下面的其他都是默认配置
listeners=SASL_PLAINTEXT://172.16.247.100:9092
sasl.enabled.mechanisms=SCRAM-SHA-256
sasl.mechanism.inter.broker.protocol=SCRAM-SHA-256
security.inter.broker.protocol=SASL_PLAINTEXT
# 这里我使用的是sasl.jaas.config配置形式,而不是kafka_server_jaas.conf形式
# 官网中http://kafka.apache.org/documentation/#security_jaas_broker支持这种配置方式
listener.name.sasl_plaintext.scram-sha-256.sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required \
username="admin" \
password="admin-secret";
创建admin账号
./kafka-configs.sh --zookeeper localhost:2181 --alter --add-config \
'SCRAM-SHA-256=[password=admin-secret],SCRAM-SHA-512=[password=admin-secret]' \
--entity-type users --entity-name admin
创建完我再ZK中的 config\users节点可以看到这个用户.
启动后的server.log,日志里kafka成功注册到zk节点
[2019-10-24 10:25:52,210] INFO Registered broker 0 at path /brokers/ids/0 with addresses: ArrayBuffer(EndPoint(172.16.247.100,9092,ListenerName(SASL_PLAINTEXT),SASL_PLAINTEXT)), czxid (broker epoch): 148 (kafka.zk.KafkaZkClient)
[2019-10-24 10:25:52,462] INFO [KafkaServer id=0] started (kafka.server.KafkaServer)
[2019-10-24 10:25:52,582] INFO [SocketServer brokerId=0] Failed authentication with /172.16.247.100 (Authentication failed during authentication due to invalid credentials with SASL mechanism SCRAM-SHA-256) (org.apache.kafka.common.network.Selector)
[2019-10-24 10:25:52,583] INFO [Controller id=0, targetBrokerId=0] Failed authentication with srv01.contoso.com/172.16.247.100 (Authentication failed during authentication due to invalid credentials with SASL mechanism SCRAM-SHA-256) (org.apache.kafka.common.network.Selector)
[2019-10-24 10:25:52,584] ERROR [Controller id=0, targetBrokerId=0] Connection to node 0 (srv01.contoso.com/172.16.247.100:9092) failed authentication due to: Authentication failed during authentication due to invalid credentials with SASL mechanism SCRAM-SHA-256 (org.apache.kafka.clients.NetworkClient)
展开
作者回复: 我觉得你可以试一下jaas文件的方式,看看整个流程能否走通。如果可以,说明还是参数指定jaas设置的问题。总之先窄化可能的问题点