Gerrit Server Setup (GIT+GERRIT+POSTGRESQL+LDAP)

Source: Internet
Author: User
Tags http authentication ldap openid psql postgres createdb postgres database server port


Gerrit Introduction


Gerrit is a web-based code review tool built on Git. As you all know, Git is a distributed code versioning tool that is often used in collaborative development work environments where programmers submit their own modified code to the local repository and then push it to the remote central repository, as shown in Figure 1. In this process, the code submission is not audited, for the team distributed in multiple locations, can not review each other, comment on other people's Code, very bad for code quality control. And Gerrit is the tool for code review, the programmer push to the central repository of code, the first to go through the team of reviewers review, is accepted before the actual submission to the repository, see Figure 2.


Gerrit Server Building (GIT+GERRIT+POSTGRESQL+LDAP) 1 overview


Operating system Ubuntu, need to install


    • Git, code version management
    • Java, minimum 1.7 version, Gerrit installation package is a war package
    • Database, Gerrit support H2 (built-in)/Mysql/postgresql, this installation chooses PostgreSQL, fully open source and suitable for large-scale data deployment
    • Identity authentication, the premise of audit is to do identity authentication to login Web,gerrit support OPENID/HTTP/LDAP, this installation has been set up a good LDAP, but will explain the HTTP authentication, need Apache to do reverse proxy
2 git installation
sudo apt-get install git
3 JDK8 Installation


Ubuntu14.10 and above version of the Ubuntu official software in mind has openjdk Java 8, can be installed directly with Apt-get, the lower version from the PPA (Personal package Archives personal packages set) installed.


sudo add-apt-repository ppa:openjdk-r/ppasudo apt-get update sudo apt-get install openjdk-8-jdk


Configuring Java Environment variables


    • Path, which specifies the command search path, which, when executed under the shell, finds the appropriate command program in the path specified by the path variable, such as Java/javac
    • CLASSPATH, specifying a class search path through which the JVM looks for classes
    • Java_home, other software finds the JDK's installation directory through it
 
vi /etc/profile
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_21  
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$CLASSPATH  
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
source /etc/profile
java -version


If you have more than one JDK installed, select a default


sudo update-alternatives --config javasudo update-alternatives --config java
4 PostgreSQL Installation
sudo apt-get install postgresql


After initial installation, Linux system users, databases, and database users named Postgres are generated by default (as database administrators), first modifying the Postgres database user's password, and then increasing the database required by Gerrit


 
sudo -u postgres psql
postgres=# \password postgres
(input password twice)
postgres=# \q
 
sudo -u postgres createuser -RDIElPS gerrit2
sudo -u postgres psql
postgres=# \password gerrit2
(input password twice)
sudo -u postgres createdb -E UTF-8 -O gerrit2 reviewdb
5 Gerrit Installation


Download Gerrit's installation package from the official website, in order to facilitate renaming to Gerrit.war, it is recommended to create a Linux user to install, I installed in Gerrit2 user's Review_site directory


sudo adduser gerrit2sudo-d /home/gerrit2/review_site


Many configurations are then made, most by default, with the database and identity authentication, which can also be modified in the ~/review_site/etc/gerrit.config file after installation is complete.



The following is someone else's configuration, he is using Mysql+nginx to do HTTP authentication, posted here just let everyone look at the installation of the approximate steps, for reference only:


 
 
# java -jar gerrit-2.8.war init -d /etc/gerrit/

*** Gerrit Code Review 2.8
***

Create ‘/etc/gerrit‘           [Y/n]? y

*** Git Repositories
***

Location of Git repositories   [git]:

*** SQL Database
***

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
Downloading http://repo2.maven.org/maven2/mysql/mysql-connector-java/5.1.21/mysql-connector-java-5.1.21.jar ... OK
Checksum mysql-connector-java-5.1.21.jar OK
Server hostname                [localhost]:
Server port                    [(mysql default)]:
Database name                  [reviewdb]: gerritdb
Database username              [root]: gerrituser
gerrituser‘s password          :
              confirm password :

