sentry磁盘占用过大如何清理历史数据

883 阅读2分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

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

#登录worker容器docker exec -it sentry_onpremise_worker_1 /bin/bash #保留多少天的数据,cleanup使用delete命令删除postgresql数据,但对于delete,update等操作,只是将对应行标志为DEAD,并没有真正释放磁盘空间sentry cleanup --days 7

2、POSTGRES数据清理 (清理完后会释放磁盘空间)

#登录postgres容器docker exec -it sentry_onpremise_postgres_1 /bin/bash#运行清理vacuumdb -U postgres -d postgres -v -f --analyze

3、定时清理脚本

0 1 * * * cd /data1/onpremise && { time docker-compose run --rm worker cleanup --days 7; } &> /var/log/cleanup.log0 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无法正常收到上报了。

参考:forum.sentry.io/t/sentry-di…

没办法,只能重新安装

cd /data1/onpremise./install.sh

重新启动生效,重新安装不会清理原有数据,所以不备份也没关系

docker-compose downdocker-compose builddocker-compose up -d

5.清理kafka占用磁盘过大的问题

清理kafka占用磁盘过大的问题搜到可以配置 .env,如下,但是我的没有效果

KAFKA_LOG_RETENTION_HOURS=24KAFKA_LOG_RETENTION_BYTES=53687091200   #50GKAFKA_LOG_SEGMENT_BYTES=1073741824      #1GKAFKA_LOG_RETENTION_CHECK_INTERVAL_MS=300000KAFKA_LOG_SEGMENT_DELETE_DELAY_MS=60000

于是自己研究,首先进入kafka的容器

docker exec -it sentry_onpremise_kafka_1 /bin/bash#查看topicskafka-topics --list --zookeeper zookeeper:2181#修改kafka配置文件vi /etc/kafka/server.properties #修改为7小时 默认168log.retention.hours=7log.cleaner.enable=truelog.cleanup.policy=deletelog.cleanup.interval.mins=1#重启kafka-server-stop kafka-server-start -daemon

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

cd /var/lib/docker/volumes/sentry-kafka/_data/events-0du -h --max-depth=1ls -alh # 日期最小的是3天前的日志:00000000000000146071.log

docker容器没有vi命令的解决方案

apt-get updateapt-get install vim

6、官方解决方案

其实官方已经提供了解决方案,修改 .env文件的以下配置

SENTRY_EVENT_RETENTION_DAYS=7

重新安装即可

详情参考:github.com/getsentry/o…

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.