Sentry是一个错误日志服务器,可以将程序错误的详细情况集中捕获,并提供Web界面来浏览错误。支持Python、JavaScript、Node.js、PHP、Ruby、Cocoa、Java、C#、Go、Elixir、Perl等语言。doc: https://docs.sentry.io/server/
Sentry中默认是使用postgresql和redis
yum install postgresql-server service postgresql initdb systemctl enable postgresql systemctl start postgresql systemctl status postgresql # http://axiaoxin.com/article/121/ # 创建一个sentry用户 sudo -u postgres createuser --superuser sentry # 为sentry用户设置密码 sudo -u postgres psql \password sentry \q
yum install redis
systemctl enable redis
systemctl start redis
systemctl status redis
安装Sentry官网提供了两种方法,via Docker & via Python:
环境依赖:
python版本需要是2.7,pip版本必须要8.1以上。如果不是需要先升级,否则无法成功安装。
因为sentry依赖django,所以本地如果有django环境由于版本原因可能会版本干扰,所以安装都尽量选择用virtualenv安装。
sudo yum install python-setuptools gcc python-devel libffi-devel libjpeg-devel libxml2-devel libxslt-devel libyaml-devel
virtualenv /www/sentry/
source /www/sentry/bin/activate
pip install -U sentry
完成后执行 sentry
命令可以看到它的命令行用法输出
TODO
sentry init /etc/sentry
修改/etc/sentry/sentry.conf.py
中的数据库配置
DATABASES = { 'default': { 'ENGINE': 'sentry.db.postgres', 'NAME': 'sentry_db', 'USER': 'sentry', 'PASSWORD': 'sentry@123', 'HOST': 'localhost', 'PORT': '5432', 'AUTOCOMMIT': True, 'ATOMIC_REQUESTS': False, } }
如果异常显示的时间不对需要添加设置默认时区:
SENTRY_DEFAULT_TIME_ZONE = 'Asia/Shanghai'
修改/etc/sentry/config.yml
中的邮件配置,将Mail Server下的对应选项设置为自己对应的邮件服务设置即可。
配置好后可以在/manage/status/mail/
界面发送测试邮件看是否配置成功。
createdb -U sentry -E utf-8 sentry_db
创建sentry_db报错: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
解决方法:修改template1的编码为utf8
update pg_database set datallowconn = TRUE where datname = 'template0'; \c template0 update pg_database set datistemplate = FALSE where datname = 'template1'; drop database template1; create database template1 with template = template0 encoding = 'UTF8'; update pg_database set datistemplate = TRUE where datname = 'template1'; \c template1 update pg_database set datallowconn = FALSE where datname = 'template0'; VACUUM FREEZE;
SENTRY_CONF=/etc/sentry sentry upgrade
若报错django.db.utils.OperationalError: FATAL: Ident authentication failed for user "sentry"
解决办法: 修改/var/lib/pgsql/data/pg_hba.conf
中的
# TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 127.0.0.1/32 trust # IPv6 local connections: host all all ::1/128 ident
把METHOD列的值改成trust
,重启:systemctl restart postgresql
过程中会询问创建超级用户,单独创建用户的命令:SENTRY_CONF=/etc/sentry sentry createuser
SENTRY_CONF=/etc/sentry sentry run web # 由于用root使用pickle序列化的安全风险,需要设置环境变量允许使用root export C_FORCE_ROOT=True SENTRY_CONF=/etc/sentry sentry run worker SENTRY_CONF=/etc/sentry sentry run cron
如果端口有冲突,修改/etc/sentry/sentry.conf.py
中的SENTRY_WEB_PORT
至此,sentry安装完成。访问web界面,设置好team创建好project后,选择相应的配置教程。
在Configure your application界面中选择flask,会跳转到一个教程页面,照做即可。
在你的flask应用中需要使用raven,他是sentry的客户端:pip install raven
然后将setup中的代码加到flask应用中,其中的dsn是为你的project特定分配的,不可修改。
你的Sentry应用配置完成后,它会自动的捕获在Flask中未被处理的异常。如果你希望发送额外的事件,Sentry 的Flask 中间件对象还额外给了一些辅助函数。
调用 captureException 捕获任意异常:
try: 1 / 0 except ZeroDivisionError: sentry.captureException()
配置NGINX
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; }
配置supervisor:
[program:sentry-web] directory=/www/sentry/ environment=SENTRY_CONF="/etc/sentry" command=/www/sentry/bin/sentry start autostart=true autorestart=true redirect_stderr=true stdout_logfile=syslog stderr_logfile=syslog [program:sentry-worker] directory=/www/sentry/ environment=SENTRY_CONF="/etc/sentry",C_FORCE_ROOT=True command=/www/sentry/bin/sentry run worker autostart=true autorestart=true redirect_stderr=true stdout_logfile=syslog stderr_logfile=syslog [program:sentry-cron] directory=/www/sentry/ environment=SENTRY_CONF="/etc/sentry" command=/www/sentry/bin/sentry run cron autostart=true autorestart=true redirect_stderr=true stdout_logfile=syslog stderr_logfile=syslog
tlinux没有make: yum reinstall make
tlinux没有cmake且cmake版本要高于3.4.3:reinstall的版本是2.8.11,需要手动编译安装:https://cmake.org/download/
由于内网pypi镜像没有cffi模块,需要手动从源码安装:https://pypi.python.org/pypi/cffi
yum install gcc-c++ ./configure gmake gmake install cmake --version
网友40.*.*.47[美国]2022-05-26 21:50
网友185.*.*.25[火星]2022-05-26 21:35
网友185.*.*.19[火星]2022-05-26 21:22
网友66.*.*.216[火星]2022-05-26 21:18
发表评论
亲~ 评论内容是必须的哟! o(∩_∩)o
昵称
邮箱
主页
评论