Moon Light Box

Time is Money

Linux - Install Gerrit in CentOS 7

| Comments

Step 1. Set Mysql Gerrit Account

# mysql -u root -p

CREATE USER 'gerrit2'@'localhost' IDENTIFIED BY 'secret';
SET PASSWORD FOR 'gerrit2'@'localhost' = PASSWORD('XXXXXX'); // your password
GRANT ALL ON reviewdb.* TO 'gerrit2'@'localhost';


Step 2. Add gerrit2 User.

# sudo useradd -m gerrit2

Step 3. Install Gerrit

# su - gerrit2
# wget
# java -jar gerrit-2.12.war init -d /home/gerrit2/gerrit

Create '/home/gerrit2/gerrit'  [Y/n]? Y
Location of Git repositories   [git]:ENTER
Database server type           [h2]: mysql
Gerrit Code Review is not shipped with MySQL Connector/J 5.1.21
**  This library is required for your configuration. **
Download and install it now [Y/n]?Y
Server hostname                [localhost]:
Server port                    [(mysql default)]:
Database name                  [reviewdb]:
Database username              [gerrit2]:
gerrit2's password             :
              confirm password :
Type                           [LUCENE/?]: ENTER
Authentication method          [OPENID/?]: http
Get username from custom HTTP header [y/N]? N
SSO logout URL                 :ENTER
Enable signed push support     [y/N]? N
Install Verified label         [y/N]? ENTER
SMTP server hostname           [localhost]: ENTER
SMTP server port               [(default)]: ENTER
SMTP encryption                [NONE/?]: ENTER
SMTP username                  : ENTER
Run as                         [gerrit2]:
Java runtime                   [/usr/lib/jvm/java-1.8.0-openjdk-]: ENTER
Copy gerrit-2.12.war to /home/gerrit2/gerrit/bin/gerrit.war [Y/n]? y
Listen on address              [*]: ENTER
Listen on port                 [29418]: ENTER
Download and install it now [Y/n]? y
Behind reverse proxy           [y/N]? y
Proxy uses SSL (https://)      [y/N]? N
Subdirectory on proxy server   [/]: ENTER
Listen on address              [*]: ENTER
Listen on port                 [8081]: ENTER
Canonical URL                  [http://localhost/]:   // change to your IP
Install plugin singleusergroup version v2.12 [y/N]? y
Install plugin commit-message-length-validator version v2.12 [y/N]? y
Install plugin reviewnotes version v2.12 [y/N]? y
Install plugin replication version v2.12 [y/N]? y
Install plugin download-commands version v2.12 [y/N]? y

Step 4. Checked and Modified gerrit.config Configuration

## vim  /home/gerrit2/gerrit/etc/gerrit.config
        basePath = git
        canonicalWebUrl =  // change to your IP
        type = mysql
        hostname = localhost
        database = reviewdb
        username = gerrit2
        type = LUCENE
        type = HTTP
        enableSignedPush = false
        smtpServer = localhost
        user = gerrit2
        javaHome = /usr/lib/jvm/java-1.8.0-openjdk-
        listenAddress = *:29418
        listenUrl = proxy-http://*:8081/
        directory = cache
# java -jar gerrit-2.12.war reindex -d /home/gerrit2/gerrit
# /home/gerrit2/gerrit/bin/ start

Step 5. Install Apache

# sudo yum install httpd httpd-tools openssl mod_ssl
# sudo vim /etc/httpd/conf/httpd.conf
ServerName  // change to your IP
# sudo vim /etc/httpd/conf.d/options.conf

TraceEnable off

## Disable Signature
ServerSignature Off

## Disable Banner
ServerTokens Prod
# sudo vim /etc/httpd/conf.d/vhosts.conf

# Load my vhosts
IncludeOptional vhosts.d/*.conf
# sudo mkdir /etc/httpd/vhosts.d
# sudo systemctl restart httpd
# sudo systemctl status httpd
# sudo systemctl enable httpd

Step 6. Set Apache Proxy

# sudo vim /etc/httpd/vhosts.d/gerrit.conf

<VirtualHost> // change to your IP
    ServerName   // change to your IP

    ProxyRequests Off
    ProxyVia Off
    ProxyPreserveHost On

    <Proxy *>
            Order deny,allow
            Allow from all

    <Location /login/>
            AuthType Basic
            AuthName "Gerrit Code Review"
            Require valid-user
            AuthUserFile '/etc/httpd/gerrit.htpasswd'

    AllowEncodedSlashes On
    ProxyPass / nocanon  // change to your IP

Step 7. Create Gerrit Account

# sudo chmod 755 /home/gerrit2
# sudo htpasswd -c /home/gerrit2/gerrit.htpasswd admin  // the first account is gerrit administrator

New password:
Re-type new password:
Adding password for user admin



comments powered by Disqus