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

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

$ 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 <ppbox-rom@pptv.com>
[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



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Fighting Horse

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值