1.kafka配置文件 server.properties增加
listeners=SASL_PLAINTEXT://127.0.0.1:9092
advertised.listeners=SASL_PLAINTEXT://127.0.0.1:9092security.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
2. 在kafka的config目录下创建一个 kafka_server_jaas.conf 文件
KafkaServer {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="admin"
password="adminpasswd"
user_admin="adminpasswd"
user_producer="producerpwd"
user_consumer="consumerpwd";
};
- usemame和password指定该代理与集群其他代理初始化连接的用户名和密码
- "user_"为前缀后接用户名方式创建连接代理的用户名和密码,例如,user_producer=“producerpwd” 是指用户名为producer,密码为producerpw
3.修改kafka-server-start.bat
%~dp0../../config/kafka_server_jaas.conf
4. 在kafka的config目录下创建一个 kafka_client_jaas.conf 文件
KafkaClient {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="admin"
password="adminpasswd";
};
5.生产者kafka-console-producer.bat增加
IF ["%KAFKA_OPTS%"] EQU [""] (
set KAFKA_OPTS=-Djava.security.auth.login.config=file:%~dp0../../config/kafka_client_jaas.conf
)
6.kafka配置文件producer.properties和 consumer.properties增加
security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN