git 服务器搭建之gerrit

Gerrit安装


  1. 安装apache

试有有没有安装apache, sudo /etc/init.d/apache2 start,如果启动了表示安装了apache,如果没有安装或其它问题,可以重装apache.

重装apache2

sudo apt-getremove --purge apache2 apache2-utils apache2.2-common

sudoapt-get install apache2


  1. 安装JDK及配置环境变量

  2. 安装gerrit

下载:http://code.google.com/p/gerrit/ 

安装: java-jar gerrit-full-2.5.2.war init -d review_site

网上有很多新建了一个用户,在该用户下安装gerrit,这里没有新建用户,直接安装。


安装过程中,提示如下:

只有几处需要修改,其它全部回车

  1. Authenticationmethod [OPENID/?]: http

  2. Behindreverse proxy [y/N]? y

  3. GerritCode Review is not shipped with Bouncy Castle Crypto v144……选择yes,直至出现GeneratingSSH host key ... rsa... dsa... done

  4. 提示安装插件,全部不安装。

  5. 这里暂没有配置邮件。


所有选择项如下:

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

***Gerrit Code Review 2.10.1

***

Create'/tools/review_site' [Y/n]?

***Git Repositories

***

Locationof Git repositories [git]:

***SQL Database

***

Databaseserver type [h2]:

***Index

***

Type [LUCENE/?]:

***User Authentication

***

Authenticationmethod [OPENID/?]: HTTP

Getusername from custom HTTP header [y/N]?

SSOlogout URL :

***Review Labels

***

InstallVerified label [y/N]?

***Email Delivery

***

SMTPserver hostname [localhost]:

SMTPserver port [(default)]:

SMTPencryption [NONE/?]:

SMTPusername :

***Container Process

***

Runas [ubuntu]:

Javaruntime [/usr/lib/jvm/jdk-8u40-linux-i586/jre]:

Copygerrit-2.10.1.war to /tools/review_site/bin/gerrit.war [Y/n]?

Copyinggerrit-2.10.1.war to /tools/review_site/bin/gerrit.war

***SSH Daemon

***

Listenon address [*]:

Listenon port [29418]:

GerritCode Review is not shipped with Bouncy Castle Crypto SSL v149

Ifavailable, Gerrit can take advantage of features

inthe library, but will also function without it.

Downloadand install it now [Y/n]? y

Downloadinghttp://www.bouncycastle.org/download/bcpkix-jdk15on-149.jar ... OK

error:SHA-1 checksum does not match

Usebcpkix-jdk15on-149.jar anyway [y/n]? n

fatal:aborted by user

ubuntu@ubuntu:/tools$java -jar gerrit-2.10.1.war init -d review_site

***Gerrit Code Review 2.10.1

***

Create'/tools/review_site' [Y/n]?

***Git Repositories

***

Locationof Git repositories [git]:

***SQL Database

***

Databaseserver type [h2]:

***Index

***

Type [LUCENE/?]:

***User Authentication

***

Authenticationmethod [OPENID/?]: http

Getusername from custom HTTP header [y/N]?

SSOlogout URL :

***Review Labels

***

InstallVerified label [y/N]?

***Email Delivery

***

SMTPserver hostname [localhost]:

SMTPserver port [(default)]:

SMTPencryption [NONE/?]:

SMTPusername :

***Container Process

***

Runas [ubuntu]:

Javaruntime [/usr/lib/jvm/jdk-8u40-linux-i586/jre]:

Copygerrit-2.10.1.war to /tools/review_site/bin/gerrit.war [Y/n]?

Copyinggerrit-2.10.1.war to /tools/review_site/bin/gerrit.war

***SSH Daemon

***

Listenon address [*]:

Listenon port [29418]:

GerritCode Review is not shipped with Bouncy Castle Crypto SSL v149

Ifavailable, Gerrit can take advantage of features

inthe library, but will also function without it.

Downloadand install it now [Y/n]? y

Downloadinghttp://www.bouncycastle.org/download/bcpkix-jdk15on-149.jar ... OK

error:SHA-1 checksum does not match

Usebcpkix-jdk15on-149.jar anyway [y/n]? y

GerritCode Review is not shipped with Bouncy Castle Crypto Provider v149

**This library is required by Bouncy Castle Crypto SSL v149. **

Downloadand install it now [Y/n]? y

Downloadinghttp://www.bouncycastle.org/download/bcprov-jdk15on-149.jar ...

OK

error:SHA-1 checksum does not match

Usebcprov-jdk15on-149.jar anyway [y/n]? error: SHA-1 checksum does notmatch

Usebcprov-jdk15on-149.jar anyway [y/n]? y

GeneratingSSH host key ... rsa(simple)... done



***HTTP Daemon

***

Behindreverse proxy [y/N]? y

