开始前请先确保已安装 Java ,Gerrit 是基于java 的 , 安装 JDK
CentOS:
[root@CentOS ~]# java -version
java version "1.7.0_101"
OpenJDK Runtime Environment (rhel-2.6.6.1.el6_7-i386 u101-b00)
OpenJDK Client VM (build 24.95-b01, mixed mode, sharing)
Ubuntu:
[root@Ubuntu ~]# java -version
java version "1.7.0_101"
OpenJDK Runtime Environment (IcedTea 2.6.6) (7u101-2.6.6-0ubuntu0.14.04.1)
OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)
1 创建Gerrit 使用的用户
CentOS
[root@CentOS ~]# groupadd -g 10001 gerrit
[root@CentOS ~]# useradd -u 10001 -d /home/gerrit -g 10001 -m gerrit
Debain/Ubuntu
[root@Ubuntu ~]# adduser --disabled-login --gecos 'Gerrit' gerrit
2 下载 gerrit war包
wget https://www.gerritcodereview.com/download/gerrit-2.12.2.war
3 安装Gerrit依赖
CentOS :
貌似没有
Debain/Ubuntu:
# apt-get install default-jre daemon
4 创建 Gerrit 数据库
安装Gitlab中已经安装了MySQL,下面只需要创建库就可以了。注意此处的 gerrituser , gerritpass 为新表拥有权限的用户名和密码
$ mysql -u root -p
> create database gerritdb;
> grant all on gerritdb.* to 'gerrituser'@'localhost' identified by 'gerritpass';
安装gerrit
enter the folder of gerrit war
su gerrit 或者在 root 下运行再更改用户我是在 root 下操作的,由于权限的问题才安装完启动的时候报错了
# java -jar gerrit-2.12.2.war init -d /home/gerrit/gerrit
root@Ubuntu:/home/gerrit# java -jar /usr/local/src/gerrit-2.12.2.war init -d /home/gerrit/gerrt_sites
Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore
[2016-05-24 03:56:10,059] [main] INFO com.google.gerrit.server.config.GerritServerConfigProvider : No /home/gerrit/gerrt_sites/etc/gerrit.config; assuming defaults
*** Gerrit Code Review 2.12.2
***
Create '/home/gerrit/gerrt_sites' [Y/n]?
*** 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]?
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 :
*** Index
***
Type [LUCENE/?]:
*** User Authentication
***
Authentication method [OPENID/?]: http
Get username from custom HTTP header [y/N]?
SSO logout URL :
Enable signed push support [y/N]?
*** 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 [root]: gerrit
Java runtime [/usr/lib/jvm/java-7-openjdk-amd64/jre]:
Copy gerrit-2.12.2.war to /home/gerrit/gerrt_sites/bin/gerrit.war [Y/n]?
Copying gerrit-2.12.2.war to /home/gerrit/gerrt_sites/bin/gerrit.war
*** SSH Daemon
***
Listen on address [*]:
Listen on port [29418]:
Gerrit Code Review is not shipped with Bouncy Castle Crypto SSL v152
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-152.jar ... Failed to clean up lib: /home/gerrit/gerrt_sites/lib/bcpkix-jdk15on-152.jar
!! FAIL !!
error: http://www.bouncycastle.org/download/bcpkix-jdk15on-152.jar: 302 Found
Please download:
http://www.bouncycastle.org/download/bcpkix-jdk15on-152.jar
and save as:
/home/gerrit/gerrt_sites/lib/bcpkix-jdk15on-152.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 [/]:
Listen on address [*]:
Listen on port [8081]:
Canonical URL [http://46.101.176.131/]: 192.157.245.90
*** Plugins
***
Installing plugins.
Install plugin singleusergroup version v2.12.2 [y/N]?
Install plugin commit-message-length-validator version v2.12.2 [y/N]?
Install plugin reviewnotes version v2.12.2 [y/N]?
Install plugin replication version v2.12.2 [y/N]?
Install plugin download-commands version v2.12.2 [y/N]?
Initializing plugins.
No plugins found with init steps.
Initialized /home/gerrit/gerrt_sites
Executing /home/gerrit/gerrt_sites/bin/gerrit.sh start
Starting Gerrit Code Review: cat: /home/gerrit/gerrt_sites/logs/gerrit.pid: No such file or directory
FAILED
error: cannot start Gerrit: exit status 1
Exception in thread "main" java.lang.NullPointerException
at com.google.gerrit.pgm.init.api.InitUtil.isAnyAddress(InitUtil.java:196)
at com.google.gerrit.pgm.init.api.InitUtil.toURI(InitUtil.java:184)
at com.google.gerrit.pgm.init.Browser.open(Browser.java:56)
at com.google.gerrit.pgm.Init.start(Init.java:162)
at com.google.gerrit.pgm.Init.afterInit(Init.java:121)
at com.google.gerrit.pgm.init.BaseInit.run(BaseInit.java:138)
at com.google.gerrit.pgm.util.AbstractProgram.main(AbstractProgram.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.google.gerrit.launcher.GerritLauncher.invokeProgram(GerritLauncher.java:159)
at com.google.gerrit.launcher.GerritLauncher.mainImpl(GerritLauncher.java:100)
at com.google.gerrit.launcher.GerritLauncher.main(GerritLauncher.java:56)
at Main.main(Main.java:25)
root@Ubuntu:/home/gerrit# chown -R gerrit: ./*
[root@Ubuntu ~]#:/home/gerrit# gerrt_sites/bin/gerrit.sh start
Starting Gerrit Code Review: OK
然后修改一下 canonicalWebUrl 的配置 贴上一份我成功的配置
[root@Ubuntu ~]# cat /home/gerrit/gerrit_sites/etc/gerrit.config
[gerrit]
basePath = git
canonicalWebUrl = http://gerrit.world-alive.win/
[database]
type = mysql
hostname = localhost
database = gerritdb
username = gerrituser
[index]
type = LUCENE
[auth]
type = HTTP
[receive]
enableSignedPush = false
[sendemail]
smtpServer = localhost
[container]
user = gerrit
javaHome = /usr/lib/jvm/java-7-openjdk-amd64/jre
[sshd]
listenAddress = *:29418
[httpd]
listenUrl = proxy-http://*:8081/
[cache]
directory = cache
修改后重启 Gerrit
[root@Ubuntu ~]# /home/gerrit/gerrit_sites/bin/gerrit.sh restart
此时浏览器访问 gerrit.world-alive.win:8081
[root@Ubuntu ~]# cat /etc/apache2/sites-enabled/gerrit.conf
<VirtualHost *:80>
#-->客户端访问:http:10.10.90.160:8081 会转到gerrit服务器的地址:http://10.10.90.160:8080 上
ServerName gerrit.world-alive.win
ProxyRequests Off
ProxyVia Off
ProxyPreserveHost On
#AllowEncodedSlashes On
RewriteEngine On
RewriteRule ^/(.*) http://192.157.245.90:8081/$1 [NE,P]
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location /login/>
AuthType Basic
AuthName "Gerrit Code Review"
Require valid-user
AuthBasicProvider file
AuthUserFile /home/gerrit/gerrt_sites/etc/passwd
</Location>
#AllowEncodedSlashes On
ProxyPass / http://192.157.245.90:8081/
ProxyPassReverse / http://192.157.245.90:8081/
</VirtualHost>
[root@Ubuntu ~]# su gerrit
[root@Ubuntu ~]# touch /home/gerrit/gerrt_sites/etc/passwd
[root@Ubuntu ~]# htpasswd -c /home/gerrit/gerrt_sites/etc/passwd admin
New password:
Re-type new password:
重启 Apache
[root@Ubuntu ~]# service apache2 restart
刷新 出现登录
没有评论