kafka客户端需要Java依赖,所以先安装Java11,
sudo yum install java-11
https://docs.aws.amazon.com/zh_cn/msk/latest/developerguide/port-info.html
# 匿名使用9092端口
BootstrapServerString=b-2.xxxx.kafka.cn-north-1.amazonaws.com.cn:9092,b-1.xxxx.c4.kafka.cn-north-1.amazonaws.com.cn:9092
# 创建topic
./kafka-topics.sh --create --bootstrap-server $BootstrapServerString --replication-factor 2 --partitions 1 --topic MSKTutorialTopic
# 生产者
./kafka-console-producer.sh --broker-list $BootstrapServerString --topic MSKTutorialTopic
# 消费者
./kafka-console-consumer.sh --bootstrap-server $BootstrapServerString --topic MSKTutorialTopic --from-beginning
匿名TLS传输和mTLS认证都使用9094端口。
匿名TLS和匿名纯文本只能二选一
client_tls.properties
security.protocol=SSL
./kafka-console-producer.sh --broker-list $BootstrapServerString --topic MSKTutorialTopic --producer.config client_tls.properties
./kafka-console-consumer.sh --bootstrap-server $BootstrapServerString --topic MSKTutorialTopic --from-beginning --from-beginning --consumer.config client_tls.properties
中国区目前不支持TLS双向认证。
IAM认证是Amazon自己加的功能,所以需要下载额外的包,https://github.com/aws/aws-msk-iam-auth
cp aws-msk-iam-auth-1.1.1-all.jar kafka_2.13-2.8.1/libs/
IAM 创建topic命令:
BootstrapServerString=b-1.xxxx.c4.kafka.cn-north-1.amazonaws.com.cn:9098,b-2.xxxx.c4.kafka.cn-north-1.amazonaws.com.cn:9098
./kafka-topics.sh --create --bootstrap-server $BootstrapServerString --command-config client.properties --replication-factor 2 --partitions 1 --topic MSKTutorialTopic
client.properties
security.protocol=SASL_SSL
sasl.mechanism=AWS_MSK_IAM
sasl.jaas.config=software.amazon.msk.auth.iam.IAMLoginModule required;
sasl.client.callback.handler.class=software.amazon.msk.auth.iam.IAMClientCallbackHandler
要使用您为 AWS 凭证创建的命名配置文件,请将 awsProfileName="`your profile name`"
https://docs.aws.amazon.com/zh_cn/msk/latest/developerguide/iam-access-control.html
这个需要关联Secrets Manager,而且Secrets Manager必须以AmazonMSK_开头,多租户的话需要关联多个Secrets Manager,如果在Secrets Manage中修改用户密码,那么需要重新绑定,否则新旧密码都能使用,这显然不符合预期。
创建users_jaas.conf文件,这个是用户名密码:
KafkaClient {
org.apache.kafka.common.security.scram.ScramLoginModule required
username="alice"
password="alice-secret";
};
然后导出到环境变量:
export KAFKA_OPTS=-Djava.security.auth.login.config=$PWD/users_jaas.conf
配置信息:
security.protocol=SASL_SSL
sasl.mechanism=SCRAM-SHA-512
连接:
BootstrapBrokerStringSaslScram=b-1.xxxx.c4.kafka.cn-north-1.amazonaws.com.cn:9096,b-2.xxxx.kafka.cn-north-1.amazonaws.com.cn:9096
[ec2-user@ip-10-0-10-91 bin]$ ./kafka-console-producer.sh --broker-list $BootstrapServerString --topic MSKTutorialTopic --producer.config client_sasl.properties
./kafka-console-consumer.sh --bootstrap-server $BootstrapBrokerStringSaslScram --topic MSKTutorialTopic --from-beginning --consumer.config client_sasl.properties
https://repost.aws/zh-Hans/knowledge-ceneccccvfubhkhugdueicbcbvubnlrgefkkldbeurkjfenter/msk-sasl-scram-issues
kafka ACL:https://docs.aws.amazon.com/zh_cn/msk/latest/developerguide/msk-acls.html
https://cwiki.apache.org/confluence/display/KAFKA/Kafka+Authorization+Command+Line+Interface
待测试