Hansen's ink

Back

安装#

安装 JDK#

Gerrit 基于 Java 开发,因此依赖 JAVA 的运行环境,当前最新 3.13 版本要求至少 Java 21。因此需要先安装 JRE。

安装 Gerrit#

Gerrit 账号创建并使用:

sudo adduser gerrit

sudo su gerrit
cd /home/gerrit
bash

Gerrit 安装

java -jar gerrit-3.10.1.war init -d /home/gerrit
bash

安装时初始参数:

Auth 方式输入 HTTP,并使用反向代理;

Plugin 插件都选 y

配置用户:

htpasswd -c /home/gerrit/gerrit/etc/gerrit.password admin     # 创建第一个用户admin,同时会生成一个gerrit.password文件
htpasswd -m /home/gerrit/gerrit/etc/gerrit.password user1     # 在gerrit.password增加用户用 -m
bash

此时 gerrit/etc/gerrit.conf 配置如下:

配置反向代理#

设置 nginx#

em /etc/nginx/conf.d/gerrit.conf

其中

location = /logout {
        return 302 <http://logout:logout@192.168.52.46:81/>;
}
bash

这一部分是因为:

Gerrit 的 HTTP 验证通常依赖外部的反向代理(如 Nginx、Apache)来处理用户的认证,客户端通过浏览器发送 HTTP basic authentication 的头部信息(Authorization: Basic <credentials>)来完成验证。

HTTP 验证的特点是:

  1. 用户的登录状态由浏览器缓存的 Basic Authentication 凭据维持,不存储在 Gerrit 中。
  2. 用户点击 Sign out 后,Gerrit 本身无法清除浏览器上缓存的凭据。
  3. 此外,现代浏览器的 HTTP Basic Auth 无法通过 JS 或页面行为主动触发清理,退出登录变得较为困难。

**浏览器缓存了 Basic Authentication 凭证,**即使点击了 Sign out,浏览器依然用之前缓存的凭据重新发送认证请求,导致用户无法登出。

基于火狐内核的解决方案:

  • 浏览器会对包含 logout:logout@ 这样形式的 URL 自动处理,直接向目标服务器发送带有 Authorization 头的请求。
  • 因为提供的用户名和密码(logout:logout)在服务器端被拒绝,导致浏览器认为当前凭据已经失效,从而清除缓存的 HTTP Basic Authentication 会话。
Gerrit 安装
https://astro-pure.js.org/blog/gerrit-install
Author Hansen W.
Published at August 11, 2025
Comment seems to stuck. Try to refresh?✨