第一章 Kafka 配置部署及SASL_PLAINTEXT安全認(rèn)證
系列文章目錄
第一章
第二章 Spring Boot 整合 Kafka消息隊列 生產(chǎn)者
第三章 Spring Boot 整合 Kafka消息隊列 消息者(待續(xù))
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 # 進(jìn)入目錄 cd kafka_2.12
2、Zookeeper 配置
2.1、修改 Zookeeper 配置文件 config/zookeeper.properties
# 編輯 zookeeper 配置文件
vim config/zookeeper.properties
2.2、Zookeeper 配置文件修改內(nèi)容
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登錄續(xù)訂 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 增加如下內(nèi)容
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 配置文件修改內(nèi)容
未做變更的不做展示
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 # 需要開啟設(shè)置超級管理員,設(shè)置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 增加如下內(nèi)容
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
執(zhí)行啟動 Zookeeper 命令
# 執(zhí)行啟動 zookeeper 命令 ./bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
5、啟動 Kafka
執(zhí)行啟動 Kafka 命令
# 執(zhí)行啟動 kafka 命令 ./bin/kafka-server-start.sh -daemon config/server.properties

浙公網(wǎng)安備 33010602011771號