gerrit + Git 服务器的搭建

一. 准备工作
      系统环境:Ubuntu12.04
      Gerrit版本:2.2.1  http://gerrit-releases.storage.googleapis.com/index.html
      Git安装:   apt-get install git

二. 配置过程

  1. zhouyanjiang@zhouyanjiang:~/Gerrit$ java -jar gerrit-2.2.1.war init -d review_sites

      安装过程中会提示输入各种信息,包括数据库信息等,大部分都可以使用默认配置。除了一个地方注意改成Y,Behind reverse proxy [y/N]? Y。


  1. *** Gerrit Code Review 2.2.1
  2. ***
  3. Create '/home/zhouyanjiang/Gerrit/review_sites' [Y/n]?
  4. *** Git Repositories
  5. ***
  6. Location of Git repositories [git]:
  7. *** SQL Database
  8. ***
  9. Database server type [H2/?]:
  10. *** User Authentication
  11. ***
  12. Authentication method [OPENID/?]:
  13. *** Email Delivery
  14. ***
  15. SMTP server hostname [localhost]:
  16. SMTP server port [(default)]:
  17. SMTP encryption [NONE/?]:
  18. SMTP username :
  19. *** Container Process
  20. ***
  21. Run as [zhouyanjiang]:
  22. Java runtime [/usr/lib/jvm/java-6-openjdk-amd64/jre]:
  23. Copy gerrit.war to /home/zhouyanjiang/Gerrit/review_sites/bin/gerrit.war [Y/n]?
  24. Copying gerrit.war to /home/zhouyanjiang/Gerrit/review_sites/bin/gerrit.war
  25. *** SSH Daemon
  26. ***
  27. Listen on address [*]:
  28. Listen on port [29418]:
  29. Gerrit Code Review is not shipped with Bouncy Castle Crypto v144
  30.   If available, Gerrit can take advantage of features
  31.   in the library, but will also function without it.
  32. Download and install it now [Y/n]?
  33. Downloading http://www.bouncycastle.org/download/bcprov-jdk16-144.jar ... OK
  34. Checksum bcprov-jdk16-144.jar OK
  35. Generating SSH host key ... rsa... dsa... done
  36. *** HTTP Daemon
  37. ***
  38. Behind reverse proxy [y/N]? Y
  39. Proxy uses SSL (https://) [y/N]?
  40. Subdirectory on proxy server [/]:
  41. Listen on address [*]:
  42. Listen on port [8081]:
  43. Canonical URL [http://zhouyanjiang-System-Product-Name/]:
  44. Initialized /home/zhouyanjiang/Gerrit/review_sites
  45. Executing /home/zhouyanjiang/Gerrit/review_sites/bin/gerrit.sh start
  46. Starting Gerrit Code Review: OK
  47. Waiting for server to start ... OK
  48. Opening browser ...

   
三.  报错处理
      1. 登陆网页会发现一些跳转不正常
          修改 review_sites/etc/gerrit.config
文件 canonicalWebUrl = http://192.168.5.102:8081/
      2. 启动gerrit服务出现报错          

  1. zhouyanjiang@zhouyanjiang:~/Gerrit/review_sites/bin$ ./gerrit.sh start
  2. ** ERROR: GERRIT_SITE not set

           报错为GERRIT_SITE未设置,只需要在gerrit.sh中设置GERRIT_SITE=/home/zhouyanjiang/Gerrit/review_sites即可

      3. 重启gerrit服务报错

  1. zhouyanjiang@zhouyanjiang:~/Gerrit/review_sites/bin$ ./gerrit.sh start
  2. Starting Gerrit Code Review: process already running.

           重新启动服务需要先stop,再start

四. 邮箱设置
        经过上述的配置和调整,gerrit页面http://192.168.5.102:8081 已经可以访问,此时第一个注册的用户为系统管理员。在此之前,还需要配置一下系统邮箱。
        系统邮箱的作用是给注册用户发送注册验证,给用户提交/merge代码发送邮件提示。在gerrit.config中的[sendemail]处进行配置,下面是的一个例子。

  1. [sendemail]
  2.         enable = true
  3.         smtpServer = smtp.gmail.com
  4.         smtpServerPort = 465
  5.         smtpEncryption = ssl
  6.         smtpUser = nuaayan@gmail.com
  7.         smtpPass = ******
  8.         sslVerify = false
  9.         from = CodeReview<nuaayan@gmail.com>

五. GERRIT公钥配置
   1.注册用户
        访问http://192.168.5.102:8081/, 点击右上角的"Register",使用google或yahoo邮箱注册,如果没有,需要提前申请。点击右上角的"Settings", 填写“Profile“里Username,"Contact Information"中Full Name,点击"Save Changes";
   2.配置公钥

  1. ~$ cd ~
  2. ~$ mkdir .ssh
  3. ~$ cd .ssh
  4. ~/.ssh$ ssh-keygen -t rsa -C nuaayan@gmail.com (:一路按回车即可)

在.ssh文件夹里添加新文件config, 内容如下:

  1. Host nuaayan
  2. Hostname 192.168.5.102
  3. Port 29418
  4. User nuaayan
  5. PubkeyAuthentication yes
  6. IdentitiesOnly yes
  7. PasswordAuthentication no
  8. IdentityFile ~/.ssh/id_rsa

    进入gerrit - Settings - SSH Keys,填入Username(和config的User一致); 并将~/.ssh/id_rsa.pub的内容复制到"Add SSH Public Key"

  1. ~$ ssh nuaayan (192.168.5.102的别名,在config中配置过)

     出现下面两行,就说明连接成功了。

  1. gerrit: no shell available
  2. Connection to 192.168.5.102 closed.

     如果遇到错误:

  1. Agent admitted failure to sign using the key.
  2. Permission denied (publickey,password).

     请在 .bashrc 中设置环境变量并重启bashrc:

  1. export SSH_AUTH_SOCK=0

六. 新建/检出 GIT仓库
     1. 新建git仓库:

  1. ssh nuaayan gerrit create-project -n test/project1

     2. 察看本人仓库权限 :

  1. ssh nuaayan gerrit ls-projects

     3. 检出仓库test/project1

  1. git clone nuaayan:test/project1

 

你可能感兴趣的:(git,ubuntu)