Setting up the environment: Ubuntu 14.04
First, the Environment preparation
1.Java Environment
Gerrit dependent, used to install the Gerrit environment.
Download: jdk-7u79-linux-x64.tar.gz http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
Installation: sudo tar zxvf./jdk-7u79-linux-x64.tar.gz-c/opt
Configuration: Vim ~/.BASHRC
Export java_home=/opt/jdk1.7.0_79
Export Jre_home= $JAVA _home/jre
Export classpath= $JAVA _home/lib: $JRE _home/lib: $CLASSPATH
Export path= $JAVA _home/bin: $JRE _home/bin: $PATH
Verification: Java-version
Java Version "1.7.0_79"
Java (TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot (TM) 64-bit Server VM (build 24.79-b02, Mixed mode)
2.git Environment
Gerrit dependency, used to manipulate git repository.
installation:sudo apt-get install git
Verification: Git
Usage:git [--version] [--help] [-c <path>] [-C Name=value]
3.gerrit Environment
Download: Gerrit 2.12.4 Https://www.gerritcodereview.com/download/gerrit-2.12.4.war
4.APACHE2 Environment
Installation: sudo apt-get install apache2
Verification: Sudo/etc/init.d/apache2 Start
5.gerrit Admin Account
Gerrit dependency, used to manage Gerrit.
sudo adduser Gerrit
sudo passwd Gerrit
Su Gerrit
Second, installation and configuration Gerrit
1. Configure Gerrit
Default installation: Java-jar Gerrit-2.12.4.war init --batch -D ~/review_site
Update configuration file:sudo vim ~/review_site/etc/gerrit.config
[Gerrit] BasePath=git #默认gerrit对应的git库 canonicalweburl= http://localhost:8081/#gerrit Web Management interface[Database] Type=H2 #h2数据库 Database= db/reviewdb #数据库路径 [index] Type=Lucene[auth] Type= http #auth模式, the default is OpenID, configured as HTTP, requires Apache configuration reverse proxy [receive] Enablesignedpush=false[SendEmail] SmtpServer=Localhost[container] User=Gerrit #linux user for Gerrit Javahome=/opt/jdk1.7.0_79/JRE #java home[sshd] listenaddress= *:29418 #default Gerrit Port[httpd] Listenurl= http://*:8081/[Cache] Directory=Cache[http] Proxy= http://localhost:8080 #proxy ServerProxyusername =gerrit1 #proxy User & password Proxypassword=123456789
2. Configuring the Apache2 Reverse Proxy
Open SSL, Proxy and other modules:
Cd/etc/apache2/mods-enabled
Ln-s. /mods-available/proxy.load
Ln-s. /mods-available/proxy.conf
Ln-s. /mods-available/proxy_http.load
Ln-s. /mods-available/proxy_balancer.conf
Ln-s. /mods-available/proxy_balancer.load
Ln-s. /mods-available/rewrite.load
Ln-s. /mods-available/ssl.conf
Ln-s. /mods-available/ssl.load
Ln-s. /mods-available/socache_shmcb.load #
Ln-s. /mods-available/slotmem_shm.load #
Update configuration file:sudo vim/etc/apache2/sites-enabled/gerrit-httpd.conf
ServerName192.168.199.112 #your Local IP<virtualhost *:8080>proxyrequests off Proxyvia off Proxypreservehost on Allowencodedslashes on Rewriteengine on Rewrite Rule^/(. *) http://192.168.199.112:8081/$1 [ne,p] #rewrite rule for proxy<proxy *>Order deny,allow allow from all</Proxy> <location/Login/>authtype Basic AuthName"Gerrit Code Review"Require Valid-User AuthbasicproviderfileAuthUserFile/home/gerrit/review_site/etc/passwd #password file for Gerrit</Location>Proxypass/http://192.168.199.112:8081/</VirtualHost>
3. Configure Gerrit account password
Touch ~/review_site/etc/passwd
Htpasswd-b ~/review_site/etc/passwd gerrit1 123456789
4. Start gerrit& boot apache2
sudo ~/review_site/bin/gerrit.sh start
Sudo/etc/init.d/apache2 start
5. Access the Gerrit management interface http://localhost:8080/
For the first visit, you need to enter the GERRIT1 and password set in step 3rd, which will act as the Gerrit Administrator account. You can set the fullname:gerritadmin after entering.
Third, how to use Gerrit
1. Add a project
To add a new project using Gerrit: (for opening new projects and using Gerrit)
Ssh-p 29418 gerrit1@localhost Gerrit create-project --empty-commit--name demo-project #建议采用管理界面添加
Or use the Gerrit management interface
Add existing Items using Gerrit: (for use with Gerrit under existing projects)
Ssh-p 29418 gerrit1@localhost Gerrit Create-project--name exist-project #建议采用管理界面添加
Or use the Gerrit management interface
The existing project is then associated with the Exist-project established on the Gerrit, which is managed by pushing the code base code into Gerrit.
CD ~/gitcode/exist-project
git push ssh://[email protected]:29418/exist-project *:*
2. Generate Sshkey
Generate Sshkey in the Development Account to use as a connection to the Gerrit server.
ssh-keygen-t RSA #生成sshkey
LS ~/.ssh/#可查看sshkey
Cat ~/.ssh/id_rsa.pub #查看sshkey
ssh-rsa aaaab3nzac1yc2eaaaadaqabaaabaqcj1xdqjnxbn39oeacjoxe8fklbjrpgs1cchrthwbytz4a5kxaaxyzcd94gud9uxxzzkcr6y90mwuj+ jkkxctlquiwj73qiipwq3re08m049w4xxdfgnu/jyti9dptwbsf0dwfjlqquutits+b1tkz7jr7+wipbz22aihwrvy4vcvccdihy/ bnccbvcfgk9u8f+x+rom+dkogfucbnxwejydqf0wy/ d13q5gp9oaxmiod05t3gtojrwytx2cvfmk4je9htcudorrznfvhqeblba7emkpiudplho7esmpwj/ wob1wnktwhouzbmt0a6hhpmnwyp2wijebea1kzthlixt [email protected]
3. Add Sshkey to Gerrit server
This step is similar to the GIT process, and id_rsa.pub content is uploaded to git repository,gerrit to help us manage git repository.
3. Pull replacement code and configure Git hooks
Verify Sshkey is configured successfully: SSH [email protected]-P 29418
The authenticity of host'[localhost]:29418 ([127.0.0.1]:29418)'Aa't be established.RSA key fingerprint is db: -: 3d:c2:94: -: b5:8d:ac:bc:b5:9e:2f: the: 5f:4a. Is you sure want to continue connecting (yes/no)?Yes warning:permanently added'[localhost]:29418'(RSA) to the list of known hosts. Welcome to Gerrit Code Review * * * * *Hi User, you had successfully connected over SSH. Unfortunately, interactive shells is disabled. To clone a hosted Git repository, Use:git cloneSSH://gerrit1@localhost: 29418/repository_name.git
Pull substitution code: Git clone ssh://[email protected]:29418/demo-project
update githooks: gitdir=$ (git rev-parse--git-dir); Scp-p-P 29418 [email protected]:hooks/commit-msg ${gitdir}/hooks/
This process is used to add Change-id,gerrit process prerequisites to the commit-msg.
Modify the code and submit it, the push is inconsistent with the original git process, with GIT push origin head:refs/for/master.
Git push Origin head:refs/ for/mastercounting objects:6, Done. Delta compression using up to4threads.compressing objects: -% (3/3), Done. Writing objects: -% (3/3),381bytes |0BYTES/S, Done. Total3(Delta0), reused0(Delta0) remote:processing changes:new:1, Refs:1, Doneremote:remote:New Changes:remote:http://LOCALHOST:8081/4 Append date to Testfileremote:toSSH://[Email Protected]:29418/demo-project* [New Branch] HEAD--refs/ for/master
4. Use Gerrit to complete code review
When the 3rd step completes the push, you can see the change of the current commit code review in the Gerrit management interface.
To view the commits that require code review:
View the details of a submission (reviewer +2 can be submitted via this submission, which can be submitted by abandon):
If the approver +2 is passed, the commit can be submitted.
Reference Links:
Java SDK download:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
Gerrit Code review-releases:https://gerrit-releases.storage.googleapis.com/index.html
Gerrit Code Review-quick Get started guide:https://git.eclipse.org/r/documentation/install-quick.html
Gerrit Code Audit Server Setup whole process http://blog.csdn.net/ganshuyu/article/details/8978614
How to build Gerrit Open source Code review tool