---
title: "搭建gerrit服务器(apache&nginx反向代理方式) "
author: "scm002"
date: "2016-04-24T23:55:49Z"
tags: []
categories: ["互联网"]
slug: "gerrit-apache-nginx"
draft: false
lastmod: "2016-04-25T18:46:30Z"
id: 2293641
url: "https://scm002.iteye.com/blog/2293641"
---

这段时间，想搭建一个gerrit，用于代码托管，gerrit的搭建，网上有很多种教程，但是自己按照别人的教程逐步操作，一直出现诸多问题。最头痛的就是：  
Configuration Error

Check the HTTP server's authentication settings.

![](http://img.blog.csdn.net/20150902123952858?watermark%2F2%2Ftext%2FaHR0cDovL2Jsb2cuY3Nkbi5uZXQv%2Ffont%2F5a6L5L2T%2Ffontsize%2F400%2Ffill%2FI0JBQkFCMA=%3D%2Fdissolve%2F70%2Fgravity%2FCenter)

      后来经过他人指点，才知道自己的原因。由于对Apache的反向代理的机制，没有清楚，导致寸步难行。现将搭建方式进行记载：

一.gerrit的搭建

     由于gerrit和Apache的安装，网上教程已经很多，这里就不一一说明了。本文主要讲解如何配置Apache的反向代理.

    本次搭建环境为VMware上的Ubuntu12.04，通过Windows上，ssh去操作。 Ubuntu虚拟机的ip地址为192.168.1.6,Windows的IP地址为192.168.1.3。搭建的gerrit服务器，在Windows上通过[http://192.168.1.6:9999/](http://192.168.1.6:9999/gerrit)进行访问。

   假定gerrit已经成功安装到Ubuntu，其路径为：/home/gerrit/review-gerrit

  进入etc路径，即/home/gerrit/review-gerrit/etc,这里贴出gerrit.config文件：

 

**\[html]** [view plain](http://blog.csdn.net/coder80/article/details/48176559 "view plain") [copy](http://blog.csdn.net/coder80/article/details/48176559 "copy")

01. \[gerrit]
02. basePath = /home/gerrit/prj-source
03. canonicalWebUrl = http://192.168.1.6:10000
04. \[database]
05. type = h2
06. database = db/ReviewDB
07. \[auth]
08. type = HTTP
09. \[sendemail]
10. smtpServer = localhost
11. \[container]
12. user = root
13. javaHome = /usr/lib/jvm/java-6-openjdk-amd64/jre
14. \[sshd]
15. listenAddress = \*:29418
16. \[httpd]
17. listenUrl = http://\*:10000

      完成以上的步骤，比较简单，很多教程都有过描述。下面主要讲解Apache的反向代理。

      首先简单描述一下反向代理的基础：反向代理（Reverse Proxy）方式是指以代理服务器来接受internet上的连接请求，然后将请求转发给内部网络上的服务器，  
并将从服务器上得到的结果返回给internet上请求连接的客户端，此时代理服务器对外就表现为一个反向代理服务器。

         例如我们想通过PC浏览器去访问http://192.168.1.6:9999，就是一个反向代理。在/home/gerrit/review- gerrit/etc/gerrit.config中，我们配置gerrit端口bind在10000，为啥外部通过访问端口9999，就可以打开 gerrit的web页面？

        原因就是Apache的反向代理功能。那就开始配置Apache吧！

        a.第一步，要在Apache上新增端口9999，用户监听网络事件。修改配置文件/etc/apache2/ports.conf。    

**\[html]** [view plain](http://blog.csdn.net/coder80/article/details/48176559 "view plain") [copy](http://blog.csdn.net/coder80/article/details/48176559 "copy")

1. NameVirtualHost \*:80
2. Listen 80
3. Listen 9999

       b.第二步，增加反向代理的配置。/etc/apache2/sites-enabled/000-default.conf

**\[html]** [view plain](http://blog.csdn.net/coder80/article/details/48176559 "view plain") [copy](http://blog.csdn.net/coder80/article/details/48176559 "copy")

01. &lt;VirtualHost \*:9999&gt;
02. ServerName 192.168.1.6
03. ProxyPreserveHost On
04. ProxyRequests Off
05. &lt;Proxy \*&gt;
06. Order deny,allow
07. Allow from all
08. &lt;/Proxy&gt;
09. &lt;Location /&gt;
10. AuthType Basic
11. AuthName "Welcomme to Gerrit Code Review Site!"
12. Require valid-user
13. AuthUserFile /home/gerrit/review-gerrit/htpasswd.conf
14. &lt;/Location&gt;
15. ProxyPass / http://192.168.1.6:10000/
16. proxyPassReverse / http://127.0.0.1:10000/
17. &lt;/VirtualHost&gt;

       c.完成以上配置，则成功。然后restart Apache和gerrit服务即可

     然后在pc浏览器上输入：http://192.168.1.6:9999/,则启动gerrit

     ![](http://img.blog.csdn.net/20150902125406567?watermark%2F2%2Ftext%2FaHR0cDovL2Jsb2cuY3Nkbi5uZXQv%2Ffont%2F5a6L5L2T%2Ffontsize%2F400%2Ffill%2FI0JBQkFCMA=%3D%2Fdissolve%2F70%2Fgravity%2FCenter)  
      输入账号密码，显示如下：

   ![](http://img.blog.csdn.net/20150902125452485?watermark%2F2%2Ftext%2FaHR0cDovL2Jsb2cuY3Nkbi5uZXQv%2Ffont%2F5a6L5L2T%2Ffontsize%2F400%2Ffill%2FI0JBQkFCMA=%3D%2Fdissolve%2F70%2Fgravity%2FCenter)

       gerrit安装配置成功。

     如果不适用Apache进行反向代理，使用nginx则更加简单，直接修改一个文件就可以了。/etc/nginx/conf.d/gerrit.conf，没有这个文件，则直接touch gerrit.conf就可生成，然后编辑一下。

 

**\[html]** [view plain](http://blog.csdn.net/coder80/article/details/48176559 "view plain") [copy](http://blog.csdn.net/coder80/article/details/48176559 "copy")

01. server {
02. listen \*:9999;
03. server\_name 192.168.1.6;
04. allow   all;
05. deny    all;
06. auth\_basic "Welcomme to Gerrit Code Review Site!";
07. auth\_basic\_user\_file /home/gerrit/review-gerrit/htpasswd.conf;
08. location / {
09. proxy\_pass  http://127.0.0.1:10000;
10. }
11. }

    按照以上步骤，可以搭建一个gerrit服务器了。

   另外，关于gerrit服务器的后台权限&项目管控，还在逐步研究。

 

 

fix below error:

/etc/apache2/sites-enabled$ systemctl restart apache2  
Job for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details.

:/etc/apache2/sites-enabled$ systemctl status apache2.service

 4月 24 23:35:52 review apache2\[11436]: Output of config test was:  
 4月 24 23:35:52 review apache2\[11436]: AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/ports.conf:5  
 4月 24 23:35:52 review apache2\[11436]: AH00526: Syntax error on line 3 of /etc/apache2/sites-enabled/000-default.conf:

 

FIX:

 

```
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


```

 

ubuntu15.10 restart apache2:  
systemctl restart apache2

 

 

refer to:

http://blog.csdn.net/coder80/article/details/48176559

http://blog.csdn.net/ljchlx/article/details/22277311

 

 

`ssh -p 29418 localhost gerrit gsql`

I get the following error :-

```
fatal: newbie does not have "Access Database" capability.
```

How to give administrators database access in gerrit ?

 

Global capabilities are [configured in the `project.config` file](https://gerrit-review.googlesource.com/Documentation/config-project-config.html#capability-section), e.g.

```
[capability]
       accessDatabase = group Administrators

```

`mkdir` `tmp`

`cd` `tmp`

`git init`

`git remote add origin ssh://admin@remote.site.com:29418/All-Projects`

`git fetch origin refs/meta/config:refs/remotes/origin/meta/config`

`git checkout meta/config`

```
[capability]
       accessDatabase = group Administrators

```

`git commit -a`

`git push origin meta/config:meta/config`

 

remote: ERROR:  In commit fc20c790fd92058305b0456b780cbd0745d9c490  
remote: ERROR:  author email address hbxwshiquan@163.com  
remote: ERROR:  does not match your user account.  
remote: ERROR:  
remote: ERROR:  You have not registered any email addresses.  
remote: ERROR:  
remote: ERROR:  To register an email address, please visit:  
remote: ERROR:  http://review.sonymobile.com:8082/#/settings/contact

FIX:

## gerrit2@ubuntu:~/review\_site$ ./bin/gerrit.sh stop Stopping Gerrit Code Review: OK gerrit2@ubuntu:~/review\_site$ ls bin gerrit.sh  gerrit.war gerrit2@ubuntu:~/review\_site$ java -jar bin/gerrit.war gsql

 

 

```
select * from ACCOUNT_EXTERNAL_IDS;
update ACCOUNT_EXTERNAL_IDS set EMAIL_ADDRESS='alex.blewitt@example.com' where ACCOUNT_ID=1000000;
```

 

 [Fix Permission denied (publickey) of repo upload](http://blog.chinaunix.net/uid-632207-id-2083402.html)

 

*The authenticity of host '\[review.example.com]:29418 (\[192.168.1.103]:29418)' can't be established.*  
*RSA key fingerprint is 42:4d:2e:2a:26:75:33:5a:75:08:7d:67:dd:07:f0:2e.*  
*Are you sure you want to continue connecting (yes/no)? yes*  
*Warning: Permanently added '\[review.example.com]:29418' (RSA) to the list of known hosts.*  
*Permission denied (publickey).*  
*fatal: Could not read from remote repository.*

*Please make sure you have the correct access rights*  
*and the repository exists.*

其原因是ssh账号它默认使用的是email账号的id部分，而如果username和email的id部分不同的话就不对了

查看了repo help upload得到了答案：

review.URL.username:

Override the username used to connect to Gerrit Code Review. By default  
the local part of the email address is used.

所以执行：

git config --global review.review.source.android.com.username MYNAME

后就OK了.

 

A mail thread about review.URL.username

[http://osdir.com/ml/repo-discuss/2010-11/msg00074.html](http://osdir.com/ml/repo-discuss/2010-11/msg00074.html)

```

```