zoukankan      html  css  js  c++  java
  • sentry磁盘占用过大如何清理历史数据

    引用:https://www.phpmianshi.com/?id=182

    1、SENTRY数据软清理 (清理完不会释放磁盘,如果很长时间没有运行,清理时间会很长)
    Bash

    登录worker容器

    docker exec -it sentry_onpremise_worker_1 /bin/bash

    保留多少天的数据,cleanup使用delete命令删除postgresql数据,但对于delete,update等操作,只是将对应行标志为DEAD,并没有真正释放磁盘空间

    sentry cleanup --days 7
    2、POSTGRES数据清理 (清理完后会释放磁盘空间)
    Bash

    登录postgres容器

    docker exec -it sentry_onpremise_postgres_1 /bin/bash

    运行清理

    vacuumdb -U postgres -d postgres -v -f --analyze
    3、定时清理脚本
    Bash
    0 1 * * * cd /data1/onpremise && { time docker-compose run --rm worker cleanup --days 7; } &> /var/log/cleanup.log
    0 8 * * * { time docker exec -i $(docker ps --format "table {{.Names}}"|grep postgres) vacuumdb -U postgres -d postgres -v -f --analyze; } &> /data1/logs/vacuumdb.log
    4、异常处理
    因为磁盘已经被占满,所以上面的清理命令也执行不动了,没办法只能自己寻找大文件临时删除一些,于是找到了下面的大文件

    /var/lib/docker/volumes/sentry-kafka/_data/events-0/

    /var/lib/docker/volumes/sentry-kafka/_data/ingest-events-0/

    删除昨天以前的数据

    看着是 .log结尾的文件,而且很大,就直接删除了,结果发现重启后,sentry无法正常收到上报了。

    参考:https://forum.sentry.io/t/sentry-disk-cleanup-kafka/11337

    没办法,只能重新安装

    Bash
    cd /data1/onpremise
    ./install.sh
    重新启动生效,重新安装不会清理原有数据,所以不备份也没关系

    Bash
    docker-compose down
    docker-compose build
    docker-compose up -d
    5.清理kafka占用磁盘过大的问题
    清理kafka占用磁盘过大的问题搜到可以配置 .env,如下,但是我的没有效果

    Bash
    KAFKA_LOG_RETENTION_HOURS=24
    KAFKA_LOG_RETENTION_BYTES=53687091200 #50G
    KAFKA_LOG_SEGMENT_BYTES=1073741824 #1G
    KAFKA_LOG_RETENTION_CHECK_INTERVAL_MS=300000
    KAFKA_LOG_SEGMENT_DELETE_DELAY_MS=60000
    于是自己研究,首先进入kafka的容器

    Bash
    docker exec -it sentry_onpremise_kafka_1 /bin/bash

    查看topics

    kafka-topics --list --zookeeper zookeeper:2181

    修改kafka配置文件

    vi /etc/kafka/server.properties

    修改为7小时 默认168

    log.retention.hours=7
    log.cleaner.enable=true
    log.cleanup.policy=delete
    log.cleanup.interval.mins=1

    重启

    kafka-server-stop
    kafka-server-start -daemon
    重启后过了一会也没效果,第二天才看到效果,具体原因有待研究,再去查看目录的大小,发小从20G下降到12G左右

    Bash
    cd /var/lib/docker/volumes/sentry-kafka/_data/events-0
    du -h --max-depth=1
    ls -alh # 日期最小的是3天前的日志:00000000000000146071.log
    docker容器没有vi命令的解决方案

    Bash
    apt-get update
    apt-get install vim
    6、官方解决方案
    其实官方已经提供了解决方案,修改 .env文件的以下配置

    Bash
    SENTRY_EVENT_RETENTION_DAYS=7
    重新安装即可

    详情参考:https://github.com/getsentry/onpremise

    Event Retention
    Sentry comes with a cleanup cron job that prunes events older than 90 days by default. If you want to change that, you can change the SENTRY_EVENT_RETENTION_DAYS environment variable in .env or simply override it in your environment. If you do not want the cleanup cron, you can remove the sentry-cleanup service from the docker-compose.ymlfile.

    ----------当你发现自己的才华撑不起野心时,就请安静下来学习吧---------
  • 相关阅读:
    Mybatis学习笔记
    Java——设计模式
    Java——多线程
    Java——集合
    DAO层、Service层、Controller层、View层
    Mybatis整合spring
    Spring中的DI和IOC
    事务
    Xml实现AOP
    2018.3.10考试的试题解析
  • 原文地址:https://www.cnblogs.com/Qing-840/p/15248570.html
Copyright © 2011-2022 走看看