*** User Authentication
***

Authentication method          [OPENID/?]: http
Get username from custom HTTP header [y/N]? n
SSO logout URL                 :

*** Email Delivery
***

SMTP server hostname           [localhost]: smtp.googlemail.com
SMTP server port               [(default)]: 587
SMTP encryption                [NONE/?]: tls
SMTP username                  [root]: gerrit@thstack.com
review@thstack.com‘s password  :
              confirm password :

*** Container Process
***

Run as                         [root]:
Java runtime                   [/usr/lib/jvm/java-6-openjdk-amd64/jre]:
Copy gerrit-2.8.war to /etc/gerrit/bin/gerrit.war [Y/n]? y
Copying gerrit-2.8.war to /etc/gerrit/bin/gerrit.war

*** SSH Daemon
***

Listen on address              [*]:
Listen on port                 [29418]:

Gerrit Code Review is not shipped with Bouncy Castle Crypto v144
  If available, Gerrit can take advantage of features
  in the library, but will also function without it.
Download and install it now [Y/n]? y
Downloading http://www.bouncycastle.org/download/bcprov-jdk16-144.jar ... OK
Checksum bcprov-jdk16-144.jar OK
Generating SSH host key ... rsa... dsa... done

*** HTTP Daemon
***

Behind reverse proxy           [y/N]? y
Proxy uses SSL (https://)      [y/N]? n
Subdirectory on proxy server   [/]:
Listen on address              [*]:
Listen on port                 [8081]: 8082
Canonical URL                  [http://www.thstack.com/]: http://review.thstack.com/

*** Plugins
***

Install plugin reviewnotes version v2.8 [y/N]? y
Install plugin download-commands version v2.8 [y/N]? y
Install plugin replication version v2.8 [y/N]? y
Install plugin commit-message-length-validator version v2.8 [y/N]? y

Initialized /etc/gerrit
Executing /etc/gerrit/bin/gerrit.sh start
Starting Gerrit Code Review: OK
Waiting for server on review.thstack.com:80 ... OK
Opening http://review.thstack.com/#/admin/projects/ ...FAILED
Open Gerrit with a JavaScript capable browser:

http://review.thstack.com/#/admin/projects/


I tried to use Apache to do reverse proxy, need to configure but configuration ~/review_site/etc/gerrit.config and/etc/apache2/httpd.conf, or a bit of a problem, always reported authorization Header error, finally selected LDAP authentication, LDAP server is the company has been set up, directly used.



Finally, my ~/review_site/etc/gerrit.config is as follows:


[gerrit] basePath = git
        canonicalWebUrl = https://localhost:8080 [database] type = postgresql
        hostname = localhost
        database = reviewdb
        username = gerrit2 [auth] type = LDAP [ldap] server = ldaps://xx:xx accountBase = xx
        accountPattern = (&(objectClass=person)(uid=${username})) accountFullName = cn
        accountEmailAddress = mail
        accountSshUserName = uid
        referral = follow
        groupBase = xx
        groupScope = one [sendemail] smtpServer = localhost from = ${user} [review] <xx@xx.com> [container] user = gerrit
        javaHome = /usr/lib/jvm/java-8-openjdk-amd64/jre [sshd] listenAddress = *:29418 [download] scheme = ssh
        scheme = http [httpd] listenUrl = proxy-http://localhost:8080 [cache] directory = cache [http] proxy = http://xx:xx [gitweb] cgi = /usr/lib/cgi-bin/gitweb.cgi [cache "web_sessions"] maxAge = 1 month


After configuration, start Gerrit, you need to use absolute path


start


In the browser input http://localhost:8080 pop-up Gerrit page, finally succeeded!



Gerrit Server Setup (GIT+GERRIT+POSTGRESQL+LDAP)


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.