• 云途科技成立于2010年 - 专注全球跨境电商服务器租赁托管!
  • 帮助中心

    您可以通过下方搜索框快速查找您想知道的问题

    ubuntu sentry 安装配置

      in  unix      Tags: 

    sentry 是一个实时的事件日志和聚合平台,基于 Django 构建。

    sentry 可以帮助你将程序的所有 exception 自动记录下来,处理 exception 是每个程序的必要部分,所以 sentry 也几乎可以说是所有项目的必备组件,同时也有利于我们开发。

    sentry 支持 web 前后端、移动应用以及游戏,支持 python、OC、Java、php、Go、Node、Django、RoR 等主流编程语言和框架 ,还提供了 GitHub、Slack、Trello 等常见开发工具的集成

    一,安装配置pgsql

    1,安装postgresql

    # apt-get install postgresql postgresql-contrib

    2,修改postgre密码

    root@test-H110M-S2PH:~# su - postgres  //切换用户
    postgres@test-H110M-S2PH:~$ psql
    psql (9.5.14)
    Type "help" for help.
    
    postgres=# \password    //修改密码
    Enter new password:
    Enter it again:
    postgres=# \q
    postgres@test-H110M-S2PH:~$ exit //退出

    3,启动postgresql

    # /etc/init.d/postgresql start
    # netstat -tpnl |grep postgre
    tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 4088/postgres //启动成功

    二,安装redis

    # apt install redis-server  //安装
    # /etc/init.d/redis-server start //启动
    # netstat -tpnl |grep redis
    tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 1070/redis-server 1  //成功

    三,安装sentry相关组件

    # apt install python-setuptools python-dev libxslt1-dev gcc libffi-dev libjpeg-dev \
    libxml2-dev libxslt-dev libyaml-dev libpq-dev python-pip build-essential

    四,安装配置sentry

    1,安装虚拟环境工具

    # pip install -U virtualenv

    2,创建虚拟环境

    # mkdir /var/www
    # cd /var/www/
    # mkdir sentry
    # chmod -R 777 /var/www/sentry
    # cd sentry
    # virtualenv venv
    # source venv/bin/activate   //这一步不要忘了,很重要,进入虚拟环境
    (venv) root@test-H110M-S2PH:/var/www/sentry#   //source过后,前面会多出个(venv)

    3,安装sentry

    # pip install -U 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.
    
     。。。。。。。。。。。。。。。。。。。。。省略。。。。。。。。。。。。。。。。。。。。。

    4,初始化sentry的配置文件

    # sentry init /var/www/sentry/conf

    5,修改postgresql的连接

    # vim /var/www/sentry/conf/sentry.conf.py
    
    DATABASES = {
     'default': {
     'ENGINE': 'sentry.db.postgres',
     'NAME': 'sentry',
     'USER': 'postgres',
     'PASSWORD': '123456', //安装完后,修改的那个密码
     'HOST': '',
     'PORT': '',
     'AUTOCOMMIT': True,
     'ATOMIC_REQUESTS': False,
     }
    }

    6,初始化数据库和创建用户

    # vim /etc/postgresql/9.5/main/pg_hba.conf //改完配置后重启postgresql
    local   all             postgres                                md5 //peer改为md5
    local   all             all                                     peer
    host    all             all             127.0.0.1/32            md5
    host    all             all             ::1/128                 md5

    如果不做这步,SENTRY_CONF=/var/www/sentry/conf/ sentry upgrade的时候,会报OperationalError: FATAL: Peer authentication failed for user "postgres"

    # su - postgres   //切换用户
    $ createdb -E utf-8 sentry  //创建数据库和用户
    $ exit  //退出

    如果不做这一步,createdb时会报createdb: could not connect to database template1: FATAL: role "root" does not exist

    # SENTRY_CONF=/var/www/sentry/conf/ sentry upgrade

    如果提示sentry.exceptions.InvalidConfiguration: MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error.

    # redis-cli
    127.0.0.1:6379> config set stop-writes-on-bgsave-error no
    OK
    127.0.0.1:6379>

    装了二次,一台真实机器,一台云机器,报了一次上面的redis错识,解决办法:登录redis,执行config set stop-writes-on-bgsave-error no。然后在执行SENTRY_CONF=/var/www/sentry/conf/ sentry upgrade  ,执行完了后,会提示创建用户

    # SENTRY_CONF=/var/www/sentry/conf/ sentry upgrade
    。。。。。。。。。。。。省略。。。。。。。。。。。。
     > sentry:0422_auto__add_grouphashtombstone__add_unique_grouphashtombstone_project_ha
     > sentry:0423_auto__add_index_grouphashtombstone_deleted_at
    Created internal Sentry project (slug=internal, id=1)
    
    Would you like to create a user account now? [Y/n]: y
    Email: 95219454@qq.com
    Password:
    Repeat for confirmation:
    Should this user be a superuser? [y/N]: y
    User created: 95219454@qq.com
    Added to organization: sentry
     - Loading initial data for sentry.
    Installed 0 object(s) from 0 fixture(s)
    Running migrations for nodestore:
     - Migrating forwards to 0001_initial.
     > nodestore:0001_initial
     - Loading initial data for nodestore.
    。。。。。。。。。。。。省略。。。。。。。。。。。。

    如果你没有创建用户,也可以用SENTRY_CONF=/var/www/sentry/conf/ sentry createuser

    7,启动sentry

    # SENTRY_CONF=/var/www/sentry/conf/ sentry run web //运行web服务
    # SENTRY_CONF=/var/www/sentry/conf/ sentry run worker //运行日志搜集进程
    # SENTRY_CONF=/var/www/sentry/conf/ sentry run cron //启动cron进程

    7.1,如果启动worker报以下错误

    07:23:46 [INFO] sentry.bgtasks: bgtask.spawn (task_name=u'sentry.bgtasks.clean_dsymcache:clean_dsymcache')
    Running a worker with superuser privileges when the
    worker accepts messages serialized with pickle is a very bad idea!

    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).

    User information: uid=0 euid=0 gid=0 egid=0

    解决办法:

    # export C_FORCE_ROOT='true'  //这是临时的,可以放到.bashrc

    work启动成功如下

    # SENTRY_CONF=/var/www/sentry/conf/ sentry run worker
    07:37:27 [INFO] sentry.bgtasks: bgtask.spawn (task_name=u'sentry.bgtasks.clean_dsymcache:clean_dsymcache')
    -------------- celery@test-H110M-S2PH v3.1.18 (Cipater)
    ---- **** -----
    --- * ***  * -- linux-4.15.0-29-generic-x86_64-with-Ubuntu-16.04-xenial
    -- * - **** ---
    - ** ---------- [config]
    - ** ---------- .> app:         sentry:0x7f43f6ed82d0
    - ** ---------- .> transport:   redis://localhost:6379//
    - ** ---------- .> results:     disabled
    - *** --- * --- .> concurrency: 4 (prefork)
    -- ******* ----
    --- ***** ----- [queues]
    -------------- .> activity.notify  exchange=default(direct) key=activity.notify
    .> alerts           exchange=default(direct) key=alerts
    .> assemble         exchange=default(direct) key=assemble

    7.2,如果登录到http://ip:9000后,页面上方报以下错误

    Background workers haven't checked in recently. This is likely an issue with your configuration or the workers aren't running.

    是因为sentry run cron,没有启动起来。

    登录成功后如下:

    sentry 安装成功

    sentry 安装成功

    五,安装supervisor,配置sentry自启动

    # apt install supervisor
    # vim /etc/supervisor/conf.d/sentry.conf
    
    [program:sentry-web]
    directory=/var/www/sentry/venv/ //注意虚拟环境目录
    environment=SENTRY_CONF="/var/www/sentry/conf" //配置文件目录
    command=/var/www/sentry/venv/bin/sentry run web
    autostart=true
    autorestart=true
    redirect_stderr=true
    stdout_logfile=syslog
    stderr_logfile=syslog
    
    [program:sentry-worker]
    directory=/var/www/sentry/venv/
    environment=SENTRY_CONF="/var/www/sentry/conf"
    command=/var/www/sentry/venv/bin/sentry run worker
    autostart=true
    autorestart=true
    redirect_stderr=true
    stdout_logfile=syslog
    stderr_logfile=syslog
    user=redis     //不用root账号,不会报C_FORCE_ROOT错误
    
    [program:sentry-cron]
    directory=/var/www/sentry/venv/
    environment=SENTRY_CONF="/var/www/sentry/conf"
    command=/var/www/sentry/venv/bin/sentry run cron
    autostart=true
    autorestart=true
    redirect_stderr=true
    stdout_logfile=syslog
    stderr_logfile=syslog
    
    # /etc/init.d/supervisor start   //启动
    
    # supervisorctl status  //查看状态,running说明启动成功
    sentry-cron RUNNING pid 7851, uptime 2:17:30
    sentry-web RUNNING pid 7850, uptime 2:17:30
    sentry-worker RUNNING pid 28691, uptime 0:00:02

    六,配置Nginx代理

    # vim sentry.conf
    server {
        listen 80;
        server_name sentry.xxxx.com;
    
    	location / {
    	  proxy_pass         http://localhost: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;
    	}
    
    }

    在这里要注意,server_name设置的域名,在登录sentry时,要设置root url,这块保持一样



    • 外贸虚拟主机

      1GB硬盘

      2个独立站点

      1000M带宽

      不限制流量

      美国外贸专用虚拟主机,cPanel面板,每天远程备份.
      服务器配置:2*E5 32核,96GB 内存,4*2TB 硬盘 RAID10 阵列.

      ¥180/年

    • 美国/荷兰外贸VPS

      2核CPU

      1G内存

      30硬盘

      10M带宽

      美国/荷兰外贸云服务器,专注外贸服务器行业12年.
      服务器配置:2*E5 32核,96GB 内存,4*2TB 硬盘 RAID10 阵列.

      ¥99/月

    • 全球外贸服务器

      8核CPU

      32G内存

      1TB硬盘

      1000M带宽

      已部署数据中心:美国洛杉矶/亚特兰大、荷兰、加拿大、英国伦敦、德国、拉脱维亚、瑞典、爱沙尼亚
      自有机柜(全球九大数据中心),稳定在线率:99.9%

      ¥999/月 原价1380

    7*24小时 在线提交工单

    如果您的问题没有得到解决,推荐您在线提交工单,我们的客服人员会第一时间为您解决问题

    展开