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启动成功如下:
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,没有启动起来。
登录成功后如下:
五,安装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,这块保持一样
转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/server/1960.html
作者你好,想问一下,日志多的话如何清理比较好啊,假如访问量大,如何运维好
日志回滚工具很多,需要保留多长时间,根据自己需要。也可以使用elk
想问一下,redis配置了个密码,怎么在sentry设置上啊,一直不成功
没事了,我的问题
请问如何运行sentry run cron sentry没有这个命令