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、動物園の飼育員 構成
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.2. Zookeeper 設定ファイルに設定命令を追加する
# 身份验证提供程序
authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider
# 需要客户端身份验证方案
requireClientAuthScheme=sasl
# jaas登录续订
jaasLoginRenew=3600000
2.3. 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.4. Zookeeper 起動スクリプト bin/zookeeper-server-start.sh を変更する
# 编辑启动脚本
vim bin/zookeeper-server-start.sh
2.5. Zookeeper は次のコンテンツを追加します
# 增加JAAS配置文件
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 は次のコンテンツを追加します
# 增加JAAS配置文件
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 命令
./bin/kafka-server-start.sh -daemon config/server.properties