Sentry私有化部署的内存和存储优化

在官方的介绍与文档里面对sentry进行了详细的介绍,以及教大家如何进行私有化部署。但是在部署后会出现什么问题,在安装之前与安装之后我们可以通过什么方式进行优化?

通过项目的实际使用所遇到的问题:

1.磁盘空间占用大

2.内存出现爆满

通过在安装之前与安装之后进行优化配置,避免服务出现以上两点问题

一、安装之前

1.配置日志存储时长

官方默认配置为90天,我们可以根据自己服务器资源(硬盘大小),以及项目需要调整配置。调整".env"文件下的配置即可。此配置可有效控制日志存储,防止日志过多,导致硬盘容量不足。

复制代码
# 将此90调整为所需要的值即可

SENTRY_EVENT_RETENTION_DAYS=90

2.开放项目集成的postgresql、clickhouse的端口

开放所用数据的端口,便于使用客户端连接。若数据量过大可以通过数据脚本进行数据清理操作。开放端口主要调整"docker-compose.yml"文件内容。具体调整内容如下:

复制代码
postgres:
    <<: *restart_policy
    # Using the same postgres version as Sentry dev for consistency purposes
    image: "postgres:14.5"
    healthcheck:
      <<: *healthcheck_defaults
      # Using default user "postgres" from sentry/sentry.conf.example.py or value of POSTGRES_USER if provided
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres}"]
    command:
      [
        "postgres",
        "-c",
        "wal_level=logical",
        "-c",
        "max_replication_slots=1",
        "-c",
        "max_wal_senders=1",
      ]
    environment:
      POSTGRES_HOST_AUTH_METHOD: "trust"
    entrypoint: /opt/sentry/postgres-entrypoint.sh
    volumes:
      - "sentry-postgres:/var/lib/postgresql/data"
      - type: bind
        read_only: true
        source: ./postgres/
        target: /opt/sentry/
    ports:
      - "5432:5432"  #增加的端口映射
clickhouse:
    <<: *restart_policy
    image: clickhouse-self-hosted-local
    build:
      context: ./clickhouse
      args:
        BASE_IMAGE: "${CLICKHOUSE_IMAGE:-}"
    ulimits:
      nofile:
        soft: 262144
        hard: 262144
    volumes:
      - "sentry-clickhouse:/var/lib/clickhouse"
      - "sentry-clickhouse-log:/var/log/clickhouse-server"
      - type: bind
        read_only: true
        source: ./clickhouse/config.xml
        target: /etc/clickhouse-server/config.d/sentry.xml
    ports:
      - "8123:8123"  #增加的端口映射
      - "9001:9000"  #增加的端口映射
    environment:
      # This limits Clickhouse's memory to 30% of the host memory
      # If you have high volume and your search return incomplete results
      # You might want to change this to a higher value (and ensure your host has enough memory)
      MAX_MEMORY_USAGE_RATIO: 0.3
    healthcheck:
      test: [
          "CMD-SHELL",
          # Manually override any http_proxy envvar that might be set, because
          # this wget does not support no_proxy. See:
          # https://github.com/getsentry/self-hosted/issues/1537
          "http_proxy='' wget -nv -t1 --spider 'http://localhost:8123/' || exit 1",
        ]
      interval: 10s
      timeout: 10s
      retries: 30

3.设置服务内存限制

内存大小限制,能有效的控制服务运行时存储爆满,将服务器拖垮导致服务宕机。此处建议对clickhouse、postgres、redis服务进行内存限制

复制代码
# 在对应服务的docker-compose文件下增加如下内容即可
deploy:
    resources:
    limits:
    memory: 8G  #根据需要设置内存大小,此处8GB

二、安装之后

根据上述配置进行调整之后,第一次服务运行起来了,我们还需要对一些服务内部的配置进行优化调整,以保持服务长时间稳定运行。

1.kafka日志数据保留时长设置调整

kafka队列日志保存时长设置,能有效的控制kafka所需使用的磁盘空间大小。在刚使用的sentry时,我就因为使用默认的配置,为调节导致kafka服务占用磁盘达到了500G左右,导致服务器空间不足。因此我就此问题找到了调整kafka队列日志保存时间,有效控制磁盘使用,kafka服务所需磁盘空间在20G左右.

以下内容为调整的方式

复制代码
# 进入kafka容器
docker exec -it sentry-self-hosted-kafka-1 /bin/bash

#查看topics
kafka-topics --list --zookeeper zookeeper:2181

# 安装vim
apt-get update
apt-get install vim

# 安装vim 时可能因为资源问题不能正常安装
# 可以将资源增加阿里云资源 
cat >> /etc/apt/sources.list
# 按enter键输入如下内容
deb https://mirrors.aliyun.com/debian-archive/debian/ jessie main non-free contrib
deb-src https://mirrors.aliyun.com/debian-archive/debian/ jessie main non-free contrib
deb http://mirrors.aliyun.com/debian-security/ squeeze/updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian-security/ squeeze/updates main non-free contrib
# 按ctrl+d 保存内容


#修改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

2.调整完成后停掉服务,重新启动

复制代码
# 停止服务
docker-compose down 
# 启动服务
docker-compose up -d
相关推荐
Geek-Chow17 小时前
04 Touring the Stack: One Checkout, Traced Through Every Container
devops
增量星球2 天前
《持续交付2.0系列一》从技术交付到业务引领
java·docker·容器·devops
宋均浩3 天前
# Docker Compose 本地环境标准化:5 个配置避免"我机器上能跑"
devops
李燚5 天前
Eino devops 调试系统源码:GraphCompileCallback 怎么工作(第50篇-E36)
数据库·golang·agent·devops·graphql·aiagent·eino
leoZ2315 天前
Skill 技能系统完全指南(四):实战 Skill——DevOps 部署
运维·devops
沐风___6 天前
iOS 崩溃收集实战:从「只看到次数、看不到原因」到 Sentry 完整集成
ios·sentry
leeyi7 天前
调试 Agent 的 3 个姿势:日志、断点、可视化(第49篇-E35)
aigc·agent·devops
南宫乘风9 天前
我们用企微机器人 + Claude 搭了个内部 DevOps 助手,替代了 60% 的日常杂活
机器人·claude·devops
love530love9 天前
GPT + Codex CLI + CodexPro 三位一体:AI 编程协作工作流
人工智能·windows·gpt·chatgpt·devops·mcp
姚青&10 天前
持续交付与 DevOps 体系
运维·devops