1. 增加配置配文件信息
vim /opt/kafka_2.13-3.6.1/config/server.properties
listeners=PLAINTEXT://192.168.50.240:9092,OUTER://192.168.50.240:9094# Listener name, hostname and port the broker will advertise to clients.
# If not set, it uses the value for "listeners".
advertised.listeners=PLAINTEXT://192.168.50.240:9092,OUTER://192.168.50.240:9094
inter.broker.listener.name=PLAINTEXT
# Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details
#listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL
listener.security.protocol.map=PLAINTEXT:PLAINTEXT,OUTER:SASL_PLAINTEXTsasl.enabled.mechanisms=PLAIN
sasl.mechanism.inter.broker.protocol=PLAINlistener.name.outer.plain.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required \username="admin" \password="admin-secret" \user_admin="admin-secret" \user_alice="alice-secret" \user_abcd="abcd";#开启acl
authorizer.class.name=kafka.security.authorizer.AclAuthorizer
allow.everyone.if.no.acl.found=true
super.users=User:admin
cd /opt/kafka_2.13-3.6.1
#启动kafka
bin/kafka-server-start.sh -daemon config/server.properties
#启动zkbin/zookeeper-server-start.sh -daemon config/zookeeper.properties
2. acl授权
#创建topic
/opt/kafka_2.13-3.6.1/bin/kafka-topics.sh --create --topic collection-syslog-topic --bootstrap-server 192.168.50.240:9094
#赋权/opt/kafka_2.13-3.6.1/bin/kafka-acls.sh --bootstrap-server 192.168.50.240:9092 --add --allow-principal User:alice --operation Write --topic collection-syslog-topic
/opt/kafka_2.13-3.6.1/bin/kafka-acls.sh --bootstrap-server 192.168.50.240:9092 --add --allow-principal User:xdso --operation read --topic collection-syslog-topic
3.配置生产者,消费者
vim /opt/kafka_2.13-3.6.1/config/producer.properties
vim /opt/kafka_2.13-3.6.1/config/consumer.properties
增加以下内容
security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAINsasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required \username="alice" \password="alice-secret";
4. 发送消息,接受消息
bin/kafka-console-producer.sh --bootstrap-server 192.168.50.240:9094 --topic collection-syslog-topic --producer.config config/producer.properties
bin/kafka-console-consumer.sh --bootstrap-server 192.168.50.240:9094 --topic collection-syslog-topic --consumer.config config/consumer.properties