日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人工智能 > ChatGpt >内容正文

ChatGpt

Kafka 压缩、限流和 SASL_PLAIN 、 SASL_SCRAM-SHA-256简单认证

發布時間:2023/12/14 ChatGpt 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Kafka 压缩、限流和 SASL_PLAIN 、 SASL_SCRAM-SHA-256简单认证 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

限流方式

方式優點缺點
client id簡單便捷client id,一次只能有一個生產者實例,只能單并發
user可以多 producer 同時進行,可與client id 進行組合,可以設置用戶密碼,增加一定的安全性,但用戶名密碼位置容易暴露需要對kafka 開啟安全認證,部署復雜行增加

基于 client id 限流

使用方法

# 對 test_lz4_10m_client 進行限流 生產消費速率為 10 M/S ./bin/kafka-configs.sh --bootstrap-server xxxx:9092 --alter --add-config 'producer_byte_rate=10240,consumer_byte_rate=10240,request_percentage=200' --entity-type clients --entity-name test_lz4_10m_client

基于 user 限流

kafka 認證方式

  • SASL/GSSAPI (Kerberos) - starting at version 0.9.0.0
  • SASL/PLAIN - starting at version 0.10.0.0 (每次生效需要重啟broker)
  • SASL/SCRAM-SHA-256 and SASL/SCRAM-SHA-512 - starting at version 0.10.2.0 (可動態增加用戶)
  • SASL/OAUTHBEARER - starting at version 2.0

其中 SASL/GSSAPI (Kerberos) 這種可能是生產環境使用最合適的,但是筆者這邊暫時還沒有使用 Kerberos ,所以這里主要使用 SASL/PLAIN 和 SASL/SCRAM-SHA-256 這兩種做一個探索。

