搭建gerrit服务器

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/anlory/article/details/80642157

简单介绍

Gerrit,谷歌开发的,一种开放源代码的代码审查软件,使用网页界面。利用网页浏览器,同一个团队的软件程序员,可以相互审阅彼此修改后的代码,决定是否能够提交,退回或是继续修改。它使用版本控制系统,Git作为底层。

参考:
http://www.worldhello.net/gotgit/05-git-server/055-gerrit.  
http://chuquan.me/2017/12/12/ubuntu-gerrit-apache/
https://blog.csdn.net/knightboyphp/article/details/51473214

gerrit服务器搭建步骤

1. 创建gerrit用户,并进入到/home/gerrit目录中。

adduser gerrit
su gerrit
cd /home/gerrit

2. 安装Gerrit。

wget http://gerrit-releases.storage.googleapis.com/gerrit-2.15.2.war
java -jar gerrit-2.6.1.war init -d review_site 
apt-get install openjdk-8 git  #gerrit依赖git 和java
安装中,基本一路回车,但我选择的安全认证方式是HTTP,数据库是H2,并需要配置反向代理
并配置SMTP

3. 配置Gerrit

 Gerrit的配置文件是review_site/etc/gerrit.config

我的配置文件:
[gerrit]
        basePath = git  #git库路径
        serverId = 31e19460-4b34-48c5-b0d9-eda02a76315a
        canonicalWebUrl = http://192.168.1.10/  #URL
[database]
        type = h2
        database = /home/gerrit/site_gerrit/db/ReviewDB
[index]
        type = LUCENE
[auth]
        type = HTTP
[receive]
        enableSignedPush = false
[sendemail]
  smtpServer = smtp.126.com   #配置邮箱
  smtpServerPort = 465  
  smtpEncryption = ssl  
  smtpUser = [email protected]  
  smtpPass = xxxxxxxx  
  sslVerify = false  
  from=CodeReview<[email protected]>  
[container]
        user = gerrit
        javaHome = /usr/lib/jvm/java-8-openjdk-amd64/jre
[sshd]
        listenAddress = *:29418
[httpd]
        listenUrl = proxy-http://127.0.0.1:8080/ #这个地方是代理地址
[cache]
        directory = cache
[gitweb]  #安装gitweb ,可以在网页查看git库目录
  type = gitweb
  cgi = /usr/share/gitweb/gitweb.cgi

3. 安装apache2 服务器

apt-get install apache2
注意:To run Gerrit behind an Apache server using 'mod_proxy', enable the necessary 
Apache2 modules:
执行:sudo a2enmod proxy_http
执行:sudo a2enmod ssl 
使新的配置生效,需要执行如下命令:
service apache2 restart

5. apache2配置反向代理,

以下部分追加在/etc/apache2/apache2.conf
<VirtualHost *:80>
  ServerName 192.168.1.10
  ProxyRequests Off 
  ProxyVia Off 
  ProxyPreserveHost On
  <Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>
  <Location /login/>
       AuthType Basic
       AuthName "Gerrit Code Review"
       Require valid-user
       AuthBasicProvider file
       AuthUserFile /home/gerrit/site_gerrit/etc/gerrit.passwd
  </Location>
  
  AllowEncodedSlashes On
  ProxyPass / http://127.0.0.1:8080/     #这两个地方一定要与gerrit.conf文件中的代理地址一样   
  ProxyPassReverse / http://127.0.0.1:8080/  
</VirtualHost>

7. HTTP验证方式口令维护

    touch /home/gerrit/site_site/etc/gerrit.passwd

    htpasswd -b /home/gerrit/site_site/etc/gerrit.passwd admin 123456(管理员)
    htpasswd -b /home/gerrit/site_site/etc/gerrit.passwd usr1 123456
   加了之后不会马上写进gerrit的h2数据库,而是登陆后写入。
htpasswd用法
Usage:
        htpasswd [-cimBdpsDv] [-C cost] passwordfile username
        htpasswd -b[cmBdpsDv] [-C cost] passwordfile username password


        htpasswd -n[imBdps] [-C cost] username
        htpasswd -nb[mBdps] [-C cost] username password
 -c  Create a new file.
 -n  Don't update file; display results on stdout.
 -b  Use the password from the command line rather than prompting for it.
 -i  Read password from stdin without verification (for script usage).
 -m  Force MD5 encryption of the password (default).
 -B  Force bcrypt encryption of the password (very secure).
 -C  Set the computing time used for the bcrypt algorithm
     (higher is more secure but slower, default: 5, valid: 4 to 31).
 -d  Force CRYPT encryption of the password (8 chars max, insecure).
 -s  Force SHA encryption of the password (insecure).
 -p  Do not encrypt the password (plaintext, insecure).
 -D  Delete the specified user.
 -v  Verify password for the specified user.
On other systems than Windows and NetWare the '-p' flag will probably not work.
The SHA algorithm does not use a salt and is less secure than the MD5 algorithm.

8. gerrit 开机自启动

在 /etc/rc.local 下追加
 /home/gerrit/site_gerrit/bin/gerrit.sh start

9. gerrit 集成 gitweb实现网页中查看项目代码

安装gitweb 

apt-get install gitweb

在gerrit.config下添加
[gitweb]
    type = gitweb
    cgi = /usr/share/gitweb/gitweb.cgi
1> 在gerrit集成gitweb之后,发现只有我的root用户(gerrit里注册的第一个用户)才能够点gitweb链接正常打开gitweb页面。其他的普通用户点gitweb链接显示404错误,  
为项目的用户组增加了对refs/meta/config的read权限,即在read标签中加入注册的用户组即可    

10. 访问http://192.168.1.19 就进入gerrit。Gerrit第一个登录的用户默认为管理员。

猜你喜欢

转载自blog.csdn.net/anlory/article/details/80642157