如何使用LDAP在Tomcat下安装Gerrit?


11

我正在尝试找到有关在具有LDAP支持的Tomcat下安装Gerrit的好的说明。我最好将此安装在Windows 2008 Server上。但是,如果不可能的话,我可以选择Linux。

Gerrit说明仅涵盖在码头下的安装:

http://gerrit.googlecode.com/svn/documentation/2.1.3/install-j2ee.html#installation

如果我希望在不同的环境下进行设置,则没有太多工作要做。

我确实找到了一些有用的链接,但是没有将所有设置整合在一起。

http://codeslife.com/2011/06/08/install-gerrit-locally-under-windows/ http://gerrit.googlecode.com/svn/documentation/2.1.7/config-gerrit.html#_a_id_ldap_a_section_ldap http ://code.google.com/p/gerrit/issues/detail?id = 292

我总是可以设置试错法,但是如果有人已经解决了这些问题,我希望节省时间。

Answers:


21

我决定继续回答这个问题,因为Gerrit社区需要这种解决方案。当前,没有很多关于Gerrit的高级设置的教程。我希望这将帮助其他人探索XP /敏捷实践并启动Gerrit并使其运行。一旦您克服了所有细微的设置挑战和细节,它便是一个很棒的工具。

该安装教程在服务于特定环境方面非常独特:

  • Windows 2008服务器
  • PostgreSQL的
  • 雄猫
  • 通过Active Directory的LDAP
  • 格里特
  • msysgit

在开始之前,请确保已在系统上安装了git。从http://code.google.com/p/msysgit/downloads/list下载适用于Windows的最新msysgit命令行工具

确保获得“用于Windows的正式Git的完整安装程序”。

  • 安装MSysGit
  • 出现提示时使用默认值
  • 配置Git

如果打算在msysgit中使用GitWeb版本,则会注意到CGI.pm周围的一些问题。我想提一个解决此问题的修补程序。

http://groups.google.com/group/msysgit/browse_thread/thread/ba3501f1f0ed95af自1.7.8版起,包含在msysgit发行版中的perl已损坏。unicore文件夹与utf8_heavy.pl和CGI.pm一起丢失。您可以通过检查perl模块进行验证:

perl -mCGI -mEncode -mFcntl -mFile ::查找-mFile :: Basename -e“”您可能会遇到以下异常:

$ perl -mCGI -mEncode -mFcntl -mFile ::查找-mFile :: Basename -e“”在@INC中找不到CGI.pm(@INC包含:/usr/lib/perl5/5.8.8/msys / usr / lib / p erl5 / 5.8.8 /usr/lib/perl5/site_perl/5.8.8/msys /usr/lib/perl5/site_perl/5.8.8 / u sr / lib / perl5 / site_perl。)。BEGIN失败-编译中止。

如果缺少CGI.pm,则必须将模块部署到msys环境:您必须从5.8.8发行版中检索它们:

http://strawberryperl.com/releases.html

档案:Strawberry-Perl-5.8.8.3.zip

内容:bin / lib / site /

将lib的内容复制到msysgit / lib / perl5 / 5.8.8中并覆盖现有文件。

如果使用命令行git,请将全局配置设置添加到git:

git config --global user.name "Your Name"
git config --global user.email you@corporation.com
git config --global core.autocrlf false

确保此处使用的凭据与gerrit中的凭据匹配。否则,gerrit将拒绝您的请求。

安装和配置Gerrit的说明如下:

  • 首先,登录到托管postgres的服务器,并为Gerrit创建用户和数据库
  • createuser --username = postgres -A -D -P -E gerrit2
  • createdb --username = postgres -E UTF-8 -O gerrit2 reviewdb
  • 现在,切换回用于Gerrit的主机(如果不同),并创建3个目录以部署Gerrit
  • 为gerrit创建基本安装目录,最好是战争部署内容的版本化目录
  • 为tomcat创建一个子目录
  • 创建一个用于部署架构和配置的配置目录
  • 内容应如下所示:
  • 格里特
    • 雄猫
    • 配置
    • Gerrit-XX
  • http://tomcat.apache.org/download-60.cgi下载tomcat
  • 注意:大多数Linux发行版的更新管理器都可以提供此功能。示例:在Ubuntu上使用Synaptic
  • 将您的tomcat安装部署到tomcat目录
  • http://code.google.com/p/gerrit/downloads/list下载最新的gerrit.war 。
  • 将文件复制到基本gerrit目录
  • 将war文件解压缩到gerrit-XX子目录中
  • CD到gerrit基本目录并运行 java -jar gerrit-2.4-rc0.war init -d config
    • 此配置包括LDAP的额外功能,并在代理后面运行,如果不需要,请不要配置这些选项。