使用 SASL_PLAINTEXT/PLAIN 進行用戶認證實現限流

  • broker 配置
  • #配置 ACL 入口類 authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer #本例使用 SASL PLAINTEXT listeners=SASL_PLAINTEXT://xxxxxx:9092 advertised.listeners=SASL_PLAINTEXT://xxxxxx:9092 security.inter.broker.protocol= SASL_PLAINTEXT sasl.mechanism.inter.broker.protocol=PLAIN sasl.enabled.mechanisms=PLAIN #設置本例中 admin 為超級用戶 super.users=User:admin
  • 創建 kafka_server_jaas.conf
  • # 這里是創建了兩個用戶admin和test user_admin 表示用戶 admin,后面的 admin-secret 表示是 admin 的密碼 KafkaServer {org.apache.kafka.common.security.plain.PlainLoginModule requiredusername="admin"password="admin-secret"user_admin="admin-secret"user_test="123456"; };
  • 啟動腳本添加指定 kafka_server_jaas.conf
  • vim kafka-server-start.sh

    # 添加 -Djava.security.auth.login.config=/data/kafka_2.13-2.7.1/config/kafka_server_jaas.conf exec $base_dir/kafka-run-class.sh $EXTRA_ARGS -Djava.security.auth.login.config=/data/kafka_2.13-2.7.1/config/kafka_server_jaas.conf kafka.Kafka "$@"
  • 添加生產者消費者配置文件
  • # 生產者 producer_jaas.conf 消費者 consumer_jaas.conf 權限文件 KafkaClient { org.apache.kafka.common.security.plain.PlainLoginModule required username = "test" password="123456"; };# 修改 kafka-console-producer.sh ## -Djava.security.auth.login.config=/data/kafka_2.13-2.7.1/config/producer_jaas.conf exec $(dirname $0)/kafka-run-class.sh -Djava.security.auth.login.config=/data/kafka_2.13-2.7.1/config/producer_jaas.conf kafka.tools.ConsoleProducer "$@"# 修改 kafka-console-consumer.sh ## -Djava.security.auth.login.config=/data/kafka_2.13-2.7.1/config/consumer_jaas.conf exec $(dirname $0)/kafka-run-class.sh -Djava.security.auth.login.config=/data/kafka_2.13-2.7.1/config/consumer_jaas.conf kafka.tools.ConsoleConsumer "$@"
  • 使用
  • # 1. 進行授權對 用戶 # 給用戶 test 對 topic test_se 讀的權限 ./bin/kafka-acls.sh --authorizer kafka.security.auth.SimpleAclAuthorizer --authorizer-properties zookeeper.connect=xxxxxx:2181/kafka27 --add --allow-principal User:test --operation Read --topic test_se# 給用戶 test 的 group test-group 賦予讀的權限 ./bin/kafka-acls.sh --authorizer kafka.security.auth.SimpleAclAuthorizer --authorizer-properties zookeeper.connect=xxxxxx:2181/kafka27 --add --allow-principal User:test --operation Read --group test-group# 給用戶 test 賦予 test_se Write 的權限 ./bin/kafka-acls.sh --authorizer kafka.security.auth.SimpleAclAuthorizer --authorizer-properties zookeeper.connect=xxxxxx:2181/kafka27 --add --allow-principal User:test --operation Write --topic test_se# 2. producer 使用 ./bin/kafka-console-producer.sh --bootstrap-server xxxxxx:9092 --topic test_se --producer-property security.protocol=SASL_PLAINTEXT --producer-property sasl.mechanism=PLAIN# 3. consumer 使用 ./bin/kafka-console-consumer.sh --bootstrap-server xxxxxx:9092 --from-beginning --topic test_se --consumer.config ./config/console_consumer.conf

    使用 SASL_PLAINTEXT/SCRAM 進行用戶認證實現限流

  • broker 配置
  • ###################### SASL ######################### sasl.enabled.mechanisms=SCRAM-SHA-256 sasl.mechanism.inter.broker.protocol=SCRAM-SHA-256 security.inter.broker.protocol=SASL_PLAINTEXT listeners=SASL_PLAINTEXT://xxxxxx:9092 advertised.listeners=SASL_PLAINTEXT://xxxxxx:9092 ####################### ACL ######################## authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer super.users=User:admin
  • 創建 kafka-broker-scram.jaas
  • KafkaServer { org.apache.kafka.common.security.scram.ScramLoginModule required username="admin" password="admin"; };
  • 指定 kafka-broker-scram.jaas 位置
  • 修改 vim kafka-server-start.sh

    exec $base_dir/kafka-run-class.sh $EXTRA_ARGS -Djava.security.auth.login.config=/data/kafka_2.13-2.7.1/config/auth/kafka-broker-scram.jaas kafka.Kafka "$@"
  • 添加生產者消費者配置文件
  • # consumer-scram.conf 或 producer-scram.conf security.protocol=SASL_PLAINTEXT sasl.mechanism=SCRAM-SHA-256 sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="test" password="123456";
  • 授權
  • # 添加用戶 ./bin/kafka-configs.sh --zookeeper xxxxxx:2181/kafka27 --alter --add-config 'SCRAM-SHA-256=[password=123456]' --entity-type users --entity-name test# 讀權限 ./bin/kafka-acls.sh --authorizer-properties zookeeper.connect=xxxxxx:2181 --add --allow-principal User:"test" --consumer --topic 'test_topic' --group '*'# 寫權限 ./bin/kafka-acls.sh --authorizer-properties zookeeper.connect=xxxxxx:2181 --add --allow-principal User:"test" --producer --topic 'test_topic'# 生產者 ./bin/kafka-console-producer.sh --broker-list xxxxxx:9092 --topic test_scram --producer.config config/auth/producer-scram.conf# 消費者 ./bin/kafka-console-consumer.sh --bootstrap-server xxxxxx:9092 --topic test_scram --consumer.config config/auth/consumer-scram.conf

    限流

    # 對用戶 test 限流 10M/S ./bin/kafka-configs.sh --zookeeper xxxxxx:2181/kafka27 --alter --add-config 'producer_byte_rate=10485760' --entity-type users --entity-name test# 對 client id 為 clientA 的限流 10M/S ./bin/kafka-configs.sh --zookeeper xxxxxx:2181/kafka27 --alter --add-config 'producer_byte_rate=10485760' --entity-type clients --entity-name clientA# /bin/kafka-configs.sh --bootstrap-server xxxxxx:9092 --alter --add-config 'producer_byte_rate=10240,consumer_byte_rate=10240,request_percentage=200' --entity-type clients --entity-name test_lz4_10m_client

    此處的限流應該是對單個 broker 限流為 10 M/S ,應為測試 topic 有 3 分區分別分布在三個 broker 所以總體限流大概在 30M/S 左右?

    附一張 kafka 壓縮類型對比(無 CPU 對比)

    總結

    以上是生活随笔為你收集整理的Kafka 压缩、限流和 SASL_PLAIN 、 SASL_SCRAM-SHA-256简单认证的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。