前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Installing sentry 9.0.0 with postgresql in Centos7

Installing sentry 9.0.0 with postgresql in Centos7

作者头像
阿dai学长
发布2019-04-03 10:01:12
1.2K0
发布2019-04-03 10:01:12
举报
文章被收录于专栏:阿dai_linux

简介

Sentry是一个开源错误跟踪工具,可帮助您实时监控和修复bug。支持 Python、OC、Java、Go、Node、Django、RoR 等主流编程语言和框架,还提供了 GitHub、Slack、Trello 等常见开发工具的集成。

用户及权限管理

用户管理

Sentry以组织的形式对用户进行管理,为每个用户建立一个独立的账户,每个用户可以加入多个不同的组织(类似于SSO)。Sentry官方对于用户根据权限的不同划分为以下5种角色:

  • Owner:拥有者
  • Manager:超级管理员
  • Admin:普通管理员
  • Member:普通用户
  • Billing:访客
权限管理

不同用户的权限对应如下表格:

行动

Billing

Member

Admin

Manager

Owner

可以查看/编辑结算信息和订阅详细信息

X

X

可以查看和处理问题,例如分配/解析/等。

X

X

X

X

可以加入和离开团队。

X

X

X

X

可以更改项目设置

X

X

X

可以添加/删除项目

X

X

X

可以编辑全局集成

X

X

可以添加/删除/更改成员

X

X

可以添加/删除团队

X

X

可以添加存储库

X

X

可以更改组织设置

X

X

可以删除组织

X

访问控制

  • 对组织的访问由角色决定,角色的范围是整个组织。
  • 对项目的访问仅限于拥有该项目的团队。但是,任何会员,管理员,经理或所有者都可以加入团队。
  • 可以通过管理员或所有者的邀请来访问团队,从而控制对团队的访问。

事件及通知管理

安装

sentry官方提供了两种方式来安装sentry:docker、python。在此使用传统的python环境进行安装。

环境依赖

  • 基于Unix的操作系统;
  • python 2.7+
  • pip 8.1+
  • 基础包: python-setuptoolspython-devellibxslt1-develgcclibffi-devellibjpeg-devellibxml2-devellibxslt-devellibyaml-devellibpq-devel (yum安装)
系统环境

环境

版本

系统

centos 7.4

python

2.7.5

pip

18.1

部署位置

192.168.228.129

代码语言:javascript
复制
新版本sentry不再支持mysql, 官方给的解释:
"Due to numerous issues over the years and recent discoveries that nearly all schema migration was broken in MySQL (due to some behavior in our migration tool), we've made the decision to no longer support MySQL. It is possible to bring the schema up to date on a MySQL machine, but Sentry's automated migrations will likely not work and require DBA assistance. Postgres is now the only supported production database."

postgresql

使用yum安装postgresql
  • 安装postgresql-10,rpm包 下载地址 # 配置rpm源 $ rpm -Uvh https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm # 安装 $ yum install -y postgresql10-server postgresql10 # 初始化数据库 $ /usr/pgsql-10/bin/postgresql-10-setup initdb
配置

Note: postgresql的配置文件在 /var/lib/pgsql/10/data/

  • 编辑 /var/lib/pgsql/10/data/pg_hba.conf 82行 ,允许本地连接: host all all 127.0.0.1/32 trust
  • 编辑 /var/lib/pgsql/10/data/postgresql.conf ,更改监听ip: listen_addresses = '127.0.0.1'
  • 启动postgresql: $ systemctl start postgresql-10
  • 检测启动状态(默认监听5432端口): $ netstat -lntp |grep post tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 25242/postmaster tcp6 0 0 ::1:5432 :::* LISTEN 25242/postmaster
  • 更改数据库初始密码: $ su - postgres # 切换到数据库用户(安装postgresql时默认创建) $ psql # 登录数据库 # 为postgres用户设置密码 postgres=# \password postgres 123456 # 退出数据库 postgres=# \q
  • 参考:

安装sentry

