在安装部署 Sentry On-Premise 的过程中,经常遇到这样一种情况:按照 Sentry On-Premise 官方文档部署说明,输入对应的命令,出现交互提示时,没仔细看,回车回车回车,部署完成;然后,在登录 sentry web,发现忘记初始用户密码。遇到这种情况的人还蛮多,当然也包括我。本文主要针对这种情况,记录一下 sentry on-premise 忘记初始用户密码的处理方式。

运行环境

系统及应用版本信息
macOS macOS 10.14.6 (18G87)
Docker Desktop Version: 2.1.0.1(37199), Channel: stable
Docker Image: Sentry On-Premise Commit: 4fade2f
Docker Image: Sentry Tag: sentry:9.1.2

安装 Sentry On-Premise

下载 Sentry On-Premise 源代码并将代码仓库切换到 4fade2f 版本:

git clone git@github.com:getsentry/onpremise.git sentry-onpremise
cd sentry-onpremise
git checkout 4fade2f

按照 README.md 提示,执行安装脚本:

./install.sh

Checking minimum requirements...

Creating volumes for persistent storage...
Created sentry-data.
Created sentry-postgres.

Creating .env...

$SENTRY_IMAGE not set, using latest stable: sentry:9.1.2
...
----------------
You're all done! Run the following command get Sentry running:

  docker-compose up -d

安装完成后,按照安装脚本的输出提示,运行以下命令,启动 Sentry:

docker-compose up -d

WARNING: The SENTRY_IMAGE variable is not set. Defaulting to a blank string.
Creating network "sentry-onpremise_default" with the default driver
Creating sentry-onpremise_smtp_1      ... done
Creating sentry-onpremise_redis_1     ... done
Creating sentry-onpremise_memcached_1 ... done
Creating sentry-onpremise_postgres_1  ... done
Creating sentry-onpremise_web_1       ... done
Creating sentry-onpremise_cron_1      ... done
Creating sentry-onpremise_worker_1    ... done

查看 Sentry 服务相关的容器启动状态:

docker ps
CONTAINER ID        IMAGE                     COMMAND                  CREATED             STATUS              PORTS                    NAMES
40f72be096ce        sentry-onpremise_worker   "/entrypoint.sh run …"   20 seconds ago      Up 18 seconds       9000/tcp                 sentry-onpremise_worker_1
84e0a13eeeb4        sentry-onpremise_cron     "/entrypoint.sh run …"   20 seconds ago      Up 18 seconds       9000/tcp                 sentry-onpremise_cron_1
f5e2b9df476d        sentry-onpremise_web      "/entrypoint.sh run …"   20 seconds ago      Up 18 seconds       0.0.0.0:9000->9000/tcp   sentry-onpremise_web_1
0e3cfc65daac        postgres:9.5              "docker-entrypoint.s…"   21 seconds ago      Up 20 seconds       5432/tcp                 sentry-onpremise_postgres_1
127f19e4f9ef        memcached:1.5-alpine      "docker-entrypoint.s…"   21 seconds ago      Up 20 seconds       11211/tcp                sentry-onpremise_memcached_1
923aa0058248        tianon/exim4              "docker-entrypoint.s…"   21 seconds ago      Up 20 seconds       25/tcp                   sentry-onpremise_smtp_1
1df9770241ad        redis:3.2-alpine          "docker-entrypoint.s…"   21 seconds ago      Up 20 seconds       6379/tcp                 sentry-onpremise_redis_1

至此,Sentry 安装完成。

注意!旧的版本 Sentry On-Premise 是没有提供 install.sh 脚本的,同时,在安装的过程中,也会提示是否创建用户。目前,使用的这个版本,默认情况下,是不会创建用户的。

修改 Sentry 用户密码

访问 http://0.0.0.0:9000 跳转到 Sentry 登录页面,如下:

preview-001.png

通常,到这里,就会去搜 Sentry 默认登录用户名密码等,但是,是搜不到的。

查看 install.sh 脚本,发现如下信息:

if [ $CI ]; then
  docker-compose run --rm web upgrade --noinput
  echo ""
  echo "Did not prompt for user creation due to non-interactive shell."
  echo "Run the following command to create one yourself (recommended):"
  echo ""
  echo "  docker-compose run --rm web createuser"
  echo ""
else
  docker-compose run --rm web upgrade
fi

按照 install.sh 脚本中的注释,运行如下命令,新建一个超级用户:

docker-compose run --rm web createuser --email admin888@example.com --password admin --superuser

WARNING: The SENTRY_IMAGE variable is not set. Defaulting to a blank string.
Starting sentry-onpremise_smtp_1  ... done
Starting sentry-onpremise_redis_1 ... done
Starting sentry-onpremise_postgres_1  ... done
Starting sentry-onpremise_memcached_1 ... done
10:47:47 [WARNING] sentry.utils.geo: settings.GEOIP_PATH_MMDB not configured.
10:47:50 [INFO] sentry.plugins.github: apps-not-configured
User created: admin888@example.com
Added to organization: sentry

然后,使用 admin888@example 用户登录,如下:

preview-002.png

如果是首次登录,那么 Sentry 会先引导用户填写相应的系统配置,当然,如果这里填错了,之后进了 Sentry 再修改也是可以的:

preview-003.png

不过,登录成功后,最好先把 SMTP 设置配置好,这样,以后就可以通过登录页的密码丢失?来重置密码了:

preview-004.png

参考资料