0
点赞
收藏
分享

微信扫一扫

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

玉字璧 2022-11-25 阅读 166


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.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/*.log

 

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

 

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

 

没办法,只能重新安装


cd /data1/onpremise
./install.sh


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


docker-compose down
docker-compose build
docker-compose up -d


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

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


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的容器


docker exec -it sentry_onpremise_kafka_1 /bin/bash

#查看topics
kafka-topics --list --zookeeper zookeeper:2181
#修改kafka配置文件
vi server.propertyies
#修改为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左右


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


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


apt-get update
apt-get install vim

6、官方解决方案

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


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.yml​​file.

举报

相关推荐

0 条评论