Docker

Docker - 如何Setup企业级Sentry系统

2021-05-22  本文已影响0人  红薯爱帅

1. 概述

Sentry's application monitoring platform helps every developer diagnose, fix, and optimize the performance of their code.
Sentry is a service that helps you monitor and fix crashes in realtime. The server is in Python, but it contains a full API for sending events from any language, in any application.

Sentry提供免费和收费的公网服务,也支持内网部署,各有利弊。

公网服务,可以在Sentry官网注册账号,创建Project后即可使用。

sentry with docker

本文重点介绍内网部署流程和测试。

Sentry的内网部署,大致有两种方式:

2. 低版本部署

2.1. Start a Redis container

$ docker run -d --name sentry-redis redis

2.2. Start a Postgres container

$ docker run -d --name sentry-postgres -e POSTGRES_PASSWORD=secret -e POSTGRES_USER=sentry postgres

2.3. Generate a new secret key to be shared by all sentry containers. This value will then be used as the SENTRY_SECRET_KEY environment variable.

$ docker run --rm sentry config generate-secret-key

2.4. If this is a new database, you'll need to run upgrade

$ docker run -it --rm -e SENTRY_SECRET_KEY='<secret-key>' --link sentry-postgres:postgres --link sentry-redis:redis sentry upgrade

Note: the -it is important as the initial upgrade will prompt to create an initial user and will fail without it

2.5. Now start up Sentry server

$ docker run -d --name my-sentry -e SENTRY_SECRET_KEY='<secret-key>' --link sentry-redis:redis --link sentry-postgres:postgres sentry

2.6. The default config needs a celery beat and celery workers, start as many workers as you need (each with a unique name)

$ docker run -d --name sentry-cron -e SENTRY_SECRET_KEY='<secret-key>' --link sentry-postgres:postgres --link sentry-redis:redis sentry run cron
$ docker run -d --name sentry-worker-1 -e SENTRY_SECRET_KEY='<secret-key>' --link sentry-postgres:postgres --link sentry-redis:redis sentry run worker

3. 最新版本部署

Sentry官方支持企业内网部署:
https://github.com/getsentry/onpremise

3.1. 准备工作

3.2. 部署流程

$ git clone https://github.com/getsentry/self-hosted.git
$ cd self-hosted
$ ./install.sh
$ docker-compose up -d

如果需要配置geolocation,可以参考:https://develop.sentry.dev/self-hosted/geolocation/
单独创建用户:docker-compose run --rm web createuser

3.3. 可能遇到的问题

3.3.1. Email配置

修改文件:sentry/config.yml

# mail.backend: 'smtp'  # Use dummy if you want to disable email entirely
mail.host: 'smtp.exmail.qq.com'
mail.port: 465
mail.username: 'noreply@aawwee.cn'
mail.password: 'xxxeeesss'
mail.use-tls: false
mail.use-ssl: true

# NOTE: The following 2 configs (mail.from and mail.list-namespace) are set
#       through SENTRY_MAIL_HOST in sentry.conf.py so remove those first if
#       you want your values in this file to be effective!


# The email address to send on behalf of
mail.from: 'noreply@aawwee.cn'

3.3.2. proxy问题

如果公司是通过http_proxy访问公网,那么,在./install.sh时,因为要build docker image,所以需要修改~/.docker/config.json,增加proxies设置如下

{
 "proxies":
 {
   "default":
   {
     "httpProxy": "http://127.0.0.1:3001",
     "httpsProxy": "http://127.0.0.1:3001",
     "noProxy": "*.test.example.com,.example2.com,127.0.0.0/8"
   }
 }
}

在启动sentry服务时,需要注释掉上述proxies设置,避免出现运行时域名解析或IP路由异常。

4. 测试

4.1. Python

$ http_proxy='' python test.py
# py38
import logging
import sentry_sdk
from sentry_sdk.integrations.logging import LoggingIntegration
from sentry_sdk import capture_message


sentry_logging = LoggingIntegration(
    level=logging.INFO,       
    event_level=logging.ERROR 
)

sentry_sdk.init(
    "http://388ceb74a20847028c81dfc616843556@10.211.28.93:9000/1",
    traces_sample_rate=1.0,
    integrations=[sentry_logging],
    debug=True,
)

capture_message('Something went wrong!')
division_by_zero = 1 / 0

4.2. nodejs

$ http_proxy='' node server/test
const Sentry = require("@sentry/node")

Sentry.init({
  dsn: "http://388ceb74a20847028c81dfc616843556@10.211.28.93:9000/1",
  appName: 'Sentry Test',
  tracesSampleRate: 1.0,
  debug: true,
});

Sentry.captureMessage('Hello, sentry world!')
上一篇 下一篇

猜你喜欢

热点阅读