从零开始:使用Docker Compose部署Sentry 9.1.2的完整流程

张开发
2026/6/2 5:24:29 15 分钟阅读
从零开始:使用Docker Compose部署Sentry 9.1.2的完整流程
从零开始使用Docker Compose部署Sentry 9.1.2的完整流程在当今快速迭代的软件开发周期中错误监控系统已成为保障应用稳定性的关键基础设施。Sentry作为一款开源的实时错误追踪工具能够帮助开发团队快速定位和修复代码中的问题。本文将详细介绍如何通过Docker Compose部署Sentry 9.1.2版本特别针对初次接触Sentry的开发者提供从环境准备到成功启动的全流程指南。1. 环境准备与基础配置在开始部署Sentry之前需要确保系统满足以下基本要求Docker版本18.06.0或更高Docker Compose版本1.22.0或更高系统资源至少4GB内存20GB磁盘空间操作系统推荐使用Ubuntu 18.04 LTS或更高版本首先更新系统软件包并安装必要的依赖sudo apt-get update sudo apt-get install -y curl git make验证Docker和Docker Compose是否已正确安装docker --version docker-compose --version如果尚未安装可以通过以下命令安装Dockercurl -fsSL https://get.docker.com | sh sudo usermod -aG docker $USER安装Docker Composesudo curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose sudo chmod x /usr/local/bin/docker-compose提示安装完成后需要重新登录终端或执行newgrp docker命令使权限变更生效。2. 获取Sentry 9.1.2源码并配置Sentry官方提供了onpremise仓库用于自托管部署。我们需要获取特定版本的源码wget https://github.com/getsentry/onpremise/archive/refs/tags/9.1.2.tar.gz tar -xzvf 9.1.2.tar.gz cd onpremise-9.1.2解压后目录结构应包含以下关键文件. ├── docker-compose.yml ├── sentry.conf.py ├── config.yml └── install.sh在运行安装脚本前需要先配置PostgreSQL数据库。编辑docker-compose.yml文件找到PostgreSQL服务部分postgres: image: postgres:9.5 environment: POSTGRES_PASSWORD: sentry POSTGRES_USER: sentry volumes: - sentry-postgres:/var/lib/postgresql/data修改为以下配置以确保密码正确设置postgres: image: postgres:9.5 environment: POSTGRES_PASSWORD: sentry POSTGRES_USER: sentry POSTGRES_DB: sentry volumes: - sentry-postgres:/var/lib/postgresql/data同时在sentry.conf.py中确保数据库配置匹配DATABASES { default: { ENGINE: django.db.backends.postgresql_psycopg2, NAME: sentry, USER: sentry, PASSWORD: sentry, HOST: postgres, PORT: 5432, } }3. 解决常见安装问题在部署过程中可能会遇到几个典型问题以下是解决方案问题1PostgreSQL连接失败错误信息django.db.utils.OperationalError: could not translate host name postgres to address解决方案确认PostgreSQL容器已启动并运行docker-compose up -d postgres检查PostgreSQL日志docker-compose logs postgres验证网络连接docker-compose exec sentry ping postgres问题2Redis连接超时错误信息redis.exceptions.ConnectionError: Error 111 connecting to redis:6379. Connection refused.解决方案确保Redis服务已启动docker-compose up -d redis检查Redis配置redis: image: redis:3.2-alpine volumes: - sentry-redis:/data问题3Sentry Web服务无法启动错误信息sentry.exceptions.InvalidConfiguration: You must configure Redis cache解决方案在config.yml中添加Redis缓存配置redis.clusters: default: hosts: 0: host: redis port: 6379重启所有服务docker-compose down docker-compose up -d4. 完整安装与初始化流程完成上述准备工作后可以开始正式安装Sentry启动基础服务docker-compose up -d postgres redis memcached运行安装脚本./install.sh安装过程中会提示创建管理员账号设置初始组织名称配置邮件服务器信息启动所有服务docker-compose up -d验证服务状态docker-compose ps正常输出应显示所有容器状态为UpName Command State Ports ------------------------------------------------------------------- memcached docker-entrypoint.sh memcached Up 11211/tcp postgres docker-entrypoint.sh postgres Up 5432/tcp redis docker-entrypoint.sh redis ... Up 6379/tcp sentry /entrypoint.sh run web Up 9000/tcp smtp mailhog Up 1025/tcp, 8025/tcp访问Sentry Web界面 打开浏览器访问http://localhost:9000使用安装时创建的管理员账号登录。5. 生产环境优化建议对于生产环境部署建议进行以下优化配置性能调优调整Docker资源限制services: sentry: deploy: resources: limits: cpus: 2 memory: 4G配置工作进程数量services: sentry: environment: - SENTRY_WORKERS4安全加固启用HTTPSservices: nginx: image: nginx:alpine ports: - 443:443 volumes: - ./nginx.conf:/etc/nginx/nginx.conf - /path/to/ssl/certs:/etc/nginx/ssl定期备份策略# PostgreSQL备份 docker-compose exec postgres pg_dump -U sentry sentry sentry_backup.sql # Redis备份 docker-compose exec redis redis-cli save监控与维护设置健康检查services: sentry: healthcheck: test: [CMD, curl, -f, http://localhost:9000/_health] interval: 30s timeout: 10s retries: 3日志轮转配置services: sentry: logging: driver: json-file options: max-size: 10m max-file: 3在实际部署中根据团队规模和项目需求可能需要进一步调整资源配置和架构设计。例如对于大型团队可以考虑将PostgreSQL和Redis分离到专用服务器或者使用Kubernetes进行容器编排管理。

更多文章