Gerrit安装使用指导(一)

Gerrit安装使用指导

简介:本指导主要分三部分组成,一是Gerrit的安装配置,二是本地git对接到Gerrit仓库,三是代码审查说明。

一、依赖组件

Gerrit依赖的组件主要有以下四个:

1)        jdk    --Gerrit主要由java实现其功能,所以需要jdk支持;

2)        mysql    --Gerrit审查过程中存储所有信息的数据库,Gerrit本身自带H2数据库一般不用;

3)        Apache/nginx    --主要用到其反向代理功能;

4)        Git    --Gerrit本身相当于是一个Git服务器。

二、组件安装

上述四个组件的安装网上的教程较多,安装的过程较简单,这里不一一赘述,有时间可以再各自写一个教程。

三、Gerrit安装

1.    准备以下三个包,放到常用按照包的目录下,比如我这里是在/root/目录下


2.    创建供Gerrit使用的数据库

mysql>create database gerritdb CHARACTER SETutf8 COLLATE utf8_general_ci;

mysql>grant all on gerritdb.* to 'gerrituser'@'localhost'identified by 'gerritpass';

 注意:有些时候使用域名localhost是访问不了数据库的,需要环回地址127.0.0.1,可以在数据库的用户表里面添加一条除host对应修改为127.0.0.1的一条user信息。

3.    添加gerrit用户

在root用户下,分布执行以下操作:

useradd gerrit

##以下操作是为了避免在安装Gerrit时再去执行会因执行时间过长影响Gerrit安装

cp /root/gerrit-2.11.3.war /home/gerrit

mkdir -p /home/gerrit/gerrit_site/lib

cp /root/mysql-connector-java-5.1.21.jar/home/gerrit/gerrit_site/lib

cp /root/bcpkix-jdk15on-1.52.jar/home/gerrit/gerrit_site/lib/

chown -R gerrit.gerrit /home/gerrit

4.    执行安装

切换到gerrit用户下,然后执行安装命令, 安装过程中除数据库选用mysql(并配置对应gerrit的数据库和密码)、开启方向代理并配置端口外,其他均选默认即可

java -jar gerrit-2.11.3.war init -d ~/gerrit_site

##以下为安装大致内容

Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore

*** Gerrit Code Review 2.11.3

*** 

*** 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]? 

Renaming mysql-connector-java-5.1.10.jar to .mysql-connector-java-5.1.10.jar.backupDownloadinghttp://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 [gerrit]: gerrituser

gerrituser's password : 

confirm password : 

*** Index

*** 

Type [LUCENE/?]: 

The index must be rebuilt before starting Gerrit:

java -jar gerrit.war reindex -d site_path

*** 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.8.0-openjdk-1.8.0.91-1.b14.el6.x86_64/jre]: 

Copy gerrit-2.11.3.war to /home/gerrit/gerrit_site/bin/gerrit.war[Y/n]? 

Copying gerrit-2.11.3.war to /home/gerrit/gerrit_site/bin/gerrit.war

*** SSH Daemon

*** 

Listen on address [*]: 

Listen on port [29418]: 

Gerrit Code Review is not shipped with Bouncy Castle Crypto SSL v151

If available, Gerrit can take advantage of features

in the library, but will also function without it.

Download and install it now [Y/n]? 

Renaming bcpkix-jdk15on-1.52.jar to.bcpkix-jdk15on-1.52.jar.backupDownloadinghttp://www.bouncycastle.org/download/bcpkix-jdk15on-151.jar ... !! FAIL !!

error: http://www.bouncycastle.org/download/bcpkix-jdk15on-151.jar: 302Found

Please download:

http://www.bouncycastle.org/download/bcpkix-jdk15on-151.jar

and save as:

/home/gerrit/gerrit_site/lib/bcpkix-jdk15on-151.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 反向代理

