gerrit环境搭建

本文详细介绍了如何搭建gerrit服务器端,并提供了客户端使用的步骤和注意事项。包括安装Java、gerrit,配置gerrit配置文件,安装和配置Apache服务器以实现反向代理,以及创建gerrit账号、登录、设置个人信息、SSH密钥等操作。此外,还说明了如何在gerrit中创建项目、添加分支、克隆项目、上传代码、提交审查等流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 1:搭建gerrit服务器端

downloadgerrit-2.10.war


install java:

sudo apt-get install openjdk-7-jre-headless


install gerrit:

java -jar gerrit-2.10.war init -d review_site


vim review_site/etc/gerrit.config

[gerrit]

       basePath = git

       canonicalWebUrl=http://10.0.7.233:8081//*根据你服务器实际的IP地址填写*/

[database]

       type = h2

       database = db/ReviewDB

[index]

       type = LUCENE

[auth]

       type = HTTP

[sendemail]

       smtpServer = localhost

[container]

       user = ofi

       javaHome= /usr/lib/jvm/java-7-openjdk-amd64/jre

[sshd]

       listenAddress = *:29418

[httpd]

        listenUrl = proxy-http://*:8081//*反向代理必须*/

[cache]

       directory = cache


./review_site/bin/gerrit.sh restart





install apache2:

sudo apt-get install apache2

in /etc/apache2/apache2.conf addInclude httpd.conf
httpd.conf
文件的内容如下红色部分根据你实际情况填写

ServerName localhost

<VirtualHost *:8080>

       ProxyRequests Off

       ProxyVia Off

       ProxyPreserveHost On

       AllowEncodedSlashes On

       RewriteEngine On

       RewriteRule ^/(.*)http://10.0.7.233:8081/$1 [NE,P]


<Proxy *>

     Order deny,allow

     Allow from all

</Proxy>


<Location /login/>

   AuthType Basic

   AuthName "Gerrit CodeReview"

   Require valid-user

   AuthBasicProvider file

   AuthUserFile/home/ofi/gerrit/review_site/etc/passwd

</Location>


ProxyPass / http://10.0.7.233:8081/


</VirtualHost>



in /etc/apache2/ports.conf add:


NameVirtualHost *:80


NameVirtualHost *:8080


Listen 80


Listen 8080


 


建立一些apache2文件的链接


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


 


创建gerrit账号:


touch ./review_site/etc/passwd


htpasswd -b ./review_site/etc/passwd ofi 123456


the first user is admin, if you want to add other user, use:


htpasswd -b ./review_site/etc/passwduser_namepassword



gerrit startup:


./review_site/bin/gerrit.sh stop


./review_site/bin/gerrit.sh restart


 


apache startup:


sudo /etc/init.d/apache2 stop


sudo /etc/init.d/apache2 restart


 


2客户使用gerrit


loginhttp://10.0.7.233:8080/*根据你实际情况而定*/

settings -->contact information, add yourfull name


右上角显示你刚刚填写的Full Name

settings -->SSH Public Keys, add your public keys


how to get your public keys? in your linux machine:


run:


ssh-keygen


cat ~/.ssh/id_rsa.pub

to get your Public Keys.



Admin can create new project in

Gerrit website Projects Create New Project

Select your new project, click Branchs , you can add branchs in yourproject.

Select your new project, click General, you can find the clone addr ofyour Project, copy it, in your linux machine, run it, you can down load thecode.

For example:
git clone ssh://ofi@10.0.7.233:29418/ofi_test && scp -p -P 29418ofi@10.0.7.233:hooks/commit-msg ofi_test/.git/hooks/


cd ofi_test/


git branch -a
git checkout -b test origin/test2


git pullrebase

git config --global user.nameyour name
git config --global user.email
your email


modify your xxx.c


git status

git add xxx.c

git commit -myour commit message

git commitamend -s

git push origin HEAD:refs/for/test2

实际操作:


上面图片放大:

解决方法:

In /etc/ssh/ssh_config, add

StrictHostKeyChecking no

解决后:

修改代码,上传代码前准备阶段。增加一个test.c文件为例子,如果在已有问价上修改,方法也是一样的。同时确保自己设置了:
git config --global user.name
your name
git config --global user.email
your email


设置的user.name,user.email都会在自己的commit中显示出来。

git add操作之前,可以先用git status先看看自己改了那些文件。最好是一个文件做一个commit。


上传代码操作:

遇到一些error,怎么解决?在gerrit服务器端,添加test2branch的Forge Author/Committer Identity

上面红色框里面的test,实际上是个group。由服务器端People--》Create NewGroup创建。可以在Group里面加入gerrit成员,设定权限。


改完后,成功push代码:

对自己上传的代码增加reviewer:


reviewer 在自己的账号下review patch(My -> Changes目录下):


Code-Review+2


reviewer将代码提交到服务器:

其他人更新下代码,就可以看到你的code了:

相关commit message:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值