测试环境搭建整套大数据系统(十九: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_PLAINTEXT

sasl.enabled.mechanisms=PLAIN
sasl.mechanism.inter.broker.protocol=PLAIN

listener.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 
#启动zk
 bin/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=PLAIN

sasl.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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值