Use SSL (https://) [y/N]? 

Listen on address [*]: 

Listen on port [8080]: 8081 如果使用反向代理,这里要使用一个代理服务器监听的不同端口,我使用的8081

Canonical URL [http://Zabbix-server:8080/]: 如果设置了反向代理,则要填写代理服务器的端口,我写的8080

*** Plugins

*** 

Installing plugins.

Install plugin download-commands version v2.11.3 [y/N]? 

Install plugin reviewnotes version v2.11.3 [y/N]? 

Install plugin singleusergroup version v2.11.3 [y/N]? 

Install plugin replication version v2.11.3 [y/N]? 

Install plugin commit-message-length-validator version v2.11.3 [y/N]? 

Initializing plugins.

No plugins found with init steps.    

Initialized /home/gerrit/gerrit_site

安装时如出现以下错误

可使用root用户登录mysql数据库,并执行命令

set global explicit_defaults_for_timestamp=1;

即可解决。如下图

5.    启动缓存

先执行命令 java -jar gerrit-2.11.3.war reindex -d/home/gerrit/gerrit_site ,防止出现以下错误

查看日志,报错如下:
[gerrit@115 ~]$ tail -f /home/gerrit/gerrit_site/logs/error_log
[2016-07-14 10:52:07,317] INFO com.google.gerrit.server.cache.h2.H2CacheFactory : Enabling disk cache /home/gerrit/gerrit_site/cache
[2016-07-14 10:52:08,110] INFO com.google.gerrit.server.config.ScheduleConfig : gc schedule parameter "gc.interval" is not configured
[2016-07-14 10:52:08,859] INFO org.eclipse.jetty.util.log : Logging initialized @4743ms
[2016-07-14 10:52:09,278] INFO com.google.gerrit.server.git.LocalDiskRepositoryManager : Defaulting core.streamFileThreshold to 2047m
[2016-07-14 10:52:09,320] INFO com.google.gerrit.server.plugins.PluginLoader : Loading plugins from /home/gerrit/gerrit_site/plugins
[2016-07-14 10:52:09,322] ERROR com.google.gerrit.pgm.Daemon : Unable to start daemon
com.google.inject.ProvisionException: Unable to provision, see the following errors:
1) No index versions ready; run Reindex
1 error
at com.google.gerrit.lucene.LuceneVersionManager.start(LuceneVersionManager.java:119)
at com.google.gerrit.lifecycle.LifecycleManager.start(LifecycleManager.java:74)
at com.google.gerrit.pgm.Daemon.start(Daemon.java:293)
at com.google.gerrit.pgm.Daemon.run(Daemon.java:205)
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:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.google.gerrit.launcher.GerritLauncher.invokeProgram(GerritLauncher.java:166)
at com.google.gerrit.launcher.GerritLauncher.mainImpl(GerritLauncher.java:93)
at com.google.gerrit.launcher.GerritLauncher.main(GerritLauncher.java:50)
at Main.main(Main.java:25)

然后启动缓存 /home/gerrit/gerrit_site/bin/gerrit.sh start

6.    修改配置文件

修改/home/gerrit/gerrit_site/etc目录下gerrit.config文件,并重启gerrit

[gerrit]
basePath = git
serverId = b18fc05c-8ff2-4f5f-9abd-f364f242ae60
canonicalWebUrl = http://111.230.166.247:8585
[database]
type = mysql
hostname = localhost
database = gerritdb
username = gerrituser
[index]
type = LUCENE
[auth]
type = HTTP
[receive]
enableSignedPush = false
[sendemail]
smtpServer = smtp.qq.com
smtpUser = [email protected]
smtpServerPort = 465
smtpEncryption = ssl
from = [email protected]
smtpPass = gzxumrfjwvtucbag
sslverify=false
[container]
user = gerrit
javaHome = /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.el7_5.x86_64/jre
[sshd]
listenAddress = *:29418
[httpd]
listenUrl = proxy-http://127.16.0.17:8081/
[cache]
directory = cache
[gitweb]
cgi = /var/www/git/gitweb.cgi

说明:

basePath配置的是git仓库相对路径,绝对路径为/home/gerrit/gerrit_site/

sendmail配置的是服务器的邮箱地址,其中配置的邮箱必须开启SMTP服务(网易自定的协议会将某些邮件发出的系统邮件当做垃圾邮件处理掉,如果使用网易邮箱作为服务器邮箱,此处密码配置为邮箱的授权码).此外,密码与/home/gerrit/gerrit_site/etc/secure.config中保持一致

listenUrl配置的是被代理的地址

[gitweb]是配置Gerrit对接到gitweb之后出现的配置信息

配置完重启

     

httpd里面配置的是对接Apache的地址

注:Apache的配置/usr/local/httpd/conf/httpd.conf

Listen 8585
<VirtualHost *:8585>
  ServerName localhost
  ProxyRequests Off  
  ProxyVia Off  
  ProxyPreserveHost On  
 
 
  <Proxy *:8585>  
        Order deny,allow  
        Allow from all  
  </Proxy>  
 
 
    <Location /login/>
      AuthType Basic
      AuthName "Gerrit Code Review"
      Require valid-user
      AuthUserFile  /home/gerrit/gerrit_site/etc/passwords
      
    </Location>
  
  AllowEncodedSlashes On
  ProxyPass / http://127.16.0.17:8081/ nocanon
  ProxyPassReverse / http://127.0.0.1:8081/

</VirtualHost>

注意:1、同时需要开放apache对应的module

          2、AllowEncodedSlashes On配置URL的特殊字段,可以查看在Gerrit上查看下级文件

          3、ProxyPass  后面加  nocanon 作用同上

7.    修改权限,添加Gerrit用户

chmod755 /home/gerrit

##此命令添加的gerrit为系统管理员用户

htpasswd -c /home/gerrit/gerrit_site/etc/passwords  gerrit

##此命令添加一般用户

htpasswd -m /home/gerrit/gerrit_site/etc/passwords  用户名

无需重启。

安装配置到此,就已经可以通过服务器地址和Apache监听的反向代理端口访问Gerrit首页了,第一次登陆时需要注册邮箱,通过邮箱里面的邮件激活,配置完大概是下面这个样子


猜你喜欢

转载自blog.csdn.net/qq_38431305/article/details/79964141