一、准备工作
安装CentOS7操作系统,准备Gerrit软件安装包:gerrit-2.10.war。
安装sendmail:
[root@localhost ~]#yum install -y sendmail
安装apache:
[root@localhost ~]#yum install -y httpd创建一个用户用于安装Gerrit:
[root@localhost ~]#adduser gerrit
二、安装Gerrit
首先切换到gerrit用户:
[root@localhost ~]#su gerrit
[gerrit@localhost root]$cd[gerrit@localhost ~]$
安装Gerrit软件:
[gerrit@localhost ~]$java -jar gerrit-2.10.war init -d review2
*** Gerrit Code Review 2.10
***
Create '/home/gerrit/review2' [Y/n]?
*** Git Repositories
***
Location of Git repositories [git]:
*** SQL Database
***
Database server type [h2]:
*** Index
***
Type [LUCENE/?]:
*** User Authentication
***
Authentication method [OPENID/?]: HTTP
Get username from custom HTTP header [y/N]?
SSO logout URL :
*** Review Labels
***
Install Verified label [y/N]?
*** Email Delivery
***
SMTP server hostname [localhost]:
SMTP server port [(default)]:
SMTP encryption [NONE/?]:
SMTP username :
*** Container Process
***
Run as [gerrit]:
Java runtime [/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75-2.5.4.2.el7_0.x86_64/jre]:
Copy gerrit-2.10.war to /home/gerrit/review2/bin/gerrit.war [Y/n]?
Copying gerrit-2.10.war to /home/gerrit/review2/bin/gerrit.war
*** SSH Daemon
***
Listen on address [*]:
Listen on port [29418]:
Gerrit Code Review is not shipped with Bouncy Castle Crypto SSL v149
If available, Gerrit can take advantage of features
in the library, but will also function without it.
Download and install it now [Y/n]?
Downloading http://www.bouncycastle.org/download/bcpkix-jdk15on-149.jar ... !! FAIL !!
error: www.bouncycastle.org
Please download:
http://www.bouncycastle.org/download/bcpkix-jdk15on-149.jar
and save as:
/home/gerrit/review2/lib/bcpkix-jdk15on-149.jar
Press enter to continue
Continue without this library [Y/n]?
Generating SSH host key ... rsa(simple)... done
*** HTTP Daemon
***
Behind reverse proxy [y/N]? y
Proxy uses SSL (https://) [y/N]?
Subdirectory on proxy server [/]: /gerrit
Listen on address [*]:
Listen on port [8081]:
Canonical URL [http://localhost/gerrit]: http://10.1.5.116/gerrit
*** Plugins
***
Install plugin commit-message-length-validator version v2.10 [y/N]?
Install plugin download-commands version v2.10 [y/N]?
Install plugin replication version v2.10 [y/N]?
Install plugin reviewnotes version v2.10 [y/N]?
Install plugin singleusergroup version v2.10 [y/N]?
Initialized /home/gerrit/review2
Executing /home/gerrit/review2/bin/gerrit.sh start
Starting Gerrit Code Review: OK
Waiting for server on 10.1.5.116:80 ... OK
Opening http://10.1.5.116/gerrit/#/admin/projects/ ...FAILED
Open Gerrit with a JavaScript capable browser:
http://10.1.5.116/gerrit/#/admin/projects/
如果下载bcpkix-jdk15on-149.jar失败,可以手动下载http://www.bouncycastle.org/download/bcpkix-jdk15on-149.jar,再将bcpkix-jdk15on-149.jar放到/home/gerrit/review2/lib/bcpkix-jdk15on-149.jar。
设置gerrit开机启动:
[gerrit@localhost root]$sudo ln -s /home/gerrit/review2/bin/gerrit.sh /etc/init.d/gerrit.sh
[gerrit@localhost root]$sudo chkconfig --level 345 gerrit.sh on
三、配置Apache反向代理
在/etc/httpd/init.d中创建gerrit.conf文件,填入下列内容:
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
SetEnv GIT_PROJECT_ROOT /git-repo/
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
ServerName localhost
ProxyRequests Off
ProxyVia Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location "/gerrit/login/">
AuthType Basic
AuthName "Gerrit Code Review"
AuthBasicProvider file
AuthUserFile /etc/gerrit.passwd
Require valid-user
</Location>
ProxyPass /gerrit http://localhost:8081/gerrit
重启httpd服务:
[root@localhost ~]#service httpd restart
设置httpd开机启动:
[root@localhost ~]#chkconfig --level 345 httpd on