Kafka集成Kerberos之后如何使用生产者消费者命令

1、生产者
1.1、准备jaas.conf并添加到环境变量(使用以下方式的其中一种)
1.1.1、使用Kinit方式
前提是手动kinit

配置内容为:

KafkaClient { com.sun.security.auth.module.Krb5LoginModule required useTicketCache=true renewTicket=true serviceName="kafka"; }; 

1.1.2、使用指定keytab和票据的方式

准备好你的keytab文件

配置内容为:

KafkaClient { com.sun.security.auth.module.Krb5LoginModule required useKeyTab=true keyTab="/usr/keytab/xiet.keytab" principal="xiet@BETA.COM"; }; 

* 添加到环境变量:

export KAFKA_OPTS="-Djava.security.auth.login.config=/home/xxx/jaas.conf" 

2、执行命令

kafka-console-producer --broker-list xxx:9092,yyy:9092 --topic sparktest --security-protocol SASL_PLAINTEXT 

或者使用配置文件的方式

producer.properties

security.protocol=SASL_PLAINTEXT sasl.mechanism=GSSAPI sasl.kerberos.service.name=kafka 

 kafka-console-producer --broker-list 10.211.55.5:9093 --topic test --producer.config  config/producer.properties 

2、消费者
2.1、准备jaas.conf并添加到环境变量
内容同1.1节

2.2、准备consumer.properties
文件内容为:

security.protocol=SASL_PLAINTEXT sasl.mechanism=GSSAPI sasl.kerberos.service.name=kafka group.id=test-consumer-group 

2.3、执行命令

kafka-console-consumer --bootstrap-server xxx:9092,yyy:9092 --topic sparktest  --from-beginning --consumer.config ./consumer.properties