部署系统基础环境
代码语言:javascript
复制
# 安装基础包
$ yum install -y python-setuptools python-devel libxslt1-devel gcc libffi-devel libjpeg-devel libxml2-devel libxslt-devel libyaml-devel libpq-devel
创建python虚拟环境
代码语言:javascript
复制
# 安装virtualenv
$ pip install -U virtualenv

$ su - chunyu

# 创建虚拟环境部署位置:/home/chunyu
$ virtualenv /home/chunyu/workspace/ENV_sentry/

# 进入虚拟环境
$ source /home/chunyu/workspace/ENV_sentry/bin/activate
$ (sentry) [root@host2 sentry]#   ## (sentry)标记表示进入了虚拟环境
安装sentry

在虚拟环境执行:

代码语言:javascript
复制
$ pip install -U sentry

该过程安装依赖比较多,遇到问题如下:

  • 问题1:
    • 报错: gcc: error trying to exec 'cc1plus': execvp: No such file or directory
    • 解决办法:系统缺少gcc-c++包,退出虚拟环境安装 $ yum install -y gcc-c++
  • 问题2:
    • 报错: redis-py-cluster 1.3.5 has requirement redis>=2.10.6, but you'll have redis 2.10.5 which is incompatible.
    • 解决办法:sentry 9.0.0依赖redis 2.10.5,redis-py-cluster 1.3.5依赖redis>=2.10.6,降级redis-py-cluster $ pip install redis-py-cluster==1.3.4
检查安装结果
代码语言:javascript
复制
# 执行sentry命令,输出结果如下:
$ sentry
Usage: sentry [OPTIONS] COMMAND [ARGS]...

  Sentry is cross-platform crash reporting built with love.

  The configuration file is looked up in the `~/.sentry` config directory but this can be
  overridden with the `SENTRY_CONF` environment variable or be explicitly provided through the
  `--config` parameter.
... ...

配置sentry

