在CentOS上优化Kafka配置,可以从以下几个方面入手:
export KAFKA_HEAP_OPTS="-Xmx8G -Xms8G"
num.partitions=100
default.replication.factor=3
log.flush.interval.messages
:控制每写入多少条消息后刷新日志。log.flush.interval.ms
:控制每隔多少毫秒刷新日志。log.flush.interval.messages=100000
log.flush.interval.ms=1000
log.retention.hours
:控制日志保留时间。log.segment.bytes
:控制日志段的大小。log.retention.hours=168
log.segment.bytes=1073741824
message.max.bytes
:控制单条消息的最大大小。replica.fetch.max.bytes
:控制副本拉取消息的最大大小。message.max.bytes=1000000
replica.fetch.max.bytes=104857600
batch.size
:控制批处理的大小。linger.ms
:控制发送消息前的等待时间。batch.size=16384
linger.ms=5
compression.type
:启用压缩可以减少网络传输和存储开销。compression.type=gzip
fetch.min.bytes=1
fetch.max.wait.ms=500
net.core.rmem_max
和 net.core.wmem_max
:增加接收和发送缓冲区大小。net.ipv4.tcp_rmem
和 net.ipv4.tcp_wmem
:设置TCP接收和发送缓冲区大小。echo "net.core.rmem_max=16777216" >> /etc/sysctl.conf
echo "net.core.wmem_max=16777216" >> /etc/sysctl.conf
echo "net.ipv4.tcp_rmem=4096 87380 16777216" >> /etc/sysctl.conf
echo "net.ipv4.tcp_wmem=4096 65536 16777216" >> /etc/sysctl.conf
sysctl -p
jmx.port=9999
log4j.rootLogger=INFO, stdout
通过以上优化措施,可以显著提高Kafka在CentOS上的性能和稳定性。根据实际需求和环境,可能需要进一步调整和测试。