您的位置:首页 > 教育 > 锐评 > 测试环境搭建整套大数据系统(十九:kafka3.6.0单节点做 sasl+acl)

测试环境搭建整套大数据系统(十九:kafka3.6.0单节点做 sasl+acl)

2024/10/6 8:33:59 来源:https://blog.csdn.net/weixin_43446246/article/details/141208043  浏览:    关键词:测试环境搭建整套大数据系统(十九:kafka3.6.0单节点做 sasl+acl)

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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com