ITeye博客

搭建gerrit服务器(apache&nginx反向代理方式)

scm002 · 2016-04-24 23:55 · Git/Gerrit · 互联网 · Markdown

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

Check the HTTP server's authentication settings.

      后来经过他人指点,才知道自己的原因。由于对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/进行访问。

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

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

 

[html] view plain copy

  1. [gerrit]
  2. basePath = /home/gerrit/prj-source
  3. canonicalWebUrl = http://192.168.1.6:10000
  4. [database]
  5. type = h2
  6. database = db/ReviewDB
  7. [auth]
  8. type = HTTP
  9. [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 copy

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

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

[html] view plain copy

  1. <VirtualHost *:9999>
  2. ServerName 192.168.1.6
  3. ProxyPreserveHost On
  4. ProxyRequests Off
  5. <Proxy *>
  6. Order deny,allow
  7. Allow from all
  8. </Proxy>
  9. <Location />
  10. AuthType Basic
  11. AuthName "Welcomme to Gerrit Code Review Site!"
  12. Require valid-user
  13. AuthUserFile /home/gerrit/review-gerrit/htpasswd.conf
  14. </Location>
  15. ProxyPass / http://192.168.1.6:10000/
  16. proxyPassReverse / http://127.0.0.1:10000/
  17. </VirtualHost>

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

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

     
      输入账号密码,显示如下:

   

       gerrit安装配置成功。

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

 

[html] view plain copy

  1. server {
  2. listen *:9999;
  3. server_name 192.168.1.6;
  4. allow   all;
  5. deny    all;
  6. auth_basic "Welcomme to Gerrit Code Review Site!";
  7. auth_basic_user_file /home/gerrit/review-gerrit/htpasswd.conf;
  8. location / {
  9. 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, 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

 

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


评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。