Sentry23.12版本私有化部署的内存和存储优化

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

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

1.磁盘空间占用大

2.内存出现爆满

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

一、安装之前

1.配置日志存储时长

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

# 将此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
  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值