GBase 8a目前可以支持kafka集群配置SASL/PLAIN认证,下面讲解kafka端配置SASL/PLAIN认证的方法和如何在使用GBase 8a时配置kafka consumer的参数。
kafka用户名密码认证配置方法:
1、编辑config/kafka_server_jaas.conf
KafkaServer {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="admin"
password="admin"
user_admin="admin"
user_gbase="gbase";
};
可以在user_{username}={password} 自定义需要添加的用户名和密码。
2、编辑 config/kafka_client_jaas.conf,保证客户端和服务端里面配置的用户名和密码是一致的。
KafkaClient {
org.apache.kafka.common.security.plain.PlainLoginModule required
username="gbase"
password="gbase";
};
3、kafka启动脚本kafka-server-start.sh里添加代码
export KAFKA_OPTS=" -Djava.security.auth.login.config=/opt/kafka/config/kafka_server_jaas.conf" //修改为kafka_server_jaas.conf的路径
4、在 config/server.properties 里面增加内容
listeners=SASL_PLAINTEXT://localhost:9092
security.inter.broker.protocol=SASL_PLAINTEXT
sasl.mechanism.inter.broker.protocol=PLAIN
sasl.enabled.mechanisms=PLAIN
此时已经可以启动kafka集群服务了。
5、编辑kafka-console-producer.sh,添加代码,在倒数第二行:
export KAFKA_OPTS=" -Djava.security.auth.login.config=/opt/kafka/config/kafka_client_jaas.conf" //修改为kafka_server_jaas.conf的路径
在config/producer.properties里面编辑:
security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN
6、编辑kafka-console-consumer.sh, 添加代码,在倒数第二行:
export KAFKA_OPTS=" -Djava.security.auth.login.config=/opt/kafka/config/kafka_client_jaas.conf" //修改为kafka_server_jaas.conf的路径
在consumer.properties里面编辑
security.protocol=SASL_PLAINTEXT
sasl.mechanism=PLAIN
7、创建topic,测试producer和consumer
$kafka_home/bin/kafka-topics.sh --create --zookeeper 10.10.11.167:2181 --replication-factor 2 --partitions 1 --topic yuehaoyu
$kafka_home/bin/kafka-console-producer.sh --broker-list 10.10.11.167:9092 --topic yuehaoyu --producer.config $kafka_home/config/producer.properties
随意写入数据,然后启动consumer脚本,从头开始消费
$kafka_home/bin/kafka-console-consumer.sh --bootstrap-server 10.10.11.167:9092 --topic yuehaoyu --consumer.config $kafka_home/config/consumer.properties --from-beginning
查看是否成功消费producer生产的数据。
若成功,说明kafka集群配置普通密码加密方式认证成功。
使用GBase 8a:
首先确认一下使用的版本是否有gbase_kafka_auth_mode参数,如果有的话,将它设置成’Plain’,然后正确配置gbase_kafka_username和gbase_kafka_password,就可以正常使用带SASL/PLAIN认证的kafka了。
如果没有gbase_kafka_auth_mode参数,但是有gbase_kafka_username和gbase_kafka_password,那么配置这两个参数后默认使用plain认证方式。其他操作不受影响。
如果上面提到的三个参数都没有,那么这个版本不支持使用带SASL/PLAIN认证的kafka。