1、下载安装
Kafka下载地址:Apache Kafka
# 下载文件 wget https://downloads.apache.org/kafka/3.5.1/kafka_2.12-3.5.1.tgz # 文件解压缩 tar -zxvf kafka_2.12-3.5.1.tgz # 修改目录名称 mv kafka_2.12-3.5.1 kafka_2.12 # 进入目录 cd kafka_2.12
2、Zookeeper 配置
2.1、修改 Zookeeper 配置文件 config/zookeeper.properties
# 编辑 zookeeper 配置文件 vim config/zookeeper.properties
2.2、Zookeeper 配置文件修改内容
dataDir=/tmp/zookeeper # the port at which the clients will connect clientPort=2181 # disable the per-ip limit on the number of connections since this is a non-production config maxClientCnxns=0 # Disable the adminserver by default to avoid port conflicts. # Set the port to something non-conflicting if choosing to enable this admin.enableServer=false # admin.serverPort=8080 authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider requireClientAuthScheme=sasl jaasLoginRenew=3600000
2.3、Zookeeper 配置文件增加配置说明
# 身份验证提供程序 authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider # 需要客户端身份验证方案 requireClientAuthScheme=sasl # jaas登录续订 jaasLoginRenew=3600000
2.4、Zookeeper 配置JAAS文件
# 配置JAAS文件 cat > config/zookeeper_jaas.conf << EOF Server { org.apache.kafka.common.security.plain.PlainLoginModule required username="admin" password="admin-2022" user_kafka="kafka-2022" user_producer="producer-2022"; }; EOF
2.5、Zookeeper 修改启动脚本 bin/zookeeper-server-start.sh
# 编辑启动脚本 vim bin/zookeeper-server-start.sh
2.6、Zookeeper 增加如下内容
export KAFKA_OPTS="-Djava.security.auth.login.config=/usr/local/kafka_2.12/config/zookeeper_jaas.conf"
3、Kafka 配置
3.1、修改 Kafka 配置文件 config/server.properties
# 编辑 Kafka 配置文件 vim config/server.properties
3.2、Kafka 配置文件修改内容
未做变更的不做展示
listeners=SASL_PLAINTEXT://0.0.0.0:9092 advertised.listeners=SASL_PLAINTEXT://192.168.1.95:9092 security.inter.broker.protocol=SASL_PLAINTEXT sasl.enabled.mechanisms=PLAIN sasl.mechanism.inter.broker.protocol=PLAIN # 完成身份验证的类 authorizer.class.name=kafka.security.authorizer.AclAuthorizer # 如果没有找到ACL(访问控制列表)配置,则允许任何操作。 allow.everyone.if.no.acl.found=false # 需要开启设置超级管理员,设置admin用户为超级管理员 super.users=User:admin
3.3、Kafka 配置JAAS文件
# 配置JAAS文件 cat > config/kafka_server_jaas.conf << EOF KafkaServer { org.apache.kafka.common.security.plain.PlainLoginModule required username="admin" password="admin-secret" user_admin="admin-secret" user_alice="secret"; }; KafkaClient { org.apache.kafka.common.security.plain.PlainLoginModule required username="kafka" password="kafka-2022"; }; EOF
3.4、Kafka 修改启动脚本 bin/kafka-server-start.sh
# 编辑启动脚本 vim bin/kafka-server-start.sh
3.5、Kafka 增加如下内容
if [ "x$KAFKA_OPTS" ]; then export KAFKA_OPTS="-Djava.security.auth.login.config=/usr/local/kafka_2.12/config/kafka_server_jaas.conf" fi
4、启动 Zookeeper
执行启动 Zookeeper 命令
# 执行启动 zookeeper 命令 ./bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
5、启动 Kafka
执行启动 Kafka 命令
# 执行启动 kafka 命令 ./bin/kafka-server-start.sh -daemon config/server.properties标签:Zookeeper,PLAINTEXT,zookeeper,kafka,SASL,server,config,Kafka From: https://www.cnblogs.com/cdkj/p/17850585.html