版本: kafka_2.13-3.2.1
一. zookeeper 配置
1. zookeeper.properties 添加改下配置
authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider
requireClientAuthScheme=sasl
jaasLoginRenew=3600000
2. 创建zookeeper_jaas.conf
Server {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="admin"
password="admin123"
user_admin="admin123"
user_zkclient="zkclient123";
};
admin 是zk之间使用的
zkclient是broker与zk之间使用的
3. 添加zookeeper_jass.conf 到启动脚本
vi /bin/zookeeper-server-start.sh
export KAFKA_OPTS="-Djava.security.auth.login.config=/$path/kafka_2.13-3.2.1/config/zookeeper_jaas.conf -Dzookeeper.sasl.serverconfig=Server"
4. 启动zookeeper
./bin/zookeeper-server-start.sh config/zookeeper.properties
二. broker 配置
1. server.properties添加以下配置
listeners=SASL_PLAINTEXT://:9092
security.inter.broker.protocol=SASL_PLAINTEXT
sasl.mechanism.inter.broker.protocol=PLAIN
sasl.enabled.mechanisms=PLAIN
advertised.listeners=SASL_PLAINTEXT://:9092
auto.create.topics.enable=true
2. 创建 kafka_server_jaas.conf
KafkaServer {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="kafkaadmin"
password="kafkaadmin123"
user_kafkaadmin="kafkaadmin123"
user_kafkatest="kafkatest000";
};
Client {
org.apache.zookeeper.server.auth.DigestLoginModule required
username="zkclient"
password="zkclient123";
};
- KafkaServer
- kafkaadmin 是broker之前使用的
- kafkatest 是client与broker之间使用的(kafkaadmin client可以用,通常做super)
- Client
- zkclient 是broker与zk之间使用的,须与zk配置一致,不然会验证出错
3. 添加conf 到启动脚本
vi bin/kafka-server-start.sh
export KAFKA_OPTS=" -Djava.security.auth.login.config=/$path/kafka_2.13-3.2.1/config/kafka_server_jaas.conf"
4. 启动broker
./bin/kafka-server-start.sh ./config/server.properties
三. kafka client 配置
1. 创建kafka_client.conf
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required \
username="kafkaadmin" \
password="kafkaadmin123";
security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN
此处使有kafkaadmin 和kafkatest 都行
创建topic
./bin/kafka-topics.sh --create --topic quickstart-events --bootstrap-server localhost:9092 --command-config ./config/kafka_client.conf
topic 查看
./bin/kafka-topics.sh --describe --topic quickstart-events --bootstrap-server localhost:9092 --command-config ./config/kafka_client.conf
后续自行玩耍各种参数