1、前言
Gerrit 名声已很大了,我也就不在过多阐述介绍了,凡是需要安装搭建 Gerrit 服务器的,网上一搜索都是大把精彩教程。但是,基本都是基于代理服务的搭建安装,一种是基于 apache+gerrit 代理的配置,一种是基于 nginx+gerrit 代理的配置,我之前发布的好几篇关于Gerrit 服务的搭建,都有详细的介绍分享,需要的都可以回顾去看看,本文介绍的是 Gerrit 自身带的服务 jetty 服务配置。
2、系统平台
操作系统:Ubuntu 22.04.1 LTS (GNU/Linux 5.15.0-52-generic x86_64)
搭建服务之前,还是老规矩,要先执行系统更新,执行如下两条指令:
$ sudo apt update
$ sudo apt -y upgrade
3、下载
官方下载地址: https://www.gerritcodereview.com/3.6.html
指令下载方式如下图所示:
#下载指令
$ wget https://gerrit-releases.storage.googleapis.com/gerrit-3.6.3.war
查看 JDK 版本
$ java -version
java version "17.0.5" 2022-10-18 LTS
Java(TM) SE Runtime Environment (build 17.0.5+9-LTS-191)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.5+9-LTS-191, mixed mode, sharing)
$
4、开始安装
执行安装指令: $ java -jar gerrit-3.6.3.war init -d /home/scmroot/review_path
如下图所示完整的执行过程
完整代码片段如下:
$ java -jar gerrit-3.6.3.war init -d /home/scmroot/review_path
Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore
[2022-11-13 09:26:01,877] [main] INFO com.google.gerrit.server.config.GerritServerConfigProvider : No /home/scmroot/review_path/etc/gerrit.config; assuming defaults
*** Gerrit Code Review 3.6.3
***
Create '/home/scmroot/review_path' [Y/n]? Y
*** Git Repositories
***
Location of Git repositories [git]: git
*** JGit Configuration
***
Auto-configured "receive.autogc = false" to disable auto-gc after git-receive-pack.
*** Index
***
Type [lucene]:
*** User Authentication
***
Authentication method [openid/?]:
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 [scmroot]:
Java runtime [/usr/local/jdk17.0.5]:
Copy gerrit-3.6.3.war to /home/scmroot/review_path/bin/gerrit.war [Y/n]? Y
Copying gerrit-3.6.3.war to /home/scmroot/review_path/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]? N
Use SSL (https://) [y/N]?
Listen on address [*]: 8080
Listen on port [8080]: 8080
Canonical URL [http://8080:8080/]: http://192.*.*.*:8080
*** Cache
***
*** Plugins
***
Installing plugins.
Install plugin codemirror-editor version v3.6.3 [y/N]? y
Installed codemirror-editor v3.6.3
Install plugin commit-message-length-validator version v3.6.3 [y/N]? y
Installed commit-message-length-validator v3.6.3
Install plugin delete-project version v3.6.3 [y/N]? y
Installed delete-project v3.6.3
Install plugin download-commands version v3.6.3 [y/N]? y
Installed download-commands v3.6.3
Install plugin gitiles version v3.6.3 [y/N]? y
Installed gitiles v3.6.3
Install plugin hooks version v3.6.3 [y/N]? y
Installed hooks v3.6.3
Install plugin plugin-manager version v3.6.3 [y/N]? N
Install plugin replication version v3.6.3 [y/N]? y
Installed replication v3.6.3
Install plugin reviewnotes version v3.6.3 [y/N]? y
Installed reviewnotes v3.6.3
Install plugin singleusergroup version v3.6.3 [y/N]? y
Installed singleusergroup v3.6.3
Install plugin webhooks version v3.6.3 [y/N]? y
Installed webhooks v3.6.3
Initializing plugins.
============================================================================
Welcome to the Gerrit community
Find more information on the homepage: https://www.gerritcodereview.com
Discuss Gerrit on the mailing list: https://groups.google.com/g/repo-discuss
============================================================================
Initialized /home/scmroot/review_path
Init complete, reindexing accounts,changes,groups,projects with: reindex --site-path /home/scmroot/review_path --threads 1 --index accounts --index changes --index groups --index proj ects --disable-cache-statsReindexed 0 documents in accounts index in 0.0s (0.0/s)
Index accounts in version 11 is ready
Reindexing groups: 100% (2/2)
Reindexed 2 documents in groups index in 0.4s (5.2/s)
Index groups in version 8 is ready
Reindexing changes: Slicing projects: 100% (2/2), done
Reindexed 0 documents in changes index in 0.0s (0.0/s)
Index changes in version 77 is ready
Reindexing projects: 100% (2/2)
Reindexed 2 documents in projects index in 0.0s (43.5/s)
Index projects in version 4 is ready
Executing /home/scmroot/review_path/bin/gerrit.sh start
Starting Gerrit Code Review: WARNING: Could not adjust Gerrit's process for the kernel's out-of-memory killer.
This may be caused by /home/scmroot/review_path/bin/gerrit.sh not being run as root.
Consider changing the OOM score adjustment manually for Gerrit's PID=11130 with e.g.:
echo '-1000' | sudo tee /proc/11130/oom_score_adj
FAILED
error: cannot start Gerrit: exit status 1
Waiting for server on 192.168.126.134:8080 ...
^Cscmroot@scmrootcicd:~/soft$
安装完成后,进入安装目录,查看启动的 log 信息,显示如下信息:
可以看到有报错地方,导致gerrit服务没有启动成功。
[2022-11-13T09:29:53.628+08:00] [WorkQueue-2[java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@55a680f8[Not completed, task = java.util.concurrent.Executors$RunnableAdapter@5f5eeb88[Wrapped task = com.google.gerrit.server.logging.LoggingContextAwareRunnable@51991e13]]]] INFO com.googlesource.gerrit.plugins.deleteproject.fs.RepositoryCleanupTask : Cleaning up expired git repositories...
[2022-11-13T09:29:53.639+08:00] [WorkQueue-2[java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@55a680f8[Not completed, task = java.util.concurrent.Executors$RunnableAdapter@5f5eeb88[Wrapped task = com.google.gerrit.server.logging.LoggingContextAwareRunnable@51991e13]]]] INFO com.googlesource.gerrit.plugins.deleteproject.fs.RepositoryCleanupTask : Cleaning up expired git repositories... Done
[2022-11-13T09:29:54.274+08:00] [main] INFO org.eclipse.jetty.server.handler.ContextHandler : Started o.e.j.s.ServletContextHandler@43a34f02{/,null,AVAILABLE}
[2022-11-13T09:29:54.288+08:00] [main] ERROR com.google.gerrit.pgm.Daemon : Unable to start daemon
java.lang.IllegalStateException: Cannot start HTTP daemon
at com.google.gerrit.pgm.http.jetty.JettyServer$Lifecycle.start(JettyServer.java:109)
at com.google.gerrit.lifecycle.LifecycleManager.start(LifecycleManager.java:95)
at com.google.gerrit.pgm.Daemon.start(Daemon.java:386)
at com.google.gerrit.pgm.Daemon.run(Daemon.java:285)
at com.google.gerrit.pgm.util.AbstractProgram.main(AbstractProgram.java:61)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at com.google.gerrit.launcher.GerritLauncher.invokeProgram(GerritLauncher.java:224)
at com.google.gerrit.launcher.GerritLauncher.mainImpl(GerritLauncher.java:120)
at com.google.gerrit.launcher.GerritLauncher.main(GerritLauncher.java:65)
at Main.main(Main.java:29)
Caused by: java.io.IOException: Failed to bind to /0.0.31.144:8080
at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:349)
at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:310)
at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:234)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:73)
at org.eclipse.jetty.server.Server.doStart(Server.java:401)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:73)
at com.google.gerrit.pgm.http.jetty.JettyServer$Lifecycle.start(JettyServer.java:95)
... 12 more
Caused by: java.net.BindException: Cannot assign requested address
at java.base/sun.nio.ch.Net.bind0(Native Method)
at java.base/sun.nio.ch.Net.bind(Net.java:555)
at java.base/sun.nio.ch.ServerSocketChannelImpl.netBind(ServerSocketChannelImpl.java:337)
at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:294)
at java.base/sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:89)
at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:344)
... 19 more
scmroot@scmrootcicd:~/review_path/logs$
关键报错是 : Caused by: java.io.IOException: Failed to bind to /0.0.31.144:8080 ,,本机的 IP 地址配置有错。
5、修改配置文件
进入etc目录下,修改关键的 gerrit.config 文件,大致修改如下:
修改成正确的 IP 地址,就可以重新执行启动 gerrit 服务了。
sh ../bin/gerrit.sh start
查看 log 日志,没有明细报错,说明配置修改正确,gerrit 服务正常启动了。
打开浏览器访问 gerrit 系统
可以看到 gerrit 首页已正常显示了,注册一个账号,就可以登录系统,正常使用了。
使用 SCM 用户登录后,创建一个 demo 仓库。
查看到 Plugins 信息,就是安装的 v3.6.3 版本对应的插件。
到此,最新版 Gerrit 3.6.3 版本,不适用代理服务的搭建配就分享结束了,希望对各位有所帮助,请给个红心点个赞,谢谢各位。