工作中遇到的几个Kafka问题整理

1. Kafka集群搭建好以后,运行一段时间Kafka节点挂掉,程序中出现如下错误

   ERROR Error while accepting connection (kafka.network.Acceptor)
   java.io.IOException: Too many open files 

   使用命令:ulimit -a   查看每个用户允许打开的最大文件数
   发现系统默认的是open files (-n) 1024,问题就出现在这里。
   然后执行:ulimit -n 4096
   将open files (-n) 1024 设置成open files (-n) 4096
   lsof -p 'kafka的进程号' | wc -l 

   命令行为临时修改不能持久
   vim /etc/security/limits.conf 
   * - nofile 8192 

2. 服务器磁盘空间小就二三十G,被kafka的日志文件给吃掉了

  这就需要调整kafkalog的保存时间以及segments的大小了,可以调整以下几个参数  

  # The minimum age of a log file to be eligible for deletion
  #log.retention.hours=168
    log.retention.hours=1

  # A size-based retention policy for logs. Segments are pruned from the log as long as the remaining
  # segments don't drop below log.retention.bytes.
  #log.retention.bytes=1073741824
    log.retention.bytes=50000000

  # The maximum size of a log segment file. When this size is reached a new log segment will be created.
    log.segment.bytes=50000000

3. Kafka消息过大,导致经常堵塞出现 kafka.common.MessageSizeTooLargeException

   1)producer.properties中参数 compression.codec和commpressed.topics 开启压缩功能

   2)server.properties  调整  message.max.bytes 大小,同时保证这个值小于  replica.fetch.max.bytes 这个参数值

   3)consumer.properties  调整  fetch.message.max.bytes 大小,保证它大于message.max.bytes.

  在使用java实现生产者和消费者时,参考上述调整参数大小。

猜你喜欢

转载自my.oschina.net/u/2329222/blog/2253094