kafka开启SASL权限认证设置方法

第一步:停止kafka

1
bin/kafka-server-stop.sh

执行该命令会报错No kafka server to stop,修改bin/kafka-server-stop.sh脚本如下

1
2
- PIDS=$(ps ax | grep -i 'kafka\.Kafka' | grep java | grep -v grep | awk '{print $1}') 
+ PIDS=$(jps -lm | grep -i 'kafka.Kafka' | awk '{print $1}')

第二步:添加权限配置

1
vi kafka_server_jaas.conf

添加如下配置

1
2
3
4
5
6
7
KafkaServer {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="test"
password="test1234"
user_admin="admin"
user_alice="alice";
};
1
vi kafka_client_jaas.conf

添加如下配置

1
2
3
4
5
KafkaClient {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="test"
password="test1234";
};

更改server.properties配置文件