Sentry 為我們提供應用程序的錯誤跟蹤,使我們能夠快速定位到錯誤所在的文件和行號。
以下是官網支持語言和框架的部分截圖:

准備工作
自 2020 年 12 月 4 日起,Sentry 默認使用 Python 3。 Sentry 21.1.0 之后的版本不在支持 Python2。
- Python 3
- Docker 20.10.6
- Sentry 21.5.1
安裝 Python 3
安裝方式可在 Python 官網下載最新的安裝包,也可以使用 brew 方式安裝。
這里使用 brew 方式安裝:
brew install python
安裝完成后,使用下面命令查看 Python 版本:
由於 Mac 自帶 Python 版本是 2.x,需要將命令改成
python3
python3 --version
如果覺得 python3 命令怪怪的,我們可以在 .bash_profile 文件增加一行。
# 查看 python 3 路徑
which python3
# 將 python 指定到 python 3 位置
echo "# python \n alias python=/Library/Frameworks/Python.framework/Versions/3.9/bin/python3" >> ~/.bash_profile
# 記得修改完后,需要 source 一下
source ~/.bash_profile
現在使用 python --version 來驗證一下我們的配置。

安裝 Docker
這里直接從官網下載:
https://www.docker.com/get-started
安裝完成后,設置一下鏡像源:
點擊頂部任務欄的 Docker 圖標,選擇 Preferences...

接下來,點擊左邊的 Docker Engine,在右邊輸入區域增加 registry-mirrors 配置。
{
...
"registry-mirrors": ["https://registry.cn-hangzhou.aliyuncs.com"]
}
再右下角點擊 Apply & Restart 按鈕,保存並重啟 Docker。
安裝 Sentry
Sentry 官方提供了非常便捷的安裝方式,只需在終端執行以下安裝命令即可。從 github 上下載最新的 Sentry 版本:
https://github.com/getsentry/onpremise/releases
下載完成后,進入到保存的下載目錄解壓,然后使用以下命令安裝:
安裝過程中如果不想被 “是否創建用戶” 的提示阻止,可以加上
--no-user-prompt。
./install.sh
在執行安裝過程中,出現 ./install/_lib.sh: line 15: realpath: command not found 錯誤。
解決辦法:
https://github.com/getsentry/onpremise/issues/941
brew install coreutils
安裝 coreutils 后,再執行 ./install.sh。
當看到下圖表示已經全部完成了,執行 docker-compose up -d 命令。


沒有出現錯誤,到這可以看看效果了,在瀏覽器中打開 http://127.0.0.1:9000/

添加賬號
如果安裝時跳過賬號創建,在終端進入 onpremise 目錄執行下面命令,創建超級用戶(管理員):
docker-compose run --rm web createuser --superuser --force-update
superuser 表示創建管理員。
force-update 表示覆蓋存在的用戶。
參考資料
- https://develop.sentry.dev/self-hosted/
- https://github.com/getsentry/onpremise
- https://github.com/getsentry/onpremise/issues/941
