簡介
sentry是一個人性化收集&定位&定格程序錯誤的工具。說白了就是在網頁上就能看到你的錯誤棧信息,和各種當時的環境變量。比你大眼瞪小眼看那些日志強多了。有多強? 誰用誰知道.
支持框架超多, 主流語言基本上都是支持的
英文官方安裝教程
點擊Installation with Python查看官方python教程
但是官方不建議使用python直接安裝了, 而是建議使用docker.
安裝
言歸正傳開始安裝, 本教程安裝的sentry為version==8.19, 系統環境 ubuntu 16.04 (其他版本應該無妨)
-
安裝 postgreSql
$ sudo aptitude install postgresql
-
安裝redis
$ sudo aptitude install redis-server
-
[
可選, 推薦
] pip安裝virtualenv
和virutalenvwrapper
然后創建虛擬環境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
-
安裝sentry包(到目前最新版本是8.19.0)
$ mkvirtualenv sentry $ workon sentry $ pip install sentry
-
創建配置
$ sudo `which sentry` init /etc/sentry
-
修改postgresql密碼
$ sudo -u postgres psql postgres=# \password
然后自己指定密碼
-
修改數據庫配置
$ vim /etc/sentry/sentry.conf.py
修改密碼用戶名等
-
修改其他配置
$ vim /etc/sentry/config.yml
如果無需郵箱則修改 mail.backend: 'dummy'
-
下面以qq企業郵箱為例
qq郵箱需要用到ssl, sentry是基于django1.6, django1.6原生不支持ssl, 從1.7開始支持, 所以先安裝
django_smtp_ssl
以支持sslpip 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'
-
創建sentry 數據庫
$ sudo -u postgres createdb sentry
-
sentry 更新數據庫
$ SENTRY_CONF=/etc/sentry `which sentry` upgrade
(如果有錯誤, 見下一章錯誤處理)
-
sentry 創建用戶, 如果上一步(upgrade)里邊創建了超級用戶這一步可以省略
$ SENTRY_CONF=/etc/sentry `which sentry` createuser
-
啟動服務
注意
: 這里啟動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), 里邊會有對應的對接教程, 很簡單直接按照步驟安裝即可