Proxyuses SSL (https://) [y/N]? n

Subdirectoryon proxy server [/]:

Listenon address [*]:

Listenon port [8081]:

CanonicalURL [http://ubuntu/]:

***Plugins

***

Installplugin commit-message-length-validator version v2.10-rc1-26-gaebb492[y/N]? n

Installplugin download-commands version v2.10-rc1-26-gaebb492 [y/N]? n

Installplugin replication version v2.10-rc1-26-gaebb492 [y/N]? n

Installplugin reviewnotes version v2.10-rc1-26-gaebb492 [y/N]? n

Installplugin singleusergroup version v2.10-rc1-26-gaebb492 [y/N]? n

Initialized/tools/review_site

Executing/tools/review_site/bin/gerrit.sh start

StartingGerrit Code Review: OK

Waitingfor server on ubuntu:80 ... OK

Openinghttp://ubuntu/#/admin/projects/ ...OK


  1. 配置apache,gerrit

这里只需ip改成自已的电脑ip即可,实际应用则是服务器ip,端口号有安装gerrit时,因为直接是回车,所以这里默认是8081


  1. Review_site/etc/gerrit.config

[gerrit]

basePath = git

canonicalWebUrl =http://192.168.105.129/

[database]

type = h2

database =db/ReviewDB

[index]

type = LUCENE

[auth]

type = HTTP

[sendemail]

smtpServer =localhost

[container]

user = ubuntu

javaHome =/usr/lib/jvm/jdk-8u40-linux-i586/jre

[sshd]

listenAddress =*:29418

[httpd]

listenUrl =proxy-http://192.168.105.129:8081/

[cache]

directory = cache


  1. /etc/apache2/httpd.conf (以下内容直接粘贴进去即可,注意下方proxypass对应的是1中的端口,即gerrit的端口,VirtualHostapache的端口)

ServerName192.168.105.129

<VirtualHost*:8080>

ProxyRequestsOff

ProxyVia Off

ProxyPreserveHost On


<Proxy *>

Orderdeny,allow

Allow fromall

</Proxy>


<Location/login/>

AuthTypeBasic

AuthName"Gerrit Code Review"

Requirevalid-user

AuthBasicProvider file

AuthUserFile/tools/review_site/etc/passwd

</Location>


ProxyPass /http://192.168.105.129:8081/

ProxyPassReverse/ http://192.168.105.129:8081/

</VirtualHost>



  1. /etc/apache2/httpd.confapache默认端口是80,因2中新增了一个apache端口8080,这里也新增8080即可,其它不改)

NameVirtualHost *:80

Listen 80

Listen 8080


<IfModule mod_ssl.c>

# If you add NameVirtualHost *:443 here, you will also have tochange

# the VirtualHost statement in/etc/apache2/sites-available/default-ssl

# to <VirtualHost *:443>

# Server Name Indication for SSL named virtual hosts is currentlynot

# supported by MSIE on Windows XP.

Listen 443

</IfModule>


<IfModule mod_gnutls.c>

Listen 443

</IfModule>


  1. 以上三处的端口关系必须写清楚,否则gerrit起不来。


  1. 启动gerrit

先重启apache:sudo /etc/init.d/apache2 restart

再启动gerrit:./review_site/bin/gerrit.sh restart

  1. 添加gerrit用户

设置第一个gerrit用户的帐号和密码,第一个用户默认为管理员
     $: touch ./review_site/etc/passwd
     $: htpasswd -b ./review_site/etc/passwd admin admin

(后续再添加gerrit用户可使用:$: htpasswd -b ./review_site/etc/passwd UserName PassWord ) 

  1. 访问

浏览器中输入:http://10.10.90.160:8080/  输入用户名密码即可使用gerrit

  1. 配置gitweb

安装gitweb

sudoapt-get install gitweb

配置gitweb,默认没有css加载,把gitweb要用的静态文件连接到DocumentRoot下:

cd/var/www/

sudoln -s /usr/share/gitweb/* .

gerrit.conf添加gitweb.cgi,先在根目录/找到gitweb.cgi的位置,sudofind . -name getweb.cgi,并将该目录添加到gerrit.conf中。

[gitweb]

cgi= /var/www/gitweb.cgi


远程操作:

有了管理员账号,正确为该账号配置公钥之后,管理员就可以远程登录Gerrit的SSH服务器操作数据库,下面就演示一些实例来体会下。

Gerrit帮助说明

先看看管理员通过SSH连接,可以执行的gerrit相关命令有哪些,以下命令列出了所有可以用的命令。

$ ssh ha gerrit --help

gerrit COMMAND [ARG ...] [--] [--help (-h)]

 

 --          : end of options

 --help (-h) : display this help text

 

Available commands of gerrit are:

 

   approve

   ban-commit

   create-account

   create-group

   create-project

   flush-caches

   gsql

   ls-groups

   ls-projects

   plugin

   query

   receive-pack

   rename-group

   review

   set-account

   set-project

   set-project-parent

   set-reviewers

   show-caches

   show-connections

   show-queue

   stream-events

   test-submit-rule

   version

 

See 'gerrit COMMAND --help' for more information.

查询数据库

输入以下命令就可以开始远程操作Gerrit数据库,操作数据库用的都是SQL语法(需要懂得一些SQL语法的东东了)。

$ ssh ha gerrit gsql

Welcome to Gerrit Code Review 2.5.2

(H2 1.2.147 (2010-11-21))

 

Type '\h' for help.  Type '\r' to clear the buffer.

 

gerrit>

如果之前你无法在Gerrit中注册email,那么可以手工进行注册email,运行GSQL工具更新特定数据字段。

         查看Gerrit数据库中所有用户信息,即查看ACCOUNT_EXTERNAL_IDS表记录。

gerrit> select * from ACCOUNT_EXTERNAL_IDS order by ACCOUNT_ID;

 ACCOUNT_ID | EMAIL_ADDRESS       | PASSWORD | EXTERNAL_ID

 -----------+---------------------+----------+---------------------------

 1000000    | NULL                | NULL     | gerrit:kaoya

 1000000    | NULL                | NULL     | username:kaoya

 1000000    | magic_kaoya@163.com | NULL     | mailto:magic_kaoya@163.com

 1000001    | NULL                | NULL     | gerrit:user1

 1000001    | NULL                | NULL     | username:user1

 1000001    | user1@163.com       | NULL     | mailto:user1@163.com

 1000002    | NULL                | NULL     | username:user99

 1000002    | user99@163.com      | NULL     | mailto:user99@163.com

 1000003    | NULL                | NULL     | username:user98

 1000003    | user98@163.com      | NULL     | mailto:user98@163.com

 1000003    | NULL                | NULL     | gerrit:user98

 1000004    | NULL                | 1234     | username:user97

 1000004    | user97@163.com      | NULL     | mailto:user97@163.com

 1000005    | NULL                | NULL     | gerrit:user99

 1000005    | NULL                | NULL     | username:user999

 1000006    | NULL                | NULL     | gerrit:user80

 1000006    | NULL                | NULL     | username:user80

(17 rows; 18 ms)


新建账号:

通过远程命令创建账号,命令用法可以通过ssh ha gerrit create-account –h查看。如下创建一个用户名为user1,全名为“张三” ,邮箱为user1@163.com的Gerrit账号。

$ ssh-keygen -t rsa -C "张三" -f ~/.ssh/user1

Generating public/private rsa key pair.

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/Administrator/.ssh/user1.

Your public key has been saved in /home/Administrator/.ssh/user1.pub.

The key fingerprint is:

47:33:fe:fc:2a:f6:00:39:12:5e:03:8a:91:6f:be:4f 张三

The key's randomart image is:

+--[ RSA 2048]----+

|  ..  .          |

|  .o . .         |

|  ... . o +      |

|    o. o = o     |

|   o  o S o      |

|    .  . + o     |

|     .E   . o    |

|    ..    o. .   |

|     ..  . oo..  |

+-----------------+

 

$ cat ~/.ssh/user1.pub | ssh ha gerrit create-account --email user1@163.com --full-name张三 --ssh-key -<it create-account --email user1@163.com --full-name张三 --ssh-key - user1

$

查看下数据库,看看有没有创建成功了:

$ ssh ha gerrit gsql

Welcome to Gerrit Code Review 2.5.2

(H2 1.2.147 (2010-11-21))

 

Type '\h' for help.  Type '\r' to clear the buffer.

 

gerrit> select * from ACCOUNT_EXTERNAL_IDS;

 ACCOUNT_ID | EMAIL_ADDRESS       | PASSWORD | EXTERNAL_ID

 -----------+---------------------+----------+---------------------------

 1000000    | NULL                | NULL     | gerrit:admin

 1000000    | NULL                | NULL     | username:admin

 1000000    | magic_kaoya@163.com | NULL     | mailto:magic_kaoya@163.com

 1000001    | NULL                | NULL     | username:user1

 1000001    | user1@163.com       | NULL     | mailto:user1@163.com

(5 rows; 2 ms)

gerrit>

gerrit> select FULL_NAME, PREFERRED_EMAIL, ACCOUNT_ID from ACCOUNTS;

 FULL_NAME | PREFERRED_EMAIL     | ACCOUNT_ID

 ----------+---------------------+-----------

 NULL      | magic_kaoya@163.com  | 1000000

 张三       | user1@163.com       | 1000001

(2 rows; 2 ms)

gerrit>

gerrit> select * from ACCOUNT_SSH_KEYS;




参考文档:http://blog.csdn.net/ljchlx/article/details/22277311

http://blog.csdn.net/ganshuyu/article/details/8978614

http://my.oschina.net/zhongl/blog/33017

http://blog.csdn.net/benkaoya/article/details/8680886

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值