执行:

C:\your_path\gerrit>java -jar gerrit-2.4-rc0.war init -d config
*** Gerrit Code Review 2.4-rc0
***
Create 'C:\your_path\gitserver\gerrit\config' [Y/n]? Y
*** Git Repositories
***
Location of Git repositories   [git]: C:\your_path\gitserver\repository\ha
*** SQL Database
***
Database server type           [H2/?]: postgresql
Server hostname                [localhost]: database.corp.local
Server port                    [(POSTGRESQL default)]:
Database name                  [reviewdb]:
Database username              [Administrator]: gerrit2
gerrit2's password             :
              confirm password :
*** User Authentication
***
Authentication method          [OPENID/?]: LDAP
LDAP server                    [ldap://localhost]: ldaps://ldap.corp.local:
636
LDAP username                  : CN=Administrator,CN=Users,DC=corp,DC=local
CN=Administrator,CN=Users,DC=corp,DC=local's password :
              confirm password :
Account BaseDN                 [DC=corp,DC=local:636]: CN=Users,DC=corp,DC=l
ocal
Group BaseDN                   [CN=Users,DC=corp,DC=local]:
*** Email Delivery
***
SMTP server hostname           [localhost]: smtp.corporation.com
SMTP server port               [(default)]: 465
SMTP encryption                [NONE/?]: SSL
SMTP username                  [Administrator]: build@corporation.com
build@corporation.com's password :
              confirm password :
*** Container Process
***
Run as                         [Administrator]:
Java runtime                   [C:\Program Files\Java\jre6]:
Copy gerrit.war to C:\your_path\gitserver\gerrit\config\bin\gerrit.war [Y/n]?
Copying gerrit.war to C:\your_path\gitserver\gerrit\config\bin\gerrit.war
*** SSH Daemon
***
Listen on address              [*]:
Listen on port                 [29418]:
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]? n
Generating SSH host key ... rsa(simple)... done
*** HTTP Daemon
***
Behind reverse proxy           [y/N]?
Use SSL (https://)             [y/N]?
Listen on address              [*]:
Listen on port                 [8080]:
Initialized C:\your_path\gitserver\gerrit\config
Automatic startup not supported on Win32.
  • 不用担心将Gerrit设置为服务器,我们稍后会进行配置
  • 编辑config \ etc \ gerrit.config
  • 在gerrit部分下,为conicalWebUrl = http://review.corporation.com/添加设置
  • 如果您的项目不遵循传统的project.git格式,请添加以下部分:
  • 将文件位置和网址以及相关属性添加到gitweb服务器

gerrit.config更新:

[gitweb]
        cgi = C:\\path to msysgit\\Git\\share\\gitweb\\gitweb.cgi
        url = https://gitweb.corporation.com
        type = custom
        project = ?p=${project};a=summary 
        revision = ?p=${project};a=commit;h=${commit}
        branch = ?p=${project};a=shortlog;h=${branch}
        filehistory = ?p=${project};a=history;hb=${branch};f=${file}
  • 如果您使用http / https进行投放,请添加以下内容:

gerrit.config更新:

[download]
scheme = http
  • 如果您将LDAP与活动目录一起使用,则需要调整设置以添加其他设置以支持AD:

gerrit.config更新:

[ldap]
sslVerify = true
server = ldaps://ldap.corp.local:636
username = CN=Administrator,CN=Users,DC=corp,DC=local
accountBase = CN=Users,DC=corp,DC=local
accountPattern = (&(objectClass=person)(sAMAccountName=${username})) 
accountFullName = displayName 
accountEmailAddress = mail 
accountSshUserName = sAMAccountName 
groupBase = CN=Users,DC=corp,DC=local
groupMemberPattern = (sAMAccountName=${username}) 
groupName = cn

Server.xml:

<Server port="8006" shutdown="SHUTDOWN">
<Service name="Catalina">
 <Engine name="Catalina" defaultHost="localhost">
  <Host name="localhost"  appBase="webapps" unpackWARs="true">
    <Context path="" docBase="C:\your_path\gitserver\gerrit\gerrit-2.4" debug="0" reloadable="false">
        <Resource
           name="jdbc/ReviewDb"
           type="javax.sql.DataSource"
           username="gerrit2"
           driverClassName="org.postgresql.Driver"
           password="secret"
           url="dbc:postgresql://yourPsqlServer:5432/reviewdb"
        />
    </Context>
  </Host>
</Engine>
<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"/>
<Connector port="8011" protocol="AJP/1.3" maxHttpHeaderSize="8192"
           maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
           disableUploadTimeout="true" enableLookups="false"
           acceptCount="100" URIEncoding="UTF-8" />
</Service>
</Server>
  • 除非打算使用Apache HTTP Server进行代理,否则不需要AJP连接器。我用它来减轻SSL加密和管理证书的负担。如果不需要,只需将其删除。如果打算独立运行,请确保将HTTP连接器端口更改为80。

  • 上面的配置适用于postgres。如果您使用的是MySQL,则必须将以下资源替换为MySQL:

Server.xml:

<Resource
name="jdbc/ReviewDb"
type="javax.sql.DataSource"
username="gerrit2"
driverClassName="org.gjt.mm.mysql.Driver"
password="secret"
url="jdbc:mysql://yourMsqlServer/reviewdb?autoReconnect=true"
/>

至此,您现在可以将Gerrit配置为服务,并使审阅系统联机。

  • 首先,调整Tomcat设置以将Gerrit作为服务运行
  • 转到tomcat / bin并编辑service.bat

jvm选项是为nt服务单独设置的。在安装nt服务之前,您必须修改service.bat文件。该文件与其他startup.bat和shutdown脚本一起位于tomcat / bin目录中。向下滚动到以下部分:

"%EXECUTABLE%"  //US//%SERVICE_NAME% \++JvmOptions  "-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties"  \--JvmMs 128 \--JvmMx 256

修改此行以匹配以下内容:

"%EXECUTABLE%" //US//%SERVICE_NAME%  \++JvmOptions  "-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties"  \++JvmOptions="-XX:MaxPermSize=256m"  \++JvmOptions="-XX:+CMSClassUnloadingEnabled"  \++JvmOptions="-XX:+CMSPermGenSweepingEnabled" \--JvmMs 512 \--JvmMx 1024

gerrit的初始内存jvmMs绝对应设置为512Mb,并将JvmMx扩展为1024Mb。

现在,您可以在Windows下将gerrit作为服务部署。只需执行以下命令:

C:\your_path\gitserver\gerrit\tomcat\bin>service install gerrit
Installing the service 'gerrit' ...
Using CATALINA_HOME: "C:\your_path\gitserver\gerrit\tomcat"
Using CATALINA_BASE: "C:\your_path\gitserver\gerrit\tomcat"
Using JAVA_HOME: "C:\Program Files\Java\jdk1.6.0_31"
Using JVM: "C:\Program Files\Java\jdk1.6.0_31\jre\bin\server\jvm.dl
l"
The service 'gerrit' has been installed.

C:\your_path\gitserver\gerrit\tomcat\bin>

转到服务器管理器,然后打开“服务”节点。打开Gerrit的属性,并确保将启动类型设置为Automatic:

服务

应用并关闭对话框。

好...我们完成了吗?不幸的是,没有,只有几步了。等一下

现在,您可以启动服务了。只需突出显示Gerrit服务,然后单击左侧的“开始”选项即可。

查看tomcat / log目录下的日志。确保没有未解决的错误。如果您有问题,可以在此处或在gerrit邮件列表中提问:http ://groups.google.com/group/repo-discuss

您应该能够转到浏览器并输入服务器的URL,以立即查看Gerrit:http ://review.corporation.com: 8080

系统将提示您输入ssh公钥。仅当您打算通过ssh而不是HTTP使用Git / Gerrit时,才需要这样做。我继续进行设置,因为它是一个不错的选择。

配置SSH

生成用于访问的ssh密钥:

Administrator @ SERVER〜/ test $ ssh-keygen -t rsa

通过Web界面使用您选择的电子邮件地址在Gerrit中注册一个新帐户。第一个登录并注册帐户的用户将自动进入具有完全特权的Administrators组,从而可以通过Web和SSH进行服务器管理。后续用户将自动注册为非特权用户。

以用户身份登录后,您会发现一个小向导可以开始使用。该向导可帮助您填写:

  • 真实姓名(在Gerrit中可见的名称)
  • 注册您的电子邮件(必须稍后确认)
  • 选择用于通过ssh + git与Gerrit通信的用户名
  • 服务器将要求您提供RSA公钥。这就是我们上面生成的密钥,是时候确保Gerrit知道我们的新密钥并可以通过它识别我们了。

    user @ host:〜$ cat .ssh / id_rsa.pub

除非您的项目对公众开放,否则仅为注册用户配置HTTP访问:

在此处输入图片说明

产生HTTP密码

尽管已配置了自己的登录名,但仍必须通过http / https为Gerrit生成密码以将其发送到服务器。转到“设置”->“ HTTP密码”配置,然后单击“生成密码”。使用此密码进行所有通过http(s)的git操作。

现在我们可以通过HTTP测试Gerrit。您应该能够克隆在Gerrit配置中引用的资源库中现有的所有项目。

使用克隆操作进行测试

Administrator@SERVER ~/test
$ git clone https://review.corporation.com/sandbox

测试您的ssh帐户

Administrator@SERVER~/test
$ ssh jhuntley@localhost -p 29418

**** Welcome to Gerrit Code Review ****

Hi Jason Huntley, you have successfully connected over SSH.

Unfortunately, interactive shells are disabled.
To clone a hosted Git repository, use:

git clone ssh://jhuntley@review.corporation.com:29418/REPOSITORY_NAME.g
it

Connection to localhost closed.

通过SSH从Gerrit克隆项目:

Administrator@SERVER~/test
$ git clone ssh://jhuntley@127.0.0.1:29418/sandbox
Cloning into 'sandbox'...
remote: Counting objects: 183, done
remote: Finding sources: 100% (183/183)
remote: Total 183 (delta 0), reused 0 (delta 0)Receiving objects: 50% (92/183)
Receiving objects: 52% (96/183)
Receiving objects: 100% (183/183), 23.76 KiB, done.

如果您现在还没有放弃,可以放松一下,您应该使用Windows 2008 Server托管的Gerrit Code Review系统,它可以正常工作:)它不像设置那样常见,并且可以保证所有额外的功能脚步。但是,我们中有些人资源有限,只能使用所提供的资源。我希望本教程对那些希望在类似环境中运行Gerrit的人有所帮助。您现在应该准备开始使用Gerrit!请享用!

