ubuntu下搭建apache+gerrit+h2+git环境

来源:互联网 发布:阿里云服务器怎么换ip 编辑:程序博客网 时间:2024/06/05 06:04

1 安装git

$sudo apt-get install git


2 安装apache2

$ sudo apt-get install apache2


3 下载gerrit, 如目前可用的Gerrit-2.12.war

4 安装gerrit:

 $ java -jar g errit-2.12.war init -d review_site/ 进入gerrit配置

Authentication method [OPENID/?]: HTTP   //注意这个不要按回车跳过去了,否则不是HTTP认证,是需要用google的OPENID
SMTP server hostname [localhost]: smtp.company.com   //自己改成自己的邮箱smtp
SMTP username [?]: yourname@company.com              //自己改成自己的邮箱
isten on address [*]:Listen on port [29418]:       //确保改端口没有被使用
Listen on port                 [8081]:          //注意,此端口号不要和apache2占用相同的端口号
除以上外,其他可以使用默认配置,以下是我的配置文件:(review_site/etc/gerrit.conf)
[gerrit]                                                                                           basePath = git        canonicalWebUrl = http://10.88.48.9:8081/[database]        type = h2        database = db/ReviewDB[index]        type = LUCENE[auth]        type = HTTP[sendemail]        smtpServer = localhost[container]        user = gerrit        javaHome = /home/gerrit/jdk/jdk1.7.0_80/jre[sshd]        listenAddress = *:29418[httpd]        listenUrl = http://10.88.48.9:8081/[cache]        directory = cache
配置apache2
在/etc/apache2/ports.conf中增加: Listen 8085    //端口号随意,只要合法不被占用
创建文件/etc/apache2/sites-enabled/gerrit.conf, 添加以下内容:

<VirtualHost 10.88.48.9:8085>          //与ports.conf中监听的端口一致,IP为本机ip
    ServerName 10.88.48.9


    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
      AuthUserFile /home/gerrit/review_site/htpasswd       //gerrit存储账号密码的文件
    </Location>


    AllowEncodedSlashes On
    ProxyPass / http://10.88.48.9:8081/          //这里对应gerrit.conf中配置的url
</VirtualHost>

保存退出


配置代理:

$cd /etc/apache2/mods-enabled
$sudo ln -s /etc/apache2/mods-available/proxy.conf proxy.conf 
$sudo ln -s /etc/apache2/mods-available/proxy.load proxy.load 
$sudo ln -s /etc/apache2/mods-available/proxy_http.load proxy_http.load


在review_site目录下创建htpasswd:

htpasswd -c ./htpasswd gerrit gerrit      //-c 仅在第一次创建htpasswd文件时使用;创建的第一个用户默认为gerrit超级用户Administrator


启动服务

启动gerrit: 

$review_site/bin/gerrit.sh start


启动apache2:

$ sudo /etc/init.d/apache2 restart


打开网页: 10.88.48.9:8085    //该处地址与apache2中配置的gerrit.conf一致

此时即提示输入账号密码,输入之前htpasswd创建的账号密码,登录


添加git工程:

可将任意git仓库软连接至review_site/git/ 目录下,重启gerrit服务



0 0