CentOS Gerrit 安装

2016年5月26日

Gerrit安装:

下载安装包,访问http://code.google.com/p/gerrit,本文下载的是gerrit-2.4.war 创建数据库
(本文以MySQL为例)

  1. # mysql -u root -p
  2. mysql> CREATE USER 'gerrit2'@'localhost' IDENTIFIED BY 'gerrit2';
  3. mysql> CREATE DATABASE reviewdb;
  4. mysql> ALTER DATABASE reviewdb charset=latin1;
  5. mysql> GRANT ALL ON reviewdb.* TO 'gerrit2'@'localhost';
  6. mysql> FLUSH PRIVILEGES;
  7. useradd gerrit
  8. wget https://gerrit-releases.storage.googleapis.com/gerrit-2.12.2.war

1.安装gerrit

  1. # cp gerrit-2.12.2.war /home/gerrit
  2. # cd /home/gerrit
  3. # java -jar gerrit-2.12.2.war init -d review_site

2.安装过程一般直接回车即可,主要注意一下地方: 数据库(本文是用MySQL,默认
为H2)

Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore
[2016-05-26 06:28:52,777] [main] INFO  com.google.gerrit.server.config.GerritServerConfigProvider : No /home/gerrit/review_site/etc/gerrit.config; assuming defaults*** Gerrit Code Review 2.12.2
***

Create '/home/gerrit/review_site' [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]?
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]:
Database username              [gerrit]: gerrit2
gerrit2'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                         [gerrit]:
Java runtime                   [/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-0.b14.el6_7.x86_64/jre]:
Copy gerrit-2.12.2.war to review_site/bin/gerrit.war [Y/n]?
Copying gerrit-2.12.2.war to review_site/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: review_site/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/review_site/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://localhost/]:

*** 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/review_site
Executing /home/gerrit/review_site/bin/gerrit.sh start
Starting Gerrit Code Review: OK
Waiting for server on localhost:80 ... OK
Opening http://localhost/#/admin/projects/ ...FAILED
Open Gerrit with a JavaScript capable browser:
http://localhost/#/admin/projects/

修改 gerrit.config 的参数  以nginx 做代理;

cat /home/gerrit/review_site/etc/gerrit.config

  1. [gerrit]
  2. basePath = git
  3. canonicalWebUrl = http://zabbix.world-alive.xyz/gerrit/
  4. [database]
  5. type = mysql
  6. hostname = localhost
  7. database = reviewdb
  8. username = gerrit2
  9. [index]
  10. type = LUCENE
  11. [auth]
  12. type = HTTP
  13. [receive]
  14. enableSignedPush = false
  15. [sendemail]
  16. smtpServer = localhost
  17. [container]
  18. user = gerrit
  19. javaHome = /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-0.b14.el6_7.x86_64/jre
  20. [sshd]
  21. listenAddress = *:29418
  22. [httpd]
  23. listenUrl = proxy-http://*:8081/gerrit/
  24. [cache]
  25. directory = cache
[gerrit@monitoring ~]$ /home/gerrit/review_site/bin/gerrit.sh restart
Stopping Gerrit Code Review: OK
Starting Gerrit Code Review: OK

创建密码文件

  1. mkdir  /usr/local/nginx/passwd/
  2. htpasswd -c /usr/local/nginx/passwd/gerrit2.passwd gerrit2

Nginx  配置文件  添加

  1. location /gerrit/ {
  2. proxy_pass http://127.0.0.1:8081;
  3. proxy_set_header X-Forwarded-For $remote_addr;
  4. proxy_set_header Host $host;
  5. auth_basic "Gerrit Code Review";
  6. auth_basic_user_file /usr/local/nginx/passwd/gerrit2.passwd;
  7. }

重载 nginx
测试访问
http://zabbix.world-alive.xyz/gerrit
输入用户名gerrit2,密码为刚才设置的密码(本文设为gerrit2);
以上资料参考地址:http://qizhanming.com/2012/05/05/centos-dev-env-setup/
http://fatalove.iteye.com/blog/1332881
http://www.infoq.com/cn/articles/Gerrit-jenkins-hudson

没有评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注