kafka配置SASL后,第一次发送消息特别慢,27s左右,后面就是10毫秒左右了
操作系统:centos7.8
zookeeper:zookeeper-3.4.14
kafka:kafka_2.13-2.5.0
jdk:1.8
使用伪集群3节点模式
配置了SASL,使用明文账号密码认证
public Map<string, object=""> producerConfigs() {
Map<String, Object> props = new HashMap<>();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, servers4Producer);
props.put(ProducerConfig.RETRIES_CONFIG, retries4Producer);
props.put(ProducerConfig.BATCH_SIZE_CONFIG, batchSize4Producer);
props.put(ProducerConfig.LINGER_MS_CONFIG, linger4Producer);
props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, bufferMemory4Producer);
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
logger.info("开启kafka账号密码配置 {}-{}",kafkaProducerUsername, kafkaProducerPassword);
props.put(SaslConfigs.SASL_MECHANISM, kafkaSaslMechanism);
props.put(SaslConfigs.SASL_JAAS_CONFIG, "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"" + kafkaProducerUsername + "\" password=\"" + kafkaProducerPassword + "\";");
props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, kafkaSecurityProtocol);
return props;
}
报错信息
2021-04-23 17:51:56.581 [http-nio-22000-exec-3] INFO org.apache.kafka.clients.producer.ProducerConfig -ProducerConfig values:
acks = 1
batch.size = 16384
bootstrap.servers = [192.168.148.76:9092, 192.168.148.76:9093, 192.168.148.76:9094]
buffer.memory = 409600000
client.id =
compression.type = none
connections.max.idle.ms = 540000
enable.idempotence = false
interceptor.classes = []
key.serializer = class org.apache.kafka.common.serialization.StringSerializer
linger.ms = 5
max.block.ms = 60000
max.in.flight.requests.per.connection = 5
max.request.size = 1048576
metadata.max.age.ms = 300000
metric.reporters = []
metrics.num.samples = 2
metrics.recording.level = INFO
metrics.sample.window.ms = 30000
partitioner.class = class org.apache.kafka.clients.producer.internals.DefaultPartitioner
receive.buffer.bytes = 32768
reconnect.backoff.max.ms = 1000
reconnect.backoff.ms = 50
request.timeout.ms = 30000
retries = 0
retry.backoff.ms = 100
sasl.client.callback.handler.class = null
sasl.jaas.config = [hidden]
sasl.kerberos.kinit.cmd = /usr/bin/kinit
sasl.kerberos.min.time.before.relogin = 60000
sasl.kerberos.service.name = null
sasl.kerberos.ticket.renew.jitter = 0.05
sasl.kerberos.ticket.renew.window.factor = 0.8
sasl.login.callback.handler.class = null
sasl.login.class = null
sasl.login.refresh.buffer.seconds = 300
sasl.login.refresh.min.period.seconds = 60
sasl.login.refresh.window.factor = 0.8
sasl.login.refresh.window.jitter = 0.05
sasl.mechanism = PLAIN
security.protocol = SASL_PLAINTEXT
send.buffer.bytes = 131072
ssl.cipher.suites = null
ssl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1]
ssl.endpoint.identification.algorithm = https
ssl.key.password = null
ssl.keymanager.algorithm = SunX509
ssl.keystore.location = null
ssl.keystore.password = null
ssl.keystore.type = JKS
ssl.protocol = TLS
ssl.provider = null
ssl.secure.random.implementation = null
ssl.trustmanager.algorithm = PKIX
ssl.truststore.location = null
ssl.truststore.password = null
ssl.truststore.type = JKS
transaction.timeout.ms = 60000
transactional.id = null
value.serializer = class org.apache.kafka.common.serialization.StringSerializer
2021-04-23 17:51:56.624 [http-nio-22000-exec-3] INFO o.a.k.common.security.authenticator.AbstractLogin -Successfully logged in.
2021-04-23 17:51:56.648 [http-nio-22000-exec-3] INFO org.apache.kafka.common.utils.AppInfoParser -Kafka version : 2.0.0
2021-04-23 17:51:56.649 [http-nio-22000-exec-3] INFO org.apache.kafka.common.utils.AppInfoParser -Kafka commitId : 3402a8361b734732
2021-04-23 17:52:23.910 [kafka-producer-network-thread | producer-1] INFO org.apache.kafka.clients.Metadata -Cluster ID: 5Hc4q95xQZSk-jvZK4G8ng
2021-04-23 17:52:23.942 [http-nio-22000-exec-3] INFO 推数据到kafka:27598ms
认证20秒,太慢了,是不正常的。
可以看看这个,https://blog.csdn.net/LuckFu/article/details/124020426?spm=1001.2014.3001.5502
同样的现象。有解决方案。
你的答案