$sudo apt-get install git-core apache2.2-bin apache2.2-common apache2-utils apache2-mpm-worker
$sudo adduser project
以新用户身份操作
$sudo su - project
http://code.google.com/p/gerrit/downloads/list?can=1&q=&colspec=Filename+Summary+Uploaded+ReleaseDate+Size+DownloadCount
java -jar gerrit-2.6.1.war init -d review_site_project/
Create '/home/gerrit2/review-site' [Y/n]? *** Git Repositories *** Location of Git repositories [git]: *** SQL Database *** Database server type [H2/?]: //改成MYSQL或者使用H2 *** User Authentication *** Authentication method [OPENID/?]: HTTP //注意这个不要按回车跳过去了,否则不是HTTP认证,是需要用google的OPENID Get username from custom HTTP header [y/N]? : SSO logout URL : *** Email Delivery *** SMTP server hostname [localhost]: smtp.company.com //自己改成自己的邮箱smtp SMTP server port [(default)]: SMTP encryption [NONE/?]: SMTP username [?]: [email protected] //自己改成自己的邮箱
[email protected]'s password : confirm password : *** Container Process *** Run as [project]: Java runtime [/usr/lib/jvm/java-6-sun-1.6.0.24/jre]: Copy gerrit.war to /home/gerrit2/review-site/bin/gerrit.war [Y/n]? Copying gerrit.war to /home/gerrit2/review-site/bin/gerrit.war *** SSH Daemon *** Listen on address [*]: Listen on port [29418]: //如果同一个用户下建多个gerrit,请不用都公用29418这个端口号 如39418 49418 Gerrit Code Review is not shipped with Bouncy Castle Crypto v144 If available, Gerrit can take advantage of features in the library, but will also function without it. Download and install it now [Y/n]? Downloading http://www.bouncycastle.org/download/bcprov-jdk16-144.jar ... OK Checksum bcprov-jdk16-144.jar OK Generating SSH host key ... rsa... dsa... done *** HTTP Daemon *** Behind reverse proxy [y/N]? y Proxy uses SSL (https://) [y/N]? n Subdirectory on proxy server [/]: /project/ //可以选择直接跳过,那样你的gerrit最后的URL是http://192.168.11.73:80 Listen on address [*]: Listen on port [8081]: //切记,此端口号一定不要和apache2占用相同的端口号,多个gerrit可以8082 8083 8084 //否则就会Starting Gerrit Code Review:Failed Canonical URL [http://*/]:http://192.168.11.73/project/ //上一步Subdirectory on proxy server 跳过不填则是http://192.168.11.73:80 (80为你将要在apache 给gerrit设置的端口) Initialized /home/gerrit2/review-site Executing /home/gerrit2/review-site/bin/gerrit.sh start Starting Gerrit Code Review: OK =========================================QA=======================================================================================
Q:Configuration ErrorCheck the HTTP server's authentication settings.The HTTP server did not provide the username in the Authorizationheader when it forwarded the request to Gerrit Code Review.If the HTTP server is Apache HTTPd, check the proxy configurationincludes an authorization directive with the proper location, ensuringit ends with '/':
In error_log:ERROR com.google.gerrit.httpd.auth.container.HttpLoginServlet : Unableto authenticate user by Authorization request header. Check containeror server configuration.
A:You cannot run these on the same port. Your Apache NameVirtualHostshould be on a different port than the internal Jetty web sever thatGerrit is using.
即gerrit和apache2占用相同的端口号
例如:cat review_site_project/etc/gerrit.config:
[httpd] listenUrl = http://x.x.x.x:8081/
cat /etc/apache2/apache2.conf :
NameVirtualHost x.x.x.x:8081
[gerrit] basePath = git //指定被gerrit管理的所有git库存放位置,即review_site_project/git/ canonicalWebUrl = http://192.168.11.73/project/ //指定web访问gerrit的网址//填自己的ip和端口号,勿完全抄 [database] type = H2 //指定gerrit所默认数据库类型,可以选用mysql database = db/ReviewDB
[auth] type = HTTP //指定浏览器登录gerrit时的认证方式 [sendemail] smtpServer = smtp.company.com //指定smtp服务器地址 smtpUser = [email protected] [container] user = project //指定gerrit所在机器的用户身份与上文创建的用户对应一致 javaHome = /usr/lib/jvm/java-6-sun-1.6.0.24/jre //系统本身自带 [sshd] listenAddress = *:29418 //指定sshd服务监听的端口号 [httpd] listenUrl = proxy-http://127.0.0.1:8081/project/ //指定http代理地址 [cache] directory = cache //缓存位置
$sudo apt-get install apache2.2-bin apache2.2-common apache2-utils apache2-mpm-worker
1.创建编辑apache配置文件,添加如下内容(下面以Ubuntu系统为例请注意不同操作系统apache配置文件的区别)也可配置 apache2.conf httpd.conf,我们这里配置的是/etc/apache2/sites-available/gerrit
$sudo vi /etc/apache2/sites-available/defalt NameVirtualHost 192.168.11.73:80 //填自己的ip和端口号,勿完全抄//填自己的ip和端口号,勿完全抄 ServerName 192.168.11.73 ProxyRequests Off ProxyVia Off ProxyPreserveHost On Order deny,allow Allow from all AuthType Basic AuthName "Gerrit Code Review" Require valid-user AuthUserFile /etc/apache2/passwords //指定http登录认证的的paassword文件所在位置,放哪都行,根据后来 //sudo htpasswd -cb /etc/apache2/passwords scm scm AllowEncodedSlashes On
RedirectMatch ^/project$ /project/
ProxyPass /project/ http://127.0.0.1:8081/project/
ProxyPassReverse /project/ http://127.0.0.1:8081/project/
保存退出
$cd /etc/apache2/sites-enabled/
$sudo ln ../sites-available/gerrit .
2.创建passwd文件,添加gerrit登录用户,-c参数为创建,仅限第一次添加用户时使用
$sudo htpasswd -cb /etc/apache2/passwords scm scm
3继续配置apache2
ServerName localhost
$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
配置apache2的监听端口:
/etc/apache2$sudo vi ports.conf
NameVirtualHost *:80
Listen 80
Listen 8080 //不要给gerrit!
Listen 8000 //不要给gerrit!
添加apache2的tcp端口号,切记不要把gerrit的,即
Listen on port [8081]: 不要输入上面配置给apache2的端口号,切记!!!
可以用sudo netstat -lnp | grep 80 查看相关80的所有端口使用情况
否则gerrit 起不来的 搭建多个gerrit 时Listen on port [8081]:可以用8082 8083 8084 等
Q:启动apache报错
Syntax error on line 300 of /etc/apache2/apache2.conf:Invalid command 'ProxyPass', perhaps misspelled or defined by a module not included in the server configuration ...fail!
cd /etc/apache2/mods-enabled ln -s /etc/apache2/mods-available/proxy.conf proxy.conf ln -s /etc/apache2/mods-available/proxy.load proxy.load ln -s /etc/apache2/mods-available/proxy_http.load proxy_http.load
No apache MPM package installed
$sudo apt-get install apache2-mpm-worker
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
ServerName localhost
Q:(13)Permission denied: make_sock: could not bind to address 0.0.0.0:80
A:需要用ROOT用户执行 直接 sudo /etc/init.d/apache2 restart 就OK了
sudo /etc/init.d/apache2 restart
$review_site_project/bin/gerrit.sh start
在浏览器地址栏中输入
192.168.11.73/project/
注:Subdirectory on proxy server [/]:选择直接跳过 则192.168.11.73:80
在显示的登录框中输入用户名/密码,
即之前配置passwords
$sudo htpasswd -cb /etc/apache2/passwords scm scm
scm
scm
ssh -p 29418 [email protected] gerrit create-project -p All-Projects -n project --empty-commit --permissions-only
ssh -p 29418 [email protected] gerrit create-project -p project -n project/manifest --empty-commit
for i in `cat project-list`;do ssh -p 29418 [email protected] gerrit create-project -p project -n project/$i --empty-commit;done
repo forall -c 'git remote add ts ssh://[email protected]:29418/$REPO_PROJECT' repo forall -c 'git push ts HEAD:refs/heads/project-dev'
git clone ssh://192.168.11.73:29418/project/manifest.git
git add default.xml git commit -m "init manifest" git push origin master:project-dev
执行如下命令
htpasswd -b passwords
新用户首次登录后,才可以给其添加权限。
Project_admin | 该项目管理员,可以为用户添加Gerrit身份; |
Project_read | 拥有gerrit用户名密码,设置了全名和邮箱的用户;拥有下载代码,提交代码,Code Review +1 的权限; |
Project_super_review | 负责查看该项目代码Review,拥有Code Review +2 的权限; |
Project_verify | 负责该项目编译验证代码,拥有Verified +1 的权限 |
Project_submit | 当该次提交代码Code Review +2 并且Verified +1后,负责将代码Merge到代码库中 |
下载代码测试
repo init -u ssh://@192.168.11.73:29418/project/manifest -b project-dev
代码提交之后,登录Gerrit,可以看到此次提交已经显示在列表中,如下图
ID | Subject | Owner | Project | Branch | Updated | CR | V |
---|---|---|---|---|---|---|---|
ChangeId | 提交信息的第一行 | 提交人 | 库名 | 分支名 | 最后变更的时间 | Review的状态 | Verify的状态 |
点击列表中的“ID”或“Subject”,则可以显示该提交更详细的信息。下图的放大效果中显示了该提交当前的状态。
下图显示了提交详细信息中的下半部分,主要有每次提交的Patch Set详情,该提交修改的文件列表,以及每次Review的说明信息。
点击Review按钮(上图红圈标识),可以对当前提交做Review的操作,如下图:
如图,可以看到两个按钮“Publish Comments”和“Publish and Submit”
如果只选择了给Review或Verify打分,也可以进行Submit,如下图,点击“Submit”按钮
至此,该提交Review完成,正式提交入库,状态变为“Merged”