ubuntu 环境下 gerrit 代码审查服务器的安装

1. 环境准备

  • 安装java环境

$ wget http://openlinux.amlogic.com:8000/deploy/java/sun-java6-bin_6.26-2lucid1_amd64.deb
$ wget http://openlinux.amlogic.com:8000/deploy/java/sun-java6-jdk_6.26-2lucid1_amd64.deb
$ wget http://openlinux.amlogic.com:8000/deploy/java/sun-java6-jre_6.26-2lucid1_all.deb
$ sudo dpkg -i sun-java6*
$ apt-get -f install

  •  安装 apache

如果安装的是apache httpd,后面的配置文件不太一样,所以尽量安装 apache2
$ sudo apt-get install apache2

2. 安装配置 gerrit

参考  http://gerrit.googlecode.com/svn/documentation/2.2.1/

2.1 安装 gerrit

  • 新建一个专用 linux 账号
$ sudo adduser gerrit
$ sudo su gerrit
$ cd ~
  •  下载安装包
$ wget http://gerrit-releases.storage.googleapis.com/gerrit-2.8-rc3.war

  • 安装

$ java -jar gerrit-2.8-rc3.war init -d review_site

2.2 配置 gerrit

参考  http://gerrit.googlecode.com/svn/documentation/2.2.1/config-gerrit.html
$ cat review_site/etc/gerrit.config
[gerrit]
        basePath = git
        canonicalWebUrl = http://192.168.27.42:8081/gerrit
[database]
        type = h2
        database = db/ReviewDB
[auth]
        type = HTTP
        #httpHeader = SM_USER
[sendemail]
        smtpServer = mail.pptv.com
        smtpServerPort = 587
        smtpEncryption = 
        smtpUser = cmguo
        smtpPass = 123456
        sslVerify = false
        from = PPBOX ROM GERRIT <[email protected]>
[container]
        user = gerrit
        javaHome = /usr/lib/jvm/java-6-sun-1.6.0.26/jre
[sshd]
        listenAddress = *:29418
[httpd]
        listenUrl = proxy-http://*:8081/gerrit
[cache]
        directory = cache

2.3 配置 apache

  • 启动反向代理
$ cd /etc/apache2/mods-enabled
$ ln ../mods-available/proxy.* .
$ ln ../mods-available/proxy_http.* .
  • 配置反向代理
$ cat mods-enabled/proxy.conf    
<IfModule mod_proxy.c>

# If you want to use apache2 as a forward proxy, uncomment the
# 'ProxyRequests On' line and the <Proxy *> block below.
# WARNING: Be careful to restrict access inside the <Proxy *> block.
# Open proxy servers are dangerous both to your network and to the
# Internet at large.
#
# If you only want to use apache2 as a reverse proxy/gateway in
# front of some web application server, you DON'T need
# 'ProxyRequests On'.

#ProxyRequests On
<Proxy *>
        AddDefaultCharset off
        Order deny,allow
        Allow from all
        #Allow from .example.com
</Proxy>

# Enable/disable the handling of HTTP/1.1 "Via:" headers.
# ("Full" adds the server version; "Block" removes all outgoing Via: headers)
# Set to one of: Off | On | Full | Block
#ProxyVia Off

ProxyPreserveHost On
#AllowEncodedSlashes On
ProxyPass /gerrit http://localhost:8081/gerrit nocanon

</IfModule>
$ cat sites-available/default
<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined

        AllowEncodedSlashes NoDecode
</VirtualHost>
  • 配置HTTP认证
$ cat /etc/apache2/httpd.conf
<Location /gerrit/login/>
  AuthType Basic
  AuthName "Gerrit Code Review"
  Require valid-user
  AuthUserFile /home/gerrit/review_site/etc/gerrit.passwd
</Location>
$ touch /home/gerrit/review_site/etc/gerrit.passwd
可能有些版本的apach2没有在apache2.conf文件中包含(Include)httpd.conf文件,需要手动添加
  • 增加管理员账号
$ htpasswd /home/gerrit/review_site/etc/gerrit.passwd cmguo

2.4 验证 gerrit 安装

登陆 http://192.168.13.202/gerrit/login

3. 集成 gitweb

  • 安装 gitweb
$ sudo apt-get install gitweb
  • 配置 gitweb
在 gerrit 配置文件添加 gitweb 配置
$ tail gerrit.config 
        user = gerrit
        javaHome = /usr/lib/jvm/java-6-sun-1.6.0.26/jre
[sshd]
        listenAddress = *:29418
[httpd]
        listenUrl = proxy-http://*:8081/gerrit
[cache]
        directory = cache
[gitweb]
        cgi = /usr/lib/cgi-bin/gitweb.cgi

  • 配置 gerrit 访问权限

gitweb 需要能够访问 refs/meta/config,需要修改 All-Projects 项目,增加 Registered Users 对 refs/meta/config 的 read 访问权限。

4. 添加新用户

4.1 注册账号

  • 注册 gerrit 账号
$ htpasswd /home/gerrit/review_site/etc/gerrit.passwd isxxguo
  • 注册 SSH key
登陆 http://192.168.13.202/gerrit/
按提示输入用户名,密码
第一次进入会提示完善账号信息,并且添加 SSH KEY

4.2 用户本地配置

  • 配置SSH主机别名
$ cat ~/.ssh/config
host ppboxrom
        user isxxguo
        hostname 192.168.13.202
        port 29418
        identityfile ~/.ssh/id_rsa



你可能感兴趣的:(git,gerrit)