Kafka日志增长太高

fdbelqdn  于 2021-06-04  发布在  Kafka
关注(0)|答案(1)|浏览(486)

我看得见 kafka logs 正在迅速增长,文件系统也在泛滥。
如何更改kafka的设置以减少日志的写入并频繁地旋转这些日志。
文件的位置是- /opt/kafka/kafka_2.12-2.2.2/logs 以及它们的大小-

5.9G    server.log.2020-11-24-14
5.9G    server.log.2020-11-24-15
5.9G    server.log.2020-11-24-16
5.7G    server.log.2020-11-24-17

上述文件中的示例日志。

[2020-11-24 14:59:59,999] WARN Exception when following the leader (org.apache.zookeeper.server.quorum.Learner)
java.io.IOException: No space left on device
        at java.io.FileOutputStream.writeBytes(Native Method)
        at java.io.FileOutputStream.write(FileOutputStream.java:326)
        at org.apache.zookeeper.common.AtomicFileOutputStream.write(AtomicFileOutputStream.java:74)
        at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
        at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)
        at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295)
        at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)
        at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
        at java.io.BufferedWriter.flush(BufferedWriter.java:254)
        at org.apache.zookeeper.server.quorum.QuorumPeer.writeLongToFile(QuorumPeer.java:1391)
        at org.apache.zookeeper.server.quorum.QuorumPeer.setCurrentEpoch(QuorumPeer.java:1426)
        at org.apache.zookeeper.server.quorum.Learner.syncWithLeader(Learner.java:454)
        at org.apache.zookeeper.server.quorum.Follower.followLeader(Follower.java:83)
        at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:981)
[2020-11-24 14:59:59,999] INFO shutdown called (org.apache.zookeeper.server.quorum.Learner)
java.lang.Exception: shutdown Follower
        at org.apache.zookeeper.server.quorum.Follower.shutdown(Follower.java:169)
        at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:985)
[2020-11-24 14:59:59,999] INFO Shutting down (org.apache.zookeeper.server.quorum.FollowerZooKeeperServer)
[2020-11-24 14:59:59,999] INFO LOOKING (org.apache.zookeeper.server.quorum.QuorumPeer)
[2020-11-24 14:59:59,999] INFO New election. My id =  1, proposed zxid=0x1000001d2 (org.apache.zookeeper.server.quorum.FastLeaderElection)
[2020-11-24 14:59:59,999] INFO Notification: 1 (message format version), 1 (n.leader), 0x1000001d2 (n.zxid), 0x2 (n.round), LOOKING (n.state), 1 (n.sid), 0x1 (n.peerEpoch) LOOKING (my state) (org.apache.zookeeper.server.quorum.FastLeaderElection)

它还向 /opt/kafka/kafka_2.12-2.2.2/kafka.log .

[2020-12-05 16:51:10,109] INFO [GroupMetadataManager brokerId=1] Finished loading offsets and group metadata from __consumer_offsets-30 in 0 milliseconds. (kafka.coordinator.group.GroupMetadataManager)
[2020-12-05 16:51:10,109] INFO [GroupMetadataManager brokerId=1] Finished loading offsets and group metadata from __consumer_offsets-36 in 0 milliseconds. (kafka.coordinator.group.GroupMetadataManager)
[2020-12-05 16:51:10,109] INFO [GroupMetadataManager brokerId=1] Finished loading offsets and group metadata from __consumer_offsets-42 in 0 milliseconds. (kafka.coordinator.group.GroupMetadataManager)
[2020-12-05 16:51:10,110] INFO [GroupMetadataManager brokerId=1] Finished loading offsets and group metadata from __consumer_offsets-48 in 0 milliseconds. (kafka.coordinator.group.GroupMetadataManager)
[2020-12-05 17:01:09,528] INFO [GroupMetadataManager brokerId=1] Removed 0 expired offsets in 0 milliseconds. (kafka.coordinator.group.GroupMetadataManager)
[2020-12-05 17:11:09,528] INFO [GroupMetadataManager brokerId=1] Removed 0 expired offsets in 0 milliseconds. (kafka.coordinator.group.GroupMetadataManager)

Kafka用于弹性堆叠。
下面是来自 server.properties 文件。


# A comma seperated list of directories under which to store log files

log.dirs=/var/log/kafka

它的日志文件是

/var/log/kafka
drwxr-xr-x 2 kafka users 4.0K Dec  5 16:51 heartbeat-1
drwxr-xr-x 2 kafka users 4.0K Dec  5 16:51 __consumer_offsets-12
drwxr-xr-x 2 kafka users 4.0K Dec  5 16:51 auditbeat-0
drwxr-xr-x 2 kafka users 4.0K Dec  5 16:51 apm-2
drwxr-xr-x 2 kafka users 4.0K Dec  5 16:51 __consumer_offsets-28
drwxr-xr-x 2 kafka users 4.0K Dec  5 16:51 filebeat-2
drwxr-xr-x 2 kafka users 4.0K Dec  5 16:51 __consumer_offsets-38
drwxr-xr-x 2 kafka users 4.0K Dec  5 16:51 __consumer_offsets-44
drwxr-xr-x 2 kafka users 4.0K Dec  5 16:51 __consumer_offsets-6
drwxr-xr-x 2 kafka users 4.0K Dec  5 16:51 __consumer_offsets-16
drwxr-xr-x 2 kafka users 4.0K Dec  5 16:51 metricbeat-0
drwxr-xr-x 2 kafka users 4.0K Dec  5 16:51 __consumer_offsets-22
drwxr-xr-x 2 kafka users 4.0K Dec  5 16:51 __consumer_offsets-32
-rw-r--r-- 1 kafka users  747 Dec  5 18:02 recovery-point-offset-checkpoint
-rw-r--r-- 1 kafka users    4 Dec  5 18:02 log-start-offset-checkpoint
-rw-r--r-- 1 kafka users  749 Dec  5 18:03 replication-offset-checkpoint

DEBUG 在中的文件中启用了级别日志 /opt/kafka/kafka_2.12-2.2.2/config 路径。
我怎样才能确保它不会在 /opt/kafka/kafka_2.12-2.2.2/logs 还有我怎样才能有规律地旋转它们。
谢谢,

dddzy1tm

dddzy1tm1#

log.dirs 是实际的代理存储,而不是进程日志,因此不应在 /var/log 与其他进程日志
几乎每天6g不是不合理的,但是您可以修改log4j.properties文件,使其与滚动文件appender保持1到2天的距离
一般来说,与任何linux管理任务一样,您都会有单独的磁盘卷来执行 /var/log ,您的操作系统存储,以及任何用于存储服务器数据的专用磁盘—例如 /kafka

相关问题