环境
- Ubuntu 20.04
- Gerrit 3.11.3
- Git 2.25.1
- Java JDK 21
- Nginx 1.18.0
安装Java JDK
sudo apt install openjdk-21-jdk
安装Git
sudo apt install git
下载Gerrit
在官网可以看到目前最新的是3.12.0,保守一点挑了前一个版本3.11.3。
安装Gerrit
创建gerrit代码存放目录,将下载下来的war文件拷贝到该目录,然后到该目录下执行如下命令
java -jar gerrit-3.11.3.war init -d review_site
配置建议如下:
Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore
[2025-06-16 21:28:13,743] [main] INFO com.google.gerrit.server.config.GerritServerConfigProvider : No /data/gerrit/review_site/etc/gerrit.config; assuming defaults
*** Gerrit Code Review 3.11.3
***
Create '/data/gerrit/review_site' [Y/n]?
*** Git Repositories
***
Location of Git repositories [git]:
*** JGit Configuration
***
Auto-configured "receive.autogc = false" to disable auto-gc after git-receive-pack.
*** Index
***
Type [lucene]:
*** User Authentication
***
Authentication method [openid/?]: http
Get username from custom HTTP header [y/N]?
SSO logout URL :
Enable signed push support [y/N]?
Use case insensitive usernames [Y/n]?
*** Review Labels
***
Install Verified label [y/N]?
*** Email Delivery
***
SMTP server hostname [localhost]:
SMTP server port [(default)]:
SMTP encryption [none/?]:
SMTP username :
*** Container Process
***
Run as [root]:
Java runtime [/usr/lib/jvm/java-21-openjdk-amd64]:
Copy gerrit-3.11.3.war to review_site/bin/gerrit.war [Y/n]?
Copying gerrit-3.11.3.war to review_site/bin/gerrit.war
*** SSH Daemon
***
Listen on address [*]:
Listen on port [29418]:
Generating SSH host key ... rsa... ed25519... ecdsa 256... ecdsa 384... ecdsa 521... done
*** HTTP Daemon
***
Behind reverse proxy [y/N]?
Use SSL (https://) [y/N]?
Listen on address [*]:
Listen on port [8080]:
Canonical URL [http://forfunsource:8080/]:
*** Cache
***
*** Plugins
***
Installing plugins.
Install plugin codemirror-editor version v3.11.3 [y/N]? y
Installed codemirror-editor v3.11.3
Install plugin commit-message-length-validator version v3.11.3 [y/N]? y
Installed commit-message-length-validator v3.11.3
Install plugin delete-project version v3.11.3 [y/N]? y
Installed delete-project v3.11.3
Install plugin download-commands version v3.11.3 [y/N]? y
Installed download-commands v3.11.3
Install plugin gitiles version v3.11.3 [y/N]? y
Installed gitiles v3.11.3
Install plugin hooks version v3.11.3 [y/N]? y
Installed hooks v3.11.3
Install plugin plugin-manager version v3.11.3 [y/N]? y
Installed plugin-manager v3.11.3
Install plugin replication version v3.11.3 [y/N]? y
Installed replication v3.11.3
Install plugin replication-api version v3.11.3 [y/N]? y
Installed replication-api v3.11.3
Install plugin reviewnotes version v3.11.3 [y/N]? y
Installed reviewnotes v3.11.3
Install plugin singleusergroup version v3.11.3 [y/N]? y
Installed singleusergroup v3.11.3
Install plugin webhooks version v3.11.3 [y/N]? y
Installed webhooks v3.11.3
Initializing plugins.
启动Gerrit
sudo /data/gerrit/review_site/bin/gerrit.sh start
安装Nignx并配置反向代理
sudo apt install nginx
可以将配置文件创建在gerrit目录,再软件链接到nginx配置目录
sudo mkdir /data/gerrit/configs
sudo vi /data/gerrit/configs/nginx
server {
listen *:81;
server_name localhost;
allow all;
deny all;
auth_basic "Welcome to Gerrit Code Review Site!";
auth_basic_user_file /data/gerrit/review_site/etc/gerrit.passwd;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host:8080;
}
}
sudo ln -s /data/gerrit/configs/nginx /etc/nginx/sites-enabled/gerrit
sudo nginx -s reload
添加第一个用户-管理员
用到htpasswd命令,需要先安装apache2-utils
sudo apt-get install apache2-utils
htpasswd -c /data/gerrit/review_site/etc/gerrit.passwd admin
## 注意这里的-c创建一个新文件,如果文件已存在,会清掉已有的账号记录,所以如果要保留已有账号数据,请用-m
htpasswd -m /data/gerrit/review_site/etc/gerrit.passwd admin
## 使用前可以用--help确认一下
htpasswd --help
后续创建新账号也是用这个命令
登录Gerrit
浏览器访问 http://ServerHostNameOrIp:81

输入账号密码看到Gerrit看到界面即代表安装成功。
排查问题
中间如果有碰到无法正常访问网页,可以到/var/log/nginx目录下,查看error.log看问题原因是什么,通常会是权限问题或是端口被占用,针对性解决即可。

218

被折叠的 条评论
为什么被折叠?



