官方安装教程
Sentry安装 Python环境
依赖
- Ubuntu16.04
- Python 2.7.12
- pip 8.1.1 +
- PostgreSQL 9.4 (docker镜像)
- Redis 3.2 (docker镜像)
- python-setuptools, python-dev, libxslt1-dev, gcc, libffi-dev, libjpeg-dev, libxml2-dev, libxslt-dev, libyaml-dev, libpq-dev
创建环境
环境搭建请使用root用户, 避免出现文件读写问题
-
安装Python virtualenv包
pip install -U virtualenv
-
选择一个目录创建Python virtualenv环境
virtualenv /home/sentry/env
-
激活virtualevn环境
source /home/sentry/env/bin/activate
安装Sentry
pip install -U sentry
配置Sentry
-
初始化配置
sentry init /home/sentry/init_s
当语句执行完毕后可在/home/sentry/init_s文件夹下看到
config.yml
和sentry.conf.py
两个文件 配置数据库
# This file is just Python, with a touch of Django which means
# you can inherit and tweak settings to your hearts content.
from sentry.conf.server import *
import os.path
CONF_ROOT = os.path.dirname(__file__)
DATABASES = {
'default': {
'ENGINE': 'sentry.db.postgres',
#数据库名称,默认sentry
'NAME': 'sentry',
#数据库登录用户
'USER': 'postgres',
#数据库连接密码
'PASSWORD': 'password',
#数据库ip
'HOST': '192.168.50.71',
#数据库端口, postgres默认5432
'PORT': '5432',
'AUTOCOMMIT': True,
'ATOMIC_REQUESTS': False,
}
}
- 配置redis
#sentry.conf.py文件中
#########
# Queue #
#########
# See https://docs.sentry.io/on-premise/server/queue/ for more
# information on configuring your queue broker and workers. Sentry relies
# on a Python framework called Celery to manage queues.
BROKER_URL = 'redis://{IP}:6379'
#config.yml文件中
# The ``redis.clusters`` setting is used, unsurprisingly, to configure Redis
# clusters. These clusters can be then referred to by name when configuring
# backends such as the cache, digests, or TSDB backend.
#
# Two types of clusters are currently supported:
#
# rb.Cluster
# A redis blaster cluster is the traditional cluster used by most services
# within sentry. This is the default type cluster type.
#
# rediscluster.StrictRedisCluster
# An official Redis Cluster can be configured by marking the named group with
# the ``is_redis_cluster: True`` flag. In future versions of Sentry more
# services will require this type of cluster.
#
redis.clusters:
default:
hosts:
0:
host: {IP}
port: 6379
-
配置邮箱
可参见官网连接
若邮件使用SSL, 则需要 SMTP SSL email backend for Djangopip install django-smtp-ssl
若邮件中按钮等链接不能正确跳转, 需要在config.yml文件中配置url前缀
system.url-prefix: 'https://sentry.example.com'
运行数据库迁移
-
执行该语句将会在配置好的postgres的sentry数据库中创建出Sentry需要的数据表。这一步比较耗内存(2G左右),我就是在执行这一步的时候出了很多意外,比如进程被 killed,报很多异常等等。
SENTRY_CONF=/home/sentry/init_s sentry upgrade
创建超级管理员
-
执行数据库迁移完成后会提示创建用户, 若未提示或选择跳过; 可通过该命令进行设置。
SENTRY_CONF=/home/sentry/init_s sentry createuser
此步骤若出现
IndexError: list index out of range
报错, 可参考#7015将sentry.conf.py
文件中的SENTRY_SINGLE_ORGANIZATION设置为False
开启web页面服务
SENTRY_CONF=/home/sentry/init_s sentry run worker
开启后台workers服务
SENTRY_CONF=/home/sentry/init_s sentry run worker
开启定时任务服务
SENTRY_CONF=/home/sentry/init_s sentry run worker
将Sentry当做服务启动
- 使用
systemd
实现服务自启动
在Ubuntu上, 在/etc/systemd/system
目录下创建sentry-web.service
,sentry-worker.service
,sentry-cron.service
三个文件
sentry-web.service
[Unit]
Description=Sentry Main Service
After=network.target
Requires=sentry-worker.service
Requires=sentry-cron.service
[Service]
Type=simple
User=执行用户名
Group=执行用户所在分组
WorkingDirectory=/home/sentry/env
Environment=SENTRY_CONF=/home/sentry/init_s
ExecStart=/home/sentry/env/bin/sentry run web
[Install]
WantedBy=multi-user.target
sentry-worker.service
[Unit]
Description=Sentry Background Worker
After=network.target
[Service]
Type=simple
User=执行用户名
Group=执行用户所在分组
WorkingDirectory=/home/sentry/env
Environment=SENTRY_CONF=/home/sentry/init_s
ExecStart=/home/sentry/env/bin/sentry run worker
[Install]
WantedBy=multi-user.target
sentry-cron.service
[Unit]
Description=Sentry Beat Service
After=network.target
[Service]
Type=simple
User=执行用户
Group=执行用户所在分组
WorkingDirectory=/home/sentry/env
Environment=SENTRY_CONF=/home/sentry/init_s
ExecStart=/home/sentry/env/bin/sentry run cron
[Install]
WantedBy=multi-user.target
-
使用systemctl命令设置应用自启动
systemctl enable sentry-web.service sysetmctl enable sentry-worker.service systemctl enable sentry-cron.service
-
systemctl其他命令
systemctl status service_name #查看服务状态 systemctl start service_name #启动服务 systemctl stop service_name #停止服务 systemctl --help #查看systemctl命令使用文档
PS
若使用root运行worker会出现提示:
If you really want to continue then you have to set the C_FORCE_ROOT environment variable (but please think about this before you do).
此时需要加入环境变量C_FORCE_ROOT
SENTRY_CONF=/home/sentry/init_s C_FORCE_ROOT=a sentry run worker