初始化配置文件
代码语言:javascript
复制
$ sentry init /home/chunyu/workspace/sentry
# 从8.0版本后初始化会生成两个文件,如下,config.yml会在后续的版本强制取代sentry.conf.py
$ ls /home/chunyu/workspace/sentry/  
config.yml  sentry.conf.py
更新sentry配置文件位置
代码语言:javascript
复制
# 为sentry指定配置文件路径
$ vim /home/chunyu/workspace/ENV_sentry/lib/python2.7/site-packages/sentry/runner/settings.py
DEFAULT_SETTINGS_CONF = '/home/chunyu/workspace/sentry/config.yml'
DEFAULT_SETTINGS_OVERRIDE = '/home/chunyu/workspace/sentry/sentry.conf.py'
数据库配置
代码语言:javascript
复制
# ~/.sentry/sentry.conf.py
DATABASES = {
    'default': {
        'ENGINE': 'sentry.db.postgres',
        'NAME': 'sentry',
        'USER': 'sentry',
        'PASSWORD': '123456',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}
部署Redis
代码语言:javascript
复制
$ yum install -y redis

$ vim /etc/redis.conf
bind 127.0.0.1
port 6379
requirepass 123456

$ systemctl start redis
sentry配置redis(缓存/缓冲)
  • sentry使用config.yml配置: redis.clusters: default: hosts: 0: host: 127.0.0.1 port: 6379 password: "123456" db: 0
邮件配置
  • confi.yml: mail.backend: 'smtp' # Use dummy if you want to disable email entirely mail.host: 'localhost' mail.port: 25 mail.username: '' mail.password: '' mail.use-tls: false mail.from: 'sentry@localhost'
  • 禁用mail服务: mail.backend: 'dummy'
初始化数据库
代码语言:javascript
复制
$ source /home/chunyu/workspace/ENV_sentry/bin/activite

# 创建sentry数据库
$ createdb -E utf-8 sentry

# 初始化数据结构
$ sentry upgrade

# 创建数据库管理员用户
$ sentry createuser
chunyu

# 测试:登录数据库
$ psql -Uchunyu -h127.0.0.1 -p5432 -dsentry -W
用户 chunyu 的口令:123
psql (10.6)
输入 "help" 来获取帮助信息.
sentry=# 
(登录成功)
配置nginx反向代理
代码语言:javascript
复制
server {
    listen        80;
    server_name sentry.chunyu.club;

    location / {
        proxy_pass         http://192.168.228.129:9000;
        proxy_redirect     off;

        proxy_set_header   Host              $host;
        proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
    }

}

参考https://docs.sentry.io/server/nginx/

加入supervisord管理

sentry运行三个进程,sentry-web、sentry-worker、sentry-cron,将其加入supervisord更便于管理:

  • 安装supervisor: (sentry_env) $ pip install supervisor
  • sentry-web:为sentry提供web管理界面 SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') # 支持SSL协议 SESSION_COOKIE_SECURE = True CSRF_COOKIE_SECURE = True SENTRY_WEB_HOST = '0.0.0.0' SENTRY_WEB_PORT = 9000 SENTRY_WEB_OPTIONS = { 'workers': 3, # the number of web workers #'protocol': 'uwsgi', # Enable uwsgi protocol instead of http }
  • sentry-worker:sentry的后台进程;
  • sentry-cron:sentry定时任务

supervisord配置文件:

代码语言:javascript
复制
[unix_http_server]
file=/home/chunyu/workspace/sentry/supervisor.sock

[supervisord]
logfile=/home/chunyu/workspace/sentry/logs/supervisord.log ; main log file; default $CWD/supervisord.log
logfile_maxbytes=50MB        ; max main logfile bytes b4 rotation; default 50MB
logfile_backups=10           ; # of main logfile backups; 0 means none, default 10
loglevel=info                ; log level; default info; others: debug,warn,trace
pidfile=/home/chunyu/workspace/sentry/supervisord.pid ; supervisord pidfile; default supervisord.pid
nodaemon=false               ; start in foreground if true; default false
minfds=1024                  ; min. avail startup file descriptors; default 1024
minprocs=200                 ; min. avail process descriptors;default 200
user=chunyu

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///home/chunyu/workspace/sentry/supervisor.sock ; use a unix:// URL  for a unix socket
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/home/chunyu/workspace/sentry/logs/sentry.slog
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=3

[program:sentry-web]
directory=/home/chunyu/workspace/sentry/
environment=SENTRY_CONF="/etc/sentry"
command=/home/chunyu/workspace/ENV_sentry/bin/sentry run web
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/home/chunyu/workspace/sentry/logs/sentry-web.slog

[program:sentry-worker]
directory=/home/chunyu/workspace/sentry/
environment=SENTRY_CONF="/etc/sentry"
command=/home/chunyu/workspace/ENV_sentry/bin/sentry run worker
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/home/chunyu/workspace/sentry/logs/sentry-worker.slog

[program:sentry-cron]
directory=/home/chunyu/workspace/sentry/
environment=SENTRY_CONF="/etc/sentry"
command=/home/chunyu/workspace/ENV_sentry/bin/sentry run cron
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/home/chunyu/workspace/sentry/logs/sentry-cron.slog
  • 启动脚本; #!/bin/sh /home/chunyu/workspace/ENV_sentry/bin/supervisord -c /home/chunyu/workspace/sentry/supervisord.conf
  • 停止脚本: #!/bin/sh /home/chunyu/workspace/ENV_sentry/bin/supervisorctl -c /home/chunyu/workspace/sentry/supervisord.conf shutdown
  • 进程管理: #!/bin/sh /home/chunyu/workspace/ENV_sentry/bin/supervisorctl -c /home/chunyu/workspace/sentry/supervisord.conf
空间回收

定期清理历史数据,释放存储资源。

代码语言:javascript
复制
# 每天凌晨3点,删除1周前的sentry
0 3 * * * /home/chunyu/workspace/ENV_sentry/bin/sentry cleanup --days=7

参考:https://docs.sentry.io/server/cli/cleanup/

参考

插件管理

LDAP集成

ldap集成依赖于第三方提供的插件,具体配置方法参考链接:https://github.com/Banno/getsentry-ldap-auth

官方插件管理

插件管理:https://docs.sentry.io/server/plugins/

注意: 所有的插件都是以最新版本的sentry进行的测试,不保证对旧版本的sentry完全兼容,部署插件的时候注意调研测试。

web配置示例

项目管理

  • 创建项目组:
201811021541139597109.png
201811021541139597109.png
  • 管理项目组:创建项目、项目组权限管理
    • 进入项目组管理界面:
    20181102154113969269671.png
    20181102154113969269671.png
    • 功能介绍:
    20181102154113985782152.png
    20181102154113985782152.png
  • 项目管理:
20181102154114003617008.png
20181102154114003617008.png
  • 使用(sentry客户端集成): 项目创建完成后,赋予项目负责人管理员权限,根据 sentry用户端集成 文档由开发将API_Keys集成到项目中即可采集项目日志信息。

通知管理

公司项目很多,并不是每个开发人员都负责所有的项目,默认情况下是接收所有项目的通知,如果想取消某项目的通知,操作如下:

  • 账户管理:
20181107154158499354774.png
20181107154158499354774.png
  • 通知管理:
20181107154158504123310.png
20181107154158504123310.png
  • 项目筛选:
20181107154158508977046.png
20181107154158508977046.png

sentry监控配置

通过mysql监控sentry

监控脚本 下载

代码语言:javascript
复制
# sentry机器
* * * * * root /usr/bin/python /root/scripts/sentry_monitor.py

通过nginx日志监控sentry

因为sentry使用nginx做的代理,所有请求都会通过nginx转发,所以可以通过nginx日志来对sentry数量进行统计,每个项目对应的API接口是唯一的,所以通过API接口进行过滤,将数据上报到Open-falcon,配置告警策略。接口对应如下:

项目名称

API接口号

medweb

3

op

24

事件采集脚本如下:

代码语言:javascript
复制
#!/bin/bash
#sentry数量统计

apis="3 24"
for api in $apis;do
  ts=`date +%s`;
  t=`LC_ALL=en_US.UTF-8 date '+%d/%b/%Y:%H:%M' -d "-1 minute"`  # 每分钟采集一次日志
  if [ $api -eq 3 ];then
    project=medweb_online
  elif [ $api -eq 24 ];then
    project=op
  fi
  valus=`tail -1000000 /usr/local/nginx/logs/access.log |egrep 'sentry.chunyu.me' |egrep $t |egrep 'POST'|egrep "/api/$api/" |wc -l`
  curl -X POST -d "[{\"metric\": \"sentry\", \"endpoint\": \"sentry\", \"timestamp\": $ts,\"step\": 60,\"value\": $valus,\"type\":\"sentry\",\"counterType\": \"GAUGE\",\"tags\": \"project=$project\"}]" http://127.0.0.1:1988/v1/push

(adsbygoogle = window.adsbygoogle || []).push({});

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018/11/02 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 简介
    • 用户及权限管理
      • 用户管理
      • 权限管理
    • 访问控制
      • 事件及通知管理
      • 安装
        • 环境依赖
          • 系统环境
        • postgresql
          • 使用yum安装postgresql
          • 配置
        • 安装sentry
          • 部署系统基础环境
          • 创建python虚拟环境
          • 安装sentry
        • 配置sentry
          • 初始化配置文件
          • 数据库配置
          • 部署Redis
          • 邮件配置
          • 初始化数据库
          • 配置nginx反向代理
          • 加入supervisord管理
          • 空间回收
          • 参考
      • 插件管理
        • LDAP集成
          • 官方插件管理
          • web配置示例
            • 项目管理
              • 通知管理
              • sentry监控配置
                • 通过mysql监控sentry
                  • 通过nginx日志监控sentry
                  相关产品与服务
                  云数据库 MySQL
                  腾讯云数据库 MySQL(TencentDB for MySQL)为用户提供安全可靠,性能卓越、易于维护的企业级云数据库服务。其具备6大企业级特性,包括企业级定制内核、企业级高可用、企业级高可靠、企业级安全、企业级扩展以及企业级智能运维。通过使用腾讯云数据库 MySQL,可实现分钟级别的数据库部署、弹性扩展以及全自动化的运维管理,不仅经济实惠,而且稳定可靠,易于运维。
                  领券
                  问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档