gerrit搭建

1.gerrit 安装

 1.1 安装java环境:

  • 从oracle下载jdk-8u144-linux-x64.tar.gz
  • 解压缩 sudo tar zxvf jdk-8u144-linux-x64.tar.gz -C /opt
  • 配置环境变量 sudo vim /etc/profile 添加:
  •   验证:java -version

export JAVA_HOME=/opt/1.8.0_144
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

  1.2 安装git

sudo apt-get install git


1.3 gerrit 安装和配置

  1.3.1 安装

  默认安装:java -jar gerrit-2.14.2.war init --batch -d ~/review_site

     1.3.2 配置文件

vim  ~/review_site/etc/gerrit.config]

[gerrit]
        basePath = git
        serverId = 2e0d4b2a-0a28-407c-9fe8-9c7b84557e90
        canonicalWebUrl = http://10.119.125.39:8081/
[database]
        type = h2
        database = /home/penggc1/review_site/db/ReviewDB
[index]
        type = LUCENE
[auth]
        type = HTTP
[receive]
        enableSignedPush = false
[sendemail]
        smtpServer = smtp.126.com

        smtpServerPort = 465

        smtpEncryption = ssl

        smtpUser = xxxx@126.com

        smtpPass = xxxxxx

        sslVerify = false

        from=CodeReview<xxxxx@126.com>

[container] user = penggc1 javaHome = /opt/jdk1.8.0_144/jre [sshd] listenAddress = *:29418 [httpd] listenUrl = http://*:8081/ [cache] directory = cache


2. apache反向代理

apache反向代理主要是用户做gerrit的http的认证

2.1 apache的安装

安装:sudo apt-get install apache2 

验证:sudo /etc/init.d/apache2 start

 进入/etc/apache2可以看到apache的目录结构如下:

 apache2.conf    conf-enabled  magic          mods-enabled sites-available

conf-available  envvars      mods-available  ports.conf   sites-enabled

2.2 apache的模块加载流程




2.3 配置apache 的server

2.3.1 开启ssl和proxy,rewrite模块

cd /etc/apache2/mods-enabled

ln -s ../mods-available/proxy.load
ln -s ../mods-available/proxy.conf
ln -s ../mods-available/proxy_http.load
ln -s ../mods-available/proxy_balancer.conf
ln -s ../mods-available/proxy_balancer.load
ln -s ../mods-available/rewrite.load
ln -s ../mods-available/ssl.conf
ln -s ../mods-available/ssl.load
ln -s ../mods-available/socache_shmcb.load 
ln -s ../mods-available/slotmem_shm.load 

2.3.2 创建反向代理的配置文件:

sudo touch  /etc/apache2/sites-available/gerrit-httpd.conf 


在文件中添加以下内容:

<VirtualHost *:8080>
ServerName 10.119.125.39
    ProxyRequests Off
    ProxyVia Off
    ProxyPreserveHost On
    AllowEncodedSlashes On
    RewriteEngine On
    RewriteRule ^/(.*) http://10.119.125.39:8081/$1 [NE,P] #rewrite rule for proxy

    <Proxy *>
          Order deny,allow
          Allow from all
    </Proxy>

    <Location /login/>
        AuthType Basic
        AuthName "Gerrit Code Review"
        Require valid-user
        AuthBasicProvider file
        AuthUserFile /etc/apache2/passwords #password file for gerrit
    </Location>

    ProxyPass / http://10.119.125.39:8081/

</VirtualHost>

其中<VirtualHost *:8080>是用户访问的端口,8081是内部服务实际上提供的端口。也就是用户访问10.119.125.39:8080时候实际上访问的10.119.125.39:8081. 8080端口是8081的代理端口

2.3.3 创建软链接,

cd /etc/apache2/sites-enable

sudo ln -s ../sites-available/gerrit-httpd.conf


2.3.4 配置让apache server 监听8080端口

 sudo vim /etc/apache2/ports.conf

 

#If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 80
Listen 8080

<IfModule ssl_module>
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

 2.3.5 启动代理

sudo a2ensite gerrit-httpd.conf 


2.4 配置gerrit 账户密码

根据反向代理的配置文件,存储用户名和密码的地方是/etc/apache2/passwords

 sudo touch /etc/apache2/passwords


htpasswd是apache密码生成工具

htpasswd -b /etc/apache2/passwords admin 123456



2.5重新 启动 apache server 和gerrit

  sudo /etc/init.d/apache2 restart 

  sudo  ~/review_site/bin/gerrit.sh stop 

 sudo  ~/review_site/bin/gerrit.sh start 



遇到问题:

1. 配置邮箱不成功:

需要登录126的邮箱设置smtp的许可


参考内容:

http://www.cnblogs.com/tesky0125/p/5877536.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值