Willy Geek's Blog

离线安装Sentry

2021/09/10
loading

1、Sentry是什么

image-20210910111113167

如官网Logo所言:

Application Monitoring and Error Tracking Software.

应用监控以及错误追踪软件。

至于Sentry到底有多好,可能只有亲身体验一下就知道了(完善的bug追踪,完整的复现流程breadcrumbs,客户机型的纪录,ip的纪录etc..)

2、为什么用Sentry

  • Sentry采用Client/Server方式。

  • 客户端提供了多个平台的SDK支持,如Android、iOS、Vue、React、Go、Java、NodeJS,开源并且方便快速集成。

  • 服务端开源,可自行搭建,也可通过官网提供的基础服务集成到自己的应用里面, 只有高级服务付费,基础服务例如最常用的bug追踪是免费的。

3、为什么需要离线安装Sentry

公司服务器机子在内网环境,无法连接到外网。而且官网仅提供在线安装的教程,并没提供离线安装的教程,其实离线安装只不过多了些额外的步骤,比如需要外网的内容一同打到镜像里面,把wal2json拉到本地等。

4、离线安装环境准备

  • 离线安装Docker,这里有篇不错的教程,可以参考一下, Linux离线安装Docker,这里需要注意最好保证有网络的服务器跟无网络的服务器保持相同的系统版本,例如同版本下的CentOS、Ubuntu,不然会有版本兼容问题。

  • 离线安装Docker-Compose,同样的,也有教程, 可以参考一下, centos7离线安装docker-compose. 简单来说, 就是把docker-compose的可执行文件放在/usr/local/bin目录下。

  • 下载Sentry的Release包, 当前用的是21.8.0版本。

  • 前期准备完成。

5、离线安装额外准备

  • 打开步骤4的Sentry安装包,先观察一下脚本安装步骤,入口在./install.sh有些地方需要外网下载的部分。

  • 打开cron/Dockerfile这个文件,大概动作就是添加cron依赖,然后拷贝入口文件,但这个添加cron动作是需要联网操作的。

  • 1
    2
    3
    4
    5
    6
    ARG BASE_IMAGE
    FROM ${BASE_IMAGE}
    RUN apt-get update && apt-get install -y --no-install-recommends cron && \
    rm -r /var/lib/apt/lists/*
    COPY entrypoint.sh /entrypoint.sh
    ENTRYPOINT ["/entrypoint.sh"]
  • 然后在docker-compose.yml,发现几个镜像,调用了上面的Dockerfile打包逻辑:

  • 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    snuba-cleanup:
    <<: *snuba_defaults
    image: snuba-cleanup-onpremise-local
    build:
    context: ./cron
    args:
    BASE_IMAGE: "$SNUBA_IMAGE"
    command: '"*/5 * * * * gosu snuba snuba cleanup --storage errors --dry-run False"'
    symbolicator-cleanup:
    <<: *restart_policy
    image: symbolicator-cleanup-onpremise-local
    build:
    context: ./cron
    args:
    BASE_IMAGE: "$SYMBOLICATOR_IMAGE"
    command: '"55 23 * * * gosu symbolicator symbolicator cleanup"'
    sentry-cleanup:
    <<: *sentry_defaults
    image: sentry-cleanup-onpremise-local
    build:
    context: ./cron
    args:
    BASE_IMAGE: "$SENTRY_IMAGE"
    entrypoint: "/entrypoint.sh"
    command: '"0 0 * * * gosu sentry sentry cleanup --days $SENTRY_EVENT_RETENTION_DAYS"'
  • 主要就是给sentry、snuba、symbolicator这几个镜像,添加cron定时任务模块,如果我们要在离线环境安装,肯定是不行的,于是我们改写一下这三个镜像,提前把定时任务打进镜像里面。举其中一个镜像当例子,新建Dockerfile:

  • 1
    2
    3
    FROM getsentry/sentry:21.8.0
    RUN apt-get update && apt-get install -y --no-install-recommends cron && \
    rm -r /var/lib/apt/lists/*

    然后docker build出来,然后用docker tag给他一个原来一样的名字,如: getsentry/sentry:21.8.0,另外两个同理build出镜像出来,便可以拉到离线环境的服务器里面了。其他需要依赖的镜像,例如alpine、redis、zookeeper, 无需其他额外操作,就按照docker-compose.yml里面的指定版本进行安装导出即可,然后拉到离线环境的服务器里面。

  • 打开install-wal2json.sh这个脚本:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    echo "${_group}Downloading and installing wal2json ..."

    FILE_TO_USE="../postgres/wal2json/wal2json.so"
    ARCH=$(uname -m)
    FILE_NAME="wal2json-Linux-$ARCH-glibc.so"

    docker_curl() {
    # The environment variables can be specified in lower case or upper case.
    # The lower case version has precedence. http_proxy is an exception as it is only available in lower case.
    docker run --rm -e http_proxy -e https_proxy -e HTTPS_PROXY -e no_proxy -e NO_PROXY curlimages/curl:7.77.0 "$@"
    }

    if [[ $WAL2JSON_VERSION == "latest" ]]; then
    VERSION=$(
    docker_curl https://api.github.com/repos/getsentry/wal2json/releases/latest |
    grep '"tag_name":' |
    sed -E 's/.*"([^"]+)".*/\1/'
    )

    if [[ ! $VERSION ]]; then
    echo "Cannot find wal2json latest version"
    exit 1
    fi
    else
    VERSION=$WAL2JSON_VERSION
    fi

    mkdir -p ../postgres/wal2json
    if [ ! -f "../postgres/wal2json/$VERSION/$FILE_NAME" ]; then
    mkdir -p "../postgres/wal2json/$VERSION"
    docker_curl -L \
    "https://github.com/getsentry/wal2json/releases/download/$VERSION/$FILE_NAME" \
    > "../postgres/wal2json/$VERSION/$FILE_NAME"
    fi
    cp "../postgres/wal2json/$VERSION/$FILE_NAME" "$FILE_TO_USE"


    echo "${_endgroup}"

    观察分析发现,这里面也是需要联网操作,我们需要从github release把wal2json下载下来,然后把wal2json-Linux-x86_64-glibc.so这个丢到/postgres/wal2json/0.0.2/这个目录下即可,然后还要在.env文件里面,把wal2json的版本从latest改为0.0.2。

6、安装sentry

需要联网下载的东西,然后把所需的镜像image,也拉到了离线环境,这里顺便提一下,如何离线安装镜像

在有联网的机器上,我们可以通过docker save命令,把已经pull下来的镜像,导出来,举个栗子:

docker save nginx > nginx.tar

1
2
3
4
5

导出来之后,把`nginx.tar`拉到离线机器上,通过docker load命令,导入镜像:

```shell
docker load < nginx.tar

我们在前一步已经准备就绪,接下来,运行

1
./install.sh

如无意外,将会自动配置各种环境。

然后,用docker-compose把容器跑起来即可:

1
docker-compose up -d
CATALOG
  1. 1. 1、Sentry是什么
  2. 2. 2、为什么用Sentry
  3. 3. 3、为什么需要离线安装Sentry
  4. 4. 4、离线安装环境准备
  5. 5. 5、离线安装额外准备
  6. 6. 6、安装sentry