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
CREATE DATABASE reviewdb;
GRANT ALL ON reviewdb.* TO 'gerrit2'@'localhost';
FLUSH PRIVILEGES;

exit

Step 2. Add gerrit2 User.

# sudo useradd -m gerrit2

Step 3. Install Gerrit

# su - gerrit2
# wget http://www.gerritcodereview.com/download/gerrit-2.12.war
# 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-1.8.0.71-2.b15.el7_2.x86_64/jre]: 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/]: http://10.10.10.10/   // 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
[gerrit]
        basePath = git
        canonicalWebUrl = http://10.10.10.10/  // change to your IP
[database]
        type = mysql
        hostname = localhost
        database = reviewdb
        username = gerrit2
[index]
        type = LUCENE
[auth]
        type = HTTP
[receive]
        enableSignedPush = false
[sendemail]
        smtpServer = localhost
[container]
        user = gerrit2
        javaHome = /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.71-2.b15.el7_2.x86_64/jre
[sshd]
        listenAddress = *:29418
[httpd]
        listenUrl = proxy-http://*:8081/
[cache]
        directory = cache
        
# java -jar gerrit-2.12.war reindex -d /home/gerrit2/gerrit
# /home/gerrit2/gerrit/bin/gerrit.sh start

Step 5. Install Apache

# sudo yum install httpd httpd-tools openssl mod_ssl
# sudo vim /etc/httpd/conf/httpd.conf
ServerName 10.10.10.10:80  // 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 10.10.10.10:80> // change to your IP
    ServerName 10.10.10.10   // change to your IP

    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 '/etc/httpd/gerrit.htpasswd'
    </Location>

    AllowEncodedSlashes On
    ProxyPass / http://10.10.10.10:8081/ nocanon  // change to your IP
</VirtualHost>

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

Reference:

https://www.rosehosting.com/blog/how-to-install-gerrit2-on-a-centos-7-linux-vps/
http://coderanch.net/15
https://gerrit-review.googlesource.com/Documentation/

Comments

comments powered by Disqus