工做中遇到的幾個Kafka問題整理

1. Kafka集羣搭建好之後,運行一段時間Kafka節點掛掉,程序中出現以下錯誤java

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

   使用命令: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 fetch

2. 服務器磁盤空間小就二三十G,被kafka的日誌文件給吃掉了this

  這就須要調整kafkalog的保存時間以及segments的大小了,能夠調整如下幾個參數  spa

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

  # 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.MessageSizeTooLargeExceptioncode

   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實現生產者和消費者時,參考上述調整參數大小。

相關文章
相關標籤/搜索