Sentry 部署及使用(windows环境/centos环境)

2,734 阅读4分钟

Sentry 部署及使用

Requirements

  • Docker 19.03.6+
  • Compose 1.28.0+
  • 4 CPU Cores
  • 8 GB RAM
  • 20 GB Free Disk Space

目录

  1. 资料文档
  2. centos环境下安装
  3. windows环境下安装
  4. vue集成
  5. 小程序集成

资料文档

sentry安装部署

windows环境上sentry安装部署


centos环境下安装

  1. yum 方式安装升级 docker 安装方式
  2. 安装 python3 安装方式
  3. 从 github 上获取 Sentry 最新代码。
  4. 进入 onpremise ,运行 install.sh 脚本。
  5. 运行 docker-compose up -d 以启动Sentry 访问 http://127.0.0.1:9000
git clone https://github.com/getsentry/onpremise.git
cd onpremise
./install.sh
docker-compose up -d

首次进入可以进行邮件配置


windows环境下安装

总体流程

  • python3安装
  • 安装docker desktop for windows
  • hyper-v 安装
  • 开启wsl功能(Windows Subsystem for Linux) / wsl升级 / windows ubuntu 安装
  • ubuntu docker安装
  • 拉取sentry初始化项目并且安装

python3安装

python3安装方法

安装docker desktop for windows

下载地址

启动后可以通过docker version 查看安装情况

hyper-v 安装

windows10家庭版没有hyper-v,如果有跳过

安装方法

开启wsl功能(Windows Subsystem for Linux) / wsl升级到wsl2

点击开始 -> 设置 -> 应用 -> 应用和功能 找到 程序和功能

勾选hyper-v以及适用于linux的windows子系统

重启过后打开windows自带的商店并搜索Linux选择并安装ubuntu 18.04LTS

使用管理员打开powershell并且输入

Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform

重启系统后依旧打开powershell输入wsl -l查看已安装的子系统

再次输入wsl --set-version Ubuntu-18.04 2将wsl升级到wsl2,等几分钟转化完成后输入wsl -l -v 查看版本

wsl --set-version Ubuntu-18.04 2
wsl -l -v 

ubuntu docker安装

1. sudo apt-get -y install apt-transport-https ca-certificates curl

2. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

3. sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

4. sudo apt-get update

5. sudo apt-get -y install docker-ce-cli

将ubuntu中的docker连接到windows的docker desktop

将docker desktop设置中的Expose daemon on tcp://localhost:2375 without TLS打开

在ubuntu使用输入以下命令

sudo docker ps

unset DOCKER_HOST 

vi ~/.bashrc

下面添加一行:

export DOCKER_HOST='unix:///var/run/docker.sock'

接着输入docker version 查看连接结果 出现下面两段信息就说明连接成功

Client: Docker Engine - Community
 Version:           20.10.11
 API version:       1.41
 Go version:        go1.16.9
 Git commit:        dea9396
 Built:             Thu Nov 18 00:37:08 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.10
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.9
  Git commit:       e2f740d
  Built:            Mon Oct 25 07:41:30 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.11
  GitCommit:        5b46e404f6b9f661a205e28d59c982d3634148f8
 runc:
  Version:          1.0.2
  GitCommit:        v1.0.2-0-g52b36a2
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

拉取sentry初始化项目并且安装

1.拉取代码: sentry下载地址 例如放到d/work/sentry

2.使用ubuntu打开windows上该项目所在位置,windows的盘挂载在mnt下

cd /
cd mnt/d/work/sentry 进入项目 执行./install.sh 执行到最后会让你创建一个admin 账号

报错:执行到最后如果卡住出现python3.8的is not报错。换成./install.sh --no-user-prompt. docker-compose run --rm web upgrade 创建admin 账号

启动 run docker-compose up -d

访问 http://localhost:9000/


vue集成

1.进入admin后创建vue项目,会有相关引导。

Sentry.init({
  Vue,
  dsn: "http://9ae29221c20347b0a018d87732f6ec2f@localhost:9000/2",
  release: process.env.RELEASEVERSION,
  integrations: [
    new Integrations.BrowserTracing({
      routingInstrumentation: Sentry.vueRouterInstrumentation(router),
      tracingOrigins: ["localhost", "my-site-url.com", /^\//],
    }),
  ],
  tracesSampleRate: 1.0,
  initialScope: {
    user: {id: 42, email: "john.doe@example.com"},
  }
});

initialScope:要设置为初始作用域的数据。初始作用域可以定义为对象或回调函数
release:发布的版本号(自定义)

其他相关参数说明:地址

2.上传source-map (定位到代码的实际位置)

插件:npm i @sentry/webpack-plugin
(如果安装失败改成cnpm去安装)

vue.config.js 引入插件

  configureWebpack: config => {
    return {
      plugins: [new SentryPlugin({
      release: process.env.RELEASEVERSION,
      include: "./dist",
    })]
    }
  },

注意:Sentry.init的release版本要和 configureWebpack配置的release版本一致,不然issue会提交到错误的版本

安装过程中容易遇到的问题

  • docker安装太慢。 解决方法:切换阿里镜像
  • Sentry 执行./install.sh 如果python环境是3.8以及以上的可能报一个语法错误。改成./install.sh --no-user-prompt

小程序集成

Sentry 无官方 api 用于提供给小程序,有第三方提供的库,可使用原有 api 实现小程序端的异常监控。 sentry-mina

npm install sentry-mina --save