Gerrit 공식 가이드

Gerrit의 공식 가이드는 https://www.gerritcodereview.com/ 상단의 Docs > Latest 에서 볼 수 있다.

이 페이지의 설치 방법은 공식 가이드 중 Qucickstart for Installing Gerrit on Linux 을 따른다.

Quickstart 설치는 Gerrit을 간단히 설치하고 맛보는 용도이다.

 

Gerrit 설치

Gerrit 다운로드

Gerrit 설치를 위해서 먼저 다운로드를 받아야 한다.

여기에서 다운로드된 Gerrit 버전이 설치 디렉토리에 복사되므로, 최신 버전인 3.5.1을 다운로드 받았다.

junggu.lee@bungslxubu51:~$ cd bin
junggu.lee@bungslxubu51:~/bin$ wget https://gerrit-releases.storage.googleapis.com/gerrit-3.5.1.war

 

Gerrit 설치 명령어

Quickstart 가이드 문서처럼 --batch --dev -d 옵션을 사용하면, 기본설정을 기본으로 가정하고 빠르게 설치가 가능하다.

Quickstart 가이드 문서에서 사용하는 옵션은 다음과 같다.

  • --batch : 기본 구성 옵션을 사용
  • --dev : 인증시 DEVELOPMENT_BECOME_ANY_ACCOUNT 을 사용
  • -d : 설치할 디렉토리 지정
junggu.lee@bungslxubu51:~$ java -jar ~/bin/gerrit-3.5.1.war init --batch --dev -d ~/work/gerrit_quickstart

설치 후 자동으로 Gerrit이 실행되며, Web Browser에서 Gerrit 창이 열린다.

 

설정 문제가 있는 경우에, 실행시 에러가 발생할 수 있다.

이 때는 로그 파일을 살펴보고, 설정 파일인 etc/gerrit.config을 수정하여 Gerrit을 실행하면 된다.

내 경우에는 8080 포트의 충돌로 인해서 에러가 발생하였다. ( 문제가 발생했을때는 etc/logs/error_log 파일로 확인 가능하다 )

etc/gerrit.configgerrit.canonicalWebUrlhttpd.listenUrl 의 8080을 8081로 변경하였다.

[gerrit]
        basePath = git
        canonicalWebUrl = http://bungslxubu51:8081/
        serverId = c5b60791-8a32-4d6f-850e-4698ef8ddde9
[container]
        javaOptions = "-Dflogger.backend_factory=com.google.common.flogger.backend.log4j.Log4jBackendFactory#getInstance"
        javaOptions = "-Dflogger.logging_context=com.google.gerrit.server.logging.LoggingContext#getInstance"
        user = junggu.lee
        javaHome = /usr/lib/jvm/java-11-openjdk-amd64
[index]
        type = lucene
[auth]
        type = DEVELOPMENT_BECOME_ANY_ACCOUNT
        userNameCaseInsensitive = true
[receive]
        enableSignedPush = false
[sendemail]
        smtpServer = localhost
[sshd]
        listenAddress = *:29418
[httpd]
        listenUrl = http://*:8081/
[cache]
        directory = cache
[plugins]
        allowRemoteAdmin = true

이후에 다시 Gerrit을 실행한다.

junggu.lee@bungslxubu51:~/work/gerrit_quickstart$ bin/gerrit.sh start

 

또 다른 방법으로는 기본값으로 설정하는 옵션인 --batch 을 제거하면 각종 설정을 개별적으로 지정할 수 있다. ( Standalone 설치 ) 

내 경우에 8080 포트 충돌을 피하기 위해, Listen on port 부분을 8081 포트로 설정하고, 나머지 설정은 기본값으로 두었다.

junggu.lee@bungslxubu51:~$ java -jar ~/bin/gerrit-3.5.1.war init -d $GERRIT_SITE
Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore
[2022-04-20 04:52:39,628] [main] INFO  com.google.gerrit.server.config.GerritServerConfigProvider : No /home/junggu.lee/work/gerrit_quickstart/etc/gerrit.config; assuming defaults

*** Gerrit Code Review 3.5.1
***

Create '/home/junggu.lee/work/gerrit_quickstart' [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/?]:
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                         [junggu.lee]:
Java runtime                   [/usr/lib/jvm/java-11-openjdk-amd64]:
Copy gerrit-3.5.1.war to /home/junggu.lee/work/gerrit_quickstart/bin/gerrit.war [Y/n]?
Copying gerrit-3.5.1.war to /home/junggu.lee/work/gerrit_quickstart/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]: 8081
Canonical URL                  [http://bungslxubu51:8081/]:

*** Cache
***


*** Plugins
***

Installing plugins.
Install plugin codemirror-editor version v3.5.1 [y/N]?
Install plugin commit-message-length-validator version v3.5.1 [y/N]?
Install plugin delete-project version v3.5.1 [y/N]?
Install plugin download-commands version v3.5.1 [y/N]?
Install plugin gitiles version v3.5.1 [y/N]?
Install plugin hooks version v3.5.1 [y/N]?
Install plugin plugin-manager version v3.5.1 [y/N]?
Install plugin replication version v3.5.1 [y/N]?
Install plugin reviewnotes version v3.5.1 [y/N]?
Install plugin singleusergroup version v3.5.1 [y/N]?
Install plugin webhooks version v3.5.1 [y/N]?
Initializing plugins.
No plugins found with init steps.

============================================================================
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/junggu.lee/work/gerrit_quickstart
Init complete, reindexing accounts,changes,groups,projects with: reindex --site-path /home/junggu.lee/work/gerrit_quickstart --threads 1 --index accounts --index changes --index groups --index projects --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.3s (6.3/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 71 is ready
Reindexing projects:    100% (2/2)
Reindexed 2 documents in projects index in 0.0s (40.8/s)
Index projects in version 4 is ready
Executing /home/junggu.lee/work/gerrit_quickstart/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/junggu.lee/work/gerrit_quickstart/bin/gerrit.sh not being run as root.
         Consider changing the OOM score adjustment manually for Gerrit's PID=870815 with e.g.:
         echo '-1000' | sudo tee /proc/870815/oom_score_adj
OK
Waiting for server on bungslxubu51:8081 ... OK
Opening http://bungslxubu51:8081/#/admin/projects/ ...OK

 

그리고 내부 테스트를 목적으로 하는 경우, 외부에서 Gerrit에 접속하는 것을 막을 수 있다.

이 경우, etc/gerrit.conifg 파일의 httpd.listenUrllocalhost로 수정하면 된다. ( Gerrit의 Quickstart 문서 참조 )

# 중략
[httpd]
        listenUrl = http://localhost:8081/
# 중략

Gerrit 실행

Gerrit 설치가 성공적으로 실행되면, 자동으로 Web Browser로 Gerrit 화면을 띄워준다.

Gerrit을 실행/중지/재실행은 다음 명령으로 가능하다.

junggu.lee@bungslxubu51:~$ cd work/gerrit_quickstart/bin/
junggu.lee@bungslxubu51:~/work/gerrit_quickstart/bin$ gerrit.sh start
junggu.lee@bungslxubu51:~/work/gerrit_quickstart/bin$ gerrit.sh stop
junggu.lee@bungslxubu51:~/work/gerrit_quickstart/bin$ gerrit.sh restart

 

Gerrit 삭제

우선 gerrit 실행을 중지한다.

junggu.lee@bungslxubu51:~$ work/gerrit_quickstart/bin/gerrit.sh stop

그리고, 혹시 실행되고 있는 프로세스가 있는지 확인한다.

junggu.lee@bungslxubu51:~$ ps -ef | grep gerrit
junggu.+  737432  707297  0 02:46 pts/0    00:00:00 grep --color=auto gerrit

설치 디렉토리를 제거한다.

junggu.lee@bungslxubu51:~$ rm -rf work/gerrit_quickstart/

 

Troubleshooting

Gerrit에 문제가 생겼을때는 에러 로그를 살펴본다. 에러 로그는 logs/error_log 이다.

다음은 내 에러 및 처리하는 과정을 표시하였다.

junggu.lee@bungslxubu51:~$ cat ~/work/gerrit_quickstart/logs/error_log
[2022-04-20T02:39:01.669Z] [main] INFO  com.google.gerrit.server.git.WorkQueue : Adding metrics for 'SshCommandStart' queue
[2022-04-20T02:39:02.037Z] [main] INFO  com.google.gerrit.server.git.WorkQueue : Adding metrics for 'SSH-Stream-Worker' queue
[2022-04-20T02:39:02.039Z] [main] INFO  com.google.gerrit.server.git.WorkQueue : Adding metrics for 'SSH-Interactive-Worker' queue
[2022-04-20T02:39:02.039Z] [main] INFO  com.google.gerrit.server.git.WorkQueue : Adding metrics for 'SSH-Batch-Worker' queue
[2022-04-20T02:39:02.040Z] [main] INFO  com.google.gerrit.server.git.WorkQueue : Adding metrics for 'MigrateExternalIdCase' queue
[2022-04-20T02:39:02.052Z] [main] WARN  com.google.gerrit.server.config.GitwebCgiConfig : gitweb not installed (no /usr/lib/cgi-bin/gitweb.cgi found)
[2022-04-20T02:39:02.726Z] [main] INFO  org.eclipse.jetty.util.log : Logging initialized @5624ms to org.eclipse.jetty.util.log.Slf4jLog
[2022-04-20T02:39:02.854Z] [main] INFO  com.google.gerrit.server.git.SystemReaderInstaller : Set JGit's SystemReader to read system config from /home/junggu.lee/work/gerrit_quickstart/etc/jgit.config
[2022-04-20T02:39:02.858Z] [main] INFO  com.google.gerrit.server.git.LocalDiskRepositoryManager : Defaulting core.streamFileThreshold to 1001m
[2022-04-20T02:39:03.261Z] [main] INFO  com.google.gerrit.server.plugins.PluginLoader : Loading plugins from /home/junggu.lee/work/gerrit_quickstart/plugins
[2022-04-20T02:39:03.275Z] [main] INFO  com.google.gerrit.server.config.ScheduleConfig : No schedule configuration for "accountDeactivation".
[2022-04-20T02:39:03.313Z] [main] INFO  com.google.gerrit.sshd.SshDaemon : Started Gerrit APACHE-SSHD-2.6.0 on *:29418
[2022-04-20T02:39:03.316Z] [main] INFO  org.eclipse.jetty.server.Server : jetty-9.4.36.v20210114; built: 2021-01-14T16:44:28.689Z; git: 238ec6997c7806b055319a6d11f8ae7564adc0de; jvm 11.0.14.1+1-Ubuntu-0ubuntu1.20.04
[2022-04-20T02:39:03.342Z] [main] INFO  org.eclipse.jetty.server.session : DefaultSessionIdManager workerName=node0
[2022-04-20T02:39:03.343Z] [main] INFO  org.eclipse.jetty.server.session : No SessionScavenger set, using defaults
[2022-04-20T02:39:03.344Z] [main] INFO  org.eclipse.jetty.server.session : node0 Scavenging every 600000ms
[2022-04-20T02:39:03.407Z] [main] INFO  org.eclipse.jetty.server.handler.ContextHandler : Started o.e.j.s.ServletContextHandler@75452b01{/,null,AVAILABLE}
[2022-04-20T02:39:03.412Z] [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:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        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:28)
Caused by: java.io.IOException: Failed to bind to 0.0.0.0/0.0.0.0: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: Address already in use
        at java.base/sun.nio.ch.Net.bind0(Native Method)
        at java.base/sun.nio.ch.Net.bind(Net.java:459)
        at java.base/sun.nio.ch.Net.bind(Net.java:448)
        at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:227)
        at java.base/sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:80)
        at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:344)
        ... 19 more

Gerrit에서는 기본 설치시에 8080포트를 사용하는데, 이미 8080포트를 사용하고 있어서 사용할 수가 없다.

8080 포트가 사용되고 있는지 확인해보았다.

junggu.lee@bungslxubu51:~$ netstat -nap | grep 8080
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:58080         127.0.0.1:9099          TIME_WAIT   -

Gerrit의 동작을 확인하기 위해서 가벼운 브라우저 ( light web browser )인 midori를 설치했는데, 이 midori에서 8080 포트를 사용하고 있었다.

Gerrit 설치시에 8081 포트를 사용하도록 재설치하여 문제를 해결하였다.

 

 

'Gerrit' 카테고리의 다른 글

Gerrit 3.1.10 - 이전 설치 ( Migration, Docker )  (0) 2022.05.16
Gerrit 3.5.1 - 설치 ( Docker )  (0) 2022.05.11
Gerrit - LDAP 설정  (0) 2022.05.03
Gerrit - 설치 ( Standalone )  (0) 2022.04.22
Gerrit 변경사항을 적용하기  (0) 2021.11.18

+ Recent posts