Sentry 8 错误跟踪服务搭建

简介

sentry是一个人性化收集&定位&定格程序错误的工具。说白了就是在网页上就能看到你的错误栈信息,和各种当时的环境变量。比你大眼瞪小眼看那些日志强多了。有多强? 谁用谁知道.
支持框架超多, 主流语言基本上都是支持的

英文官方安装教程

点击Installation with Python查看官方python教程

但是官方不建议使用python直接安装了, 而是建议使用docker.

安装

言归正传开始安装, 本教程安装的sentry为version==8.19, 系统环境 ubuntu 16.04 (其他版本应该无妨)

  1. 安装 postgreSql

    $ sudo aptitude install postgresql
    
  2. 安装redis

    $ sudo aptitude install redis-server
    
  3. [可选, 推荐] pip安装virtualenvvirutalenvwrapper然后创建虚拟环境sentry

    $ sudo pip install virtualenv
    $ sudo pip install virutalenvwrapper
    $ vim ~/.bashrc
    

    .bashrc末尾追加:

    export WORKON_HOME=$HOME/.virtualenvs  
    source /usr/local/bin/virtualenvwrapper.sh
    

    紧接着

    $ source ~/.bashrc
    
  1. 安装sentry包(到目前最新版本是8.19.0)

    $ mkvirtualenv sentry
    $ workon sentry
    $ pip install sentry
    
  2. 创建配置

    $ sudo `which sentry` init /etc/sentry
    
  3. 修改postgresql密码

    $ sudo -u postgres psql
    postgres=# \password
    

    然后自己指定密码

  4. 修改数据库配置

    $ vim /etc/sentry/sentry.conf.py
    

    修改密码用户名等

  5. 修改其他配置

    $ vim /etc/sentry/config.yml
    
    • 如果无需邮箱则修改 mail.backend: ‘dummy’

    • 下面以qq企业邮箱为例

      qq邮箱需要用到ssl, sentry是基于django1.6, django1.6原生不支持ssl, 从1.7开始支持, 所以先安装django_smtp_ssl以支持ssl

      pip install django_smtp_ssl
      

      修改 /etc/sentry/config.yml

      mail.backend: 'django_smtp_ssl.SSLEmailBackend'  # Use dummy if you want to disable email entirely
      mail.host: 'smtp.exmail.qq.com'
      mail.port: 465
      mail.username: 'username@yourdomain.com'
      mail.password: 'yourpassword'
      mail.use-tls: false
      # The email address to send on behalf of
      mail.from: 'username@yourdomain.com'
      mail.list-namespace: 'yourdomain.com'
      
  1. 创建sentry 数据库

    $ sudo -u postgres createdb sentry
    
  2. sentry 更新数据库

    $ SENTRY_CONF=/etc/sentry `which sentry` upgrade
    

    (如果有错误, 见下一章错误处理)

  3. sentry 创建用户, 如果上一步(upgrade)里边创建了超级用户这一步可以省略

    $ SENTRY_CONF=/etc/sentry `which sentry` createuser
    
  4. 启动服务

    注意: 这里启动worker不能使用root, supervisor需要显式指定用户

    两种方式任选其一, 推荐supervisor, 可以持久化服务

    • 手动启动服务

      • 启动sentry web服务

        $ SENTRY_CONF=/etc/sentry `which sentry` run web
        
      • 启动sentry worker服务

        $ SENTRY_CONF=/etc/sentry `which sentry` run worker
        
      • 启动sentry cron服务

        $ SENTRY_CONF=/etc/sentry `which sentry` run cron
        
    • supervisor启动服务, 需要配置supervisor, 然后创建配置文件如下

      [program:sentry-web]
      directory=/tmp
      environment=SENTRY_CONF="/etc/sentry"
      command=<sentry_path>/sentry start
      autostart=true
      autorestart=true
      redirect_stderr=true
      stdout_logfile=syslog
      stderr_logfile=syslog
      user=<not root>
      
      [program:sentry-worker]
      directory=/tmp
      environment=SENTRY_CONF="/etc/sentry"
      command=<sentry_path>/sentry run worker
      autostart=true
      autorestart=true
      redirect_stderr=true
      stdout_logfile=syslog
      stderr_logfile=syslog
      user=<not root>
      
      [program:sentry-cron]
      directory=/tmp
      environment=SENTRY_CONF="/etc/sentry"
      command=<sentry_path>/sentry run cron
      autostart=true
      autorestart=true
      redirect_stderr=true
      stdout_logfile=syslog
      stderr_logfile=syslog
      user=<not root>
      

错误处理

  • 错误1: 如果在sentry update发生错误:

    AttributeError: ‘NoneType’ object has no attribute ‘connection_pool’

    则是 redis 包2.10.6的 bug, 使用2.10.5解决

    pip install redis==2.10.5
    
  • 错误2: Pillow安装错误, 网上有各种教程自行搜索

  • 错误3:

    sentry@sentry:/var$ sudo -u postgres psql -p 5432 -h localhost
    psql: could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?
    could not connect to server: Cannot assign requested address
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
    sentry@sentry:/var$ sudo -u postgres psql                     
    psql: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
    

    解决:

    dpkg-reconfigure locales
    然后选择合适你的本地语言
    
    pg_createcluster 9.5 main --start
    (9.5 is my version of postgresql)
    
    /etc/init.d/postgresql start
    
    然后就运行成功了
    sudo su - postgres
    psql
    

使用

打开sentry web界面: localhost:9000

使用之前设置的superuser登录
手动设置邮箱之后便可以尽情使用了
登录之后创建项目, 然后选定自己要跟踪的项目的类型(我的是django), 里边会有对应的对接教程, 很简单直接按照步骤安装即可

    原文作者:weidwonder
    原文地址: https://www.jianshu.com/p/d718ec9d9fbf
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