1.增加kafka_server_jaas.conf
进入kafka的配置目录config:
vim 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"
};
#user_kafka表示增加一个kafka用户,密码是kafka#secret
#user_alice表示增加一个alice用户,密码是alice#secret
2.增加kafka_client_jaas.conf
进入kafka的配置目录config:
vim kafka_client_jaas.conf
#增加如下内容:
KafkaServer {
org.apache.kafka.common.security.plain.PlainLoginModule required
username=
"kafka"
password=
"kafka#secret"
};
#kafka消费端连接kafka使用用户名kafka,密码kafka#secret
3.修改producer.properties
进入kafka的配置目录config:
vim producer.properties
#增加如下内容:
security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN
4.修改consumer.properties
进入kafka的配置目录config:
vim consumer.properties
#增加如下内容:
security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN
5.修改server.properties
进入kafka的配置目录config:
vim producer.properties
#增加如下内容:
host.name=192.168.66.206
listeners=SASL_PLAINTEXT:
//
:9092
#任意地址监听
security.inter.broker.protocol=SASL_PLAINTEXT
sasl.enabled.mechanisms=PLAIN
sasl.mechanism.inter.broker.protocol=PLAIN
advertised.listeners=SASL_PLAINTEXT:
//
:9092
#或者advertised.listeners=SASL_PLAINTEXT://192.168.66.206:9092
6.修改kafka-server-start.sh
进入kafka的bin目录bin:
vim kafka-server-start.sh
#增加如下内容:
export
KAFKA_OPTS=
"-Djava.security.auth.login.config=/opt/kafka_2.12-2.6.0/config/kafka_server.jaas.conf"
7.修改kafka-console-producer.sh
进入kafka的bin目录bin:
vim kafka-console-producer.sh
#增加如下内容:
export
KAFKA_OPTS=
"-Djava.security.auth.login.config=/opt/kafka_2.12-2.6.0/config/kafka_client.jaas.conf"
8.修改kafka-console-consumer.sh
进入kafka的bin目录bin:
vim kafka-console-consumer.sh
#增加如下内容:
export
KAFKA_OPTS=
"-Djava.security.auth.login.config=/opt/kafka_2.12-2.6.0/config/kafka_client.jaas.conf"
9.正常启动kafka和相关生产端,消费端
标签:认证,vim,secret,conf,SASL,security,kafka,config From: https://blog.51cto.com/u_15899033/5903546