1.kafka_server_jaas.conf
KafkaServer {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="admin"
password="admin"
user_admin="admin"
user_reader="reader"
user_writer="writer";
};
2.kafka_client_jaas.conf
KafkaClient {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="writer"
password="writer";
};
3.server.properties
#开启超级用户
super.user.name=admin
super.user.password=admin@2023
############################# Server Basics #############################
broker.id=0
############################# Socket Server Settings #############################
#开启ACL
authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer
#使用SASL_PLAINTEXT协议
listeners=SASL_PLAINTEXT://127.0.0.1:9092
#Broker之间不启用ssl
security.inter.broker.protocol=SASL_PLAINTEXT
#PLAIN认证
sasl.enabled.mechanisms=PLAIN
#broker之间开启PLAIN认证
sasl.mechanism.inter.broker.protocol=PLAIN
allow.everyone.if.no.acl.found=true
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
############################# Log Basics #############################
log.dirs=/data/kafka/kafka_data/log/kafka
num.partitions=1
num.recovery.threads.per.data.dir=1
############################# Internal Topic Settings #############################
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
############################# Log Flush Policy #############################
#log.flush.interval.messages=10000
#log.flush.interval.ms=1000
############################# Log Retention Policy #############################
log.retention.hours=168
#log.retention.bytes=1073741824
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
############################# Zookeeper #############################
zookeeper.connect=10.22.245.173:2181
zookeeper.connection.timeout.ms=6000
############################# Group Coordinator Settings #############################
group.initial.rebalance.delay.ms=0
port=9092
host.name=127.0.0.1
zookeeper.connect=127.0.0.1:2181
4.consumer.properties
security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN
5.producer.properties
security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN
export KAFKA_OPTS=" -Djava.security.auth.login.config=/data/kafka/kafka2.3/config/kafka_server_jaas.conf"