有关使用Gerrit的更多信息,请查阅Gerrit项目的用户指南:

http://gerrit-documentation.googlecode.com/svn/Documentation/2.3/index.html

谢谢Shawn Pierce对IRC的帮助!

备查

教程已转换为Gerrit项目的文档。对于那些有兴趣并且需要很好的参考。请在此处查看补丁程序请求:

https://gerrit-review.googlesource.com/#/c/37072


非常好又完整的信息。<p> msysgit的默认“ Windows的Git”不包含CGI.pm,如何管理gitweb?
larrycai 2012年

我不久前解决了这个问题。我注意到如何解决该问题。我会尽快在这里提供更新。
杰森·亨特利

嘿拉里,我已经更新了教程,并包含了GIT.pm问题的修复程序。如果您发现此帖子有用,请对答案进行投票。谢谢!
杰森·亨特利

gitweb是否可以像您描述为CGI那样工作?我创建了gitweb.bat来包装它而不使用apache <p>对于CGI.pm,只需下载CGI.tar.gz并上传到/ usr / lib / perl5 / site_perl就足够了。<p>教程非常完整,但是对于初学者来说,这有点困难;-)
larrycai 2012年

@larrycai,是的,我前一段时间写了本教程,它实际上已经得到改进,并为Gerrit的项目文档做出了贡献。它仍在审查中,但是一旦获得批准,我将更新此问题。感谢您的反馈。哦,是的,gitweb肯定会通过Apache作为CGI运行。
杰森·亨特利
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.