1. 程式人生 > >工作中遇到的幾個Kafka問題整理

工作中遇到的幾個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實現生產者和消費者時,參考上述調整引數大小。