<Spec>

  • Ubuntu version : ubuntu-18.04.5-desktop-amd64
  • Gerrit version : 3.4.1.war
  • JDK version : 11.X 이상
  • Database : H2 (Gerrit defalut DB)
  • Git Repository browser : Gitiles (Gerrit defalut DB) 

(참고로, gerrit-3.1.4.war 는 JDK 8.X 이상이면 된다.)

 

 

-Working path

$ pwd
/opt

 

1. Apache2 설치

$ sudo apt-get install apache2
$ sudo apt-get install apache2-utils
$ sudo a2enmod proxy				# 상태 확인
$ sudo a2enmod proxy_http			# 상태 확인
$ sudo service apache2 restart			#apache2 Start
$ systemctl status apache2			#apache2 상태 확인

 

2. Open SSH Server 설치

$ sudo apt-get install openssh-server

 

3. Git 설치

$ sudo apt-get install git

 

4. Gerrit 설치

$ sudo apt install openjdk-11-jre-headless
$ sudo wget https://gerrit-releases.storage.googleapis.com/gerrit-3.4.1.war
$ sudo java -jar gerrit-3.4.1.war init -d /opt/gerrit

 

[sudo] password for whatmam: 
Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore
[2021-12-01 06:33:08,345] [main] INFO  com.google.gerrit.server.config.GerritServerConfigProvider : No /opt/gerrit/etc/gerrit.config; assuming defaults

*** Gerrit Code Review 3.4.1
*** 

Create '/opt/gerrit'           [Y/n]? Y

*** Git Repositories
*** 

Location of Git repositories   [git]: repositories

*** 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]? y
Username HTTP header           [SM_USER]: 
SSO logout URL                 : 
Enable signed push support     [y/N]?  

*** Review Labels
*** 

Install Verified label         [y/N]? y

*** Email Delivery
*** 

SMTP server hostname           [localhost]: smtp.gmail.com    
SMTP server port               [(default)]: 465     
SMTP encryption                [none/?]: SSL
SMTP username                  [root]: whatmam@gmail.com
whatmam@gmail.com's password   : 
              confirm password : 

*** Container Process
*** 

Run as                         [root]: 
Java runtime                   [/usr/lib/jvm/java-11-openjdk-amd64]: 
Copy gerrit-3.4.1.war to /opt/gerrit/bin/gerrit.war [Y/n]? Y
Copying gerrit-3.4.1.war to /opt/gerrit/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]? y
Proxy uses SSL (https://)      [y/N]? 
Subdirectory on proxy server   [/]: 
Listen on address              [*]: 192.168.111.130
Listen on port                 [8081]: 8989
Canonical URL                  [http://192.168.111.130/]: 

*** Cache
*** 


*** Plugins
*** 

Installing plugins.
Install plugin codemirror-editor version v3.4.1 [y/N]? y
Installed codemirror-editor v3.4.1
Install plugin commit-message-length-validator version v3.4.1 [y/N]? y
Installed commit-message-length-validator v3.4.1
Install plugin delete-project version v3.4.1 [y/N]? y
Installed delete-project v3.4.1
Install plugin download-commands version v3.4.1 [y/N]? y
Installed download-commands v3.4.1
Install plugin gitiles version v3.4.1 [y/N]? y
Installed gitiles v3.4.1
Install plugin hooks version v3.4.1 [y/N]? y
Installed hooks v3.4.1
Install plugin plugin-manager version v3.4.1 [y/N]? y
Installed plugin-manager v3.4.1
Install plugin replication version v3.4.1 [y/N]? y
Installed replication v3.4.1
Install plugin reviewnotes version v3.4.1 [y/N]? y
Installed reviewnotes v3.4.1
Install plugin singleusergroup version v3.4.1 [y/N]? y
Installed singleusergroup v3.4.1
Install plugin webhooks version v3.4.1 [y/N]? y
Installed webhooks v3.4.1
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 /opt/gerrit
Init complete, reindexing accounts with: reindex --site-path /opt/gerrit --threads 1 --index accountsReindexed 0 documents in accounts index in 0.0s (0.0/s)
Index accounts in version 11 is ready
Warning: InterruptedException
java.lang.InterruptedException
at java.base/java.lang.Object.wait(Native Method)
at java.base/java.lang.Thread.join(Thread.java:1308)
at org.h2.util.MathUtils.getSecureRandom(MathUtils.java:105)
at org.h2.util.MathUtils.secureRandomBytes(MathUtils.java:307)
at org.h2.store.FileLock.setUniqueId(FileLock.java:315)
at org.h2.store.FileLock.lockFile(FileLock.java:345)
at org.h2.store.FileLock.lock(FileLock.java:136)
at org.h2.engine.Database.open(Database.java:622)
at org.h2.engine.Database.openDatabase(Database.java:260)
at org.h2.engine.Database.<init>(Database.java:254)
at org.h2.engine.Engine.openSession(Engine.java:57)
at org.h2.engine.Engine.openSession(Engine.java:164)
at org.h2.engine.Engine.createSessionAndValidate(Engine.java:142)
at org.h2.engine.Engine.createSession(Engine.java:125)
at org.h2.engine.Engine.createSession(Engine.java:27)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:331)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:107)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:91)
at org.h2.Driver.connect(Driver.java:74)
at com.google.gerrit.server.cache.h2.H2CacheImpl$SqlHandle.<init>(H2CacheImpl.java:679)
at com.google.gerrit.server.cache.h2.H2CacheImpl$SqlStore.acquire(H2CacheImpl.java:647)
at com.google.gerrit.server.cache.h2.H2CacheImpl$SqlStore.buildBloomFilter(H2CacheImpl.java:365)
at com.google.gerrit.server.cache.h2.H2CacheImpl$SqlStore.open(H2CacheImpl.java:337)
at com.google.gerrit.server.cache.h2.H2CacheImpl.start(H2CacheImpl.java:197)
at com.google.gerrit.server.logging.LoggingContextAwareRunnable.run(LoggingContextAwareRunnable.java:113)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Collecting projects:    2 changes with: reindex --site-path /opt/gerrit --threads 1 --index changes
Reindexing changes: project-slices: 100% (2/2), done    
Reindexed 0 documents in changes index in 0.0s (0.0/s)
Index changes in version 61 is ready
Reindexing groups:      100% (2/2)ith: reindex --site-path /opt/gerrit --threads 1 --index groups
Reindexed 2 documents in groups index in 0.2s (11.4/s)
Index groups in version 8 is ready
Reindexing projects:    100% (2/2) with: reindex --site-path /opt/gerrit --threads 1 --index projects
Reindexed 2 documents in projects index in 0.1s (14.5/s)
Index projects in version 4 is ready
Executing /opt/gerrit/bin/gerrit.sh start
Starting Gerrit Code Review: OK
Waiting for server on 192.168.111.130:80 ... OK
Opening http://192.168.111.130/#/admin/projects/ ...Gtk-Message: 06:47:49.754: Failed to load module "canberra-gtk-module"
OK

후에 다시 수정해서 사용하기에 기본적으로 Setting 해준다. plugin은 무지성 깔아보려한다.

 

 

5. Gerrit 계정 추가

$ sudo htpasswd -c /opt/gerrit/etc/passwords "whatmam"
$		### 	추가로 계정 추가시 -c option 제거

htpasswd로 생성하는 계정은 apache에서 인증을 위해 사용하는 계정이며, gerrit은 처음 생성된 계정(uid 1000000)을 administrator로 인식한다.

 

* Port number 

Gerrit port : 8989

apache port : 8081

6. Apache VirtualHost File 생성

$ sudo vi /etc/apache2/sites-available/001-whatmam.conf 


<VirtualHost *:8989>						### Gerrit Port 		
        ServerName 192.168.111.130				### Gerrit address
       
        ProxyRequests Off
        ProxyVia Off
        ProxyPreserveHost On

        <Proxy *>
                Order deny,allow
                Allow from all		
        </Proxy>

        <Location /login/>
                AuthType Basic
                AuthName "Gerrit Code Review"
                Require valid-user
                AuthUserFile /opt/gerrit/etc/passwords		### Gerrit passwords path 지정
        </Location>

        AllowEncodedSlashes On
        ProxyPass / http://192.168.111.130:8081/ nocanon	### nocanon option 필수
        ProxyPassReverse / http://192.168.111.130:8081/
</VirtualHost>

 

7. Apache site-enabled 활성화

$ cd /etc/apache2/sites-enabled/
$ sudo ln -s ../sites-available/001-whatmam.conf ./001-whatmam.conf
$ sudo a2ensite 001-whatmam.conf
$	### a2ensite는 sites-available에 있는 Setting 활성화 (00X- 의 형식을지켜야함)
$	### Linking되어 있으면 굳이 쓸필요 없다.

 

8. Apache port 설정

$ sudo vi /etc/apache2/ports.conf


# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

NameVirtualHost *:8989			### Gerrit port 추가
Listen 8989

<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

 

9. Gerrit Configure file 수정

$ vi /opt/gerrit/etc/gerrit.config


[gerrit]
        basePath = repositories
        canonicalWebUrl = http://192.168.111.130:8989/				### Gerrit URL & port
        serverId = a9a19cf0-f784-441c-be5a-f4f821df29cc
[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 = root
        javaHome = /usr/lib/jvm/java-11-openjdk-amd64
[index]
        type = lucene
[auth]
        type = HTTP
#       httpHeader = SM_USER
        logoutUrl = http://aa:aa@192.168.111.130:8989/login/		###  http특성으로 인한 Gerrit 버그 해결
[receive]
        enableSignedPush = false
[sendemail]
        smtpServer = smtp.gmail.com
        smtpServerPort = 465
        smtpEncryption = SSL
        smtpUser = whatmam@gmail.com
[sshd]
        listenAddress = *:29418
[httpd]
        listenUrl = proxy-http://192.168.111.130:8081/				### Apache port
[cache]
        directory = cache

logoutUrl에 'aa:aa' 부분이 빠지면 로그아웃이 되지않는 현상이 발생함. 'aa'라는 계정으로 login page접근하겠다는 의미로 로그아웃을 시켜버림.

 

10. Apache & gerrit restart

$ sudo service apache2 restart
$ sudo /opt/gerrit/bin/gerrit.sh restart

 

11. Gerrit 접속

"http://192.168.111.130:8989/" 로 접속해보겠다.

 

 

 

접속이 완료 되었다. 이것저것 둘러보고

다음에는

 - Repogitory 생성 및 clone push 

 - 계정 새성 및 권한 지정

 - 코드 리뷰를 위한 push 

 

알아보도록 하자!

'Gerrit' 카테고리의 다른 글

Gerrit 계정 권한 설정  (0) 2021.12.22
Gerrit Porject 생성 및 Push  (1) 2021.12.05

+ Recent posts