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

我正在试图find在Tomcat下安装Gerrit以及LDAP支持的很好的说明。 我需要安装在Windows 2008 Server上,最好。 但是,如果不可能,我可以selectLinux。

Gerrit指令仅涵盖docker安装:

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

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

我find了一些有用的链接,但是没有把这些设置整合在一起。

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

我总是可以设置这个试验和错误,但如果有人已经解决了这个问题,我宁愿节省时间。

我决定继续这个答案,因为这是Gerrit社区所需要的。 目前,还没有很多关于Gerrit高级设置的教程。 我希望这将帮助其他人探索XP /敏捷实践并使Gerrit运行起来。 一旦你通过了所有微妙的设置挑战和细节,这是一个伟大的工具。

这个安装教程是相当独特的,因为它服务于特定的环境:

  • Windows 2008 Server
  • PostgreSQL的
  • Tomcat的
  • 通过Active Directory的LDAP
  • 格里特
  • msysgit

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

确保你得到“官方Git for Windows的完整安装程序”。

  • 安装MSysGit
  • 出现提示时使用默认值
  • configurationGit

如果你打算在msysgit中使用GitWeb版本,你会注意到CGI.pm的一些问题。 我想提一个解决这个问题的解决方法。

msysgit发行版中包含的perl版本(从1.7.8开始)被破坏, http: //groups.google.com/group/msysgit/browse_thread/thread/ba3501f1f0ed95af。 unicore文件夹与utf8_heavy.pl和CGI.pm一起丢失。 您可以通过检查perl模块进行validation:

perl -mCGI -mEncode -mFcntl -mFile :: Find -mFile :: Basename -e“”您可能会遇到以下exception:

$ perl -mCGI -mEncode -mFcntl -mFile :: Find -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失败 – 编译中止。

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

http://strawberryperl.com/releases.html

File:strawberry-perl-5.8.8.3.zip

内容:bin / lib / site /

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

如果使用命令行git,请将您的全局configuration设置添加到git中:

git config --global user.name "Your Name" git config --global user.email [email protected] git config --global core.autocrlf false 

确保这里使用的凭证与gerrit中的凭证相匹配。 否则,gerrit会拒绝你的请求。

Gerrit的安装和configuration说明如下:

  • 首先,login到托pipepostgres的服务器,并为Gerrit创build一个用户和数据库
  • createuser –username = postgres -A -D -P -E gerrit2
  • createdb –username = postgres -E UTF-8 -O gerrit2 reviewdb
  • 现在,切换回主机(如果不同),为Gerrit创build3个目录来部署Gerrit
  • 为gerrit创build一个基本安装目录,最好是war部署内容的版本化目录
  • 为tomcat创build一个子目录
  • 创build一个用于部署模式和configuration的configuration目录
  • 内容应该是这样的:
  • 格里特
    • tomcat的
    • configuration
    • 格里特-XX
  • http://tomcat.apache.org/download-60.cgi下载tomcat
  • 注意:大多数Linux发行版都可以从他们的更新pipe理器获得。 例如:在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
    • 此configuration包含LDAP的附加function,并在代理之后运行,如果不需要,请不要configuration这些选项。

执行:

 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]: [email protected] [email protected]'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设置为服务器,我们将在稍后进行configuration
  • 编辑configuration\ etc \ gerrit.config
  • 在gerrit部分,添加一个设置为conicalWebUrl = http://review.corporation.com/
  • 如果您的项目不遵循传统的project.git格式,请添加以下部分:
  • 将文件locaiton和url以及关联的属性添加到您的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 
  • http://www.bouncycastle.org/latest_releases.html下载最新版本的Bouncy Castles
  • 复制bcmail-jdk15on-147.jar,bcpg-jdk15on-147.jar,bcpkix -jdk15on-147.jar,bcprov -jdk15on-147.jar,bcprov-ext-jdk15on -147.jar到gerrit-XX \ WEB-INF \ LIB
  • 编辑server.xml。 将gerrit部署添加到server.xml的Host部分:(注意:对于Tomcat 7,而不是server.xml,可能需要编辑context.xml,请参阅: http : //tomcat.apache.org/tomcat- 7.0-doc / jndi-datasource-examples-howto.html#MySQL_DBCP_Example )

在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连接器。 我使用它来卸载SSLencryption和pipe理证书。 如果不需要,就把它删除。 如果您打算独立运行,请确保将您的HTTP连接器端口更改为80。

  • 上面的configuration适用于postgres。 如果你使用的是MySQL,你将不得不用MySQLreplace下面的资源:

在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" /> 

此时,您已准备好将Gerritconfiguration为服务,并将审阅系统联机。

  • 首先,调整运行Gerrit即服务的Tomcat设置
  • 转到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> 

转到您的服务器pipe理器并打开服务节点。 打开Gerrit的属性,并确保将启动types设置为Automatic:

服务

应用并closures对话框。

好的…我们完成了吗? 不幸的是,只有更多的步骤去。 挂在那里。

现在你已经准备好开始这项服务了。 只需突出显示Gerrit服务,然后单击左侧的开始选项。

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

你应该能够到你的浏览器,并input您的服务器的URL来查看Gerrit现在: http ://review.corporation.com: 8080

你会被提示input你的SSH公钥。 这只有在你打算通过ssh而不是HTTP来使用Git / Gerrit时才是必须的。 我继续设置它,因为这是一个很好的select。

configurationSSH

生成一个用于访问的ssh密钥:

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

在Gerrit中通过您所select的电子邮件地址login一个新帐户。 login和注册帐户的第一个用户将被自动置于完全特权的pipe理员组中,允许通过networking和SSH进行服务器pipe理。 后续用户将被自动注册为非特权用户。

一旦以您的用户身份login,您会发现一个小向导让您开始。 该向导可帮助您填写:

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

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

只为注册用户configurationHTTP访问权限,除非您的项目向公众开放:

在这里输入图像描述

生成一个HTTP密码

尽pipe已经configuration了自己的login名,但仍然需要通过http / https生成gerrit到服务器的密码。 转到您的设置 – > HTTP密码configuration,然后点击“生成密码”。 通过http(s)使用此密码进行所有git操作。

现在我们可以通过HTTPtestingGerrit。 您应该能够克隆Gerritconfiguration中引用的存储库中的任何项目。

用克隆操作进行testing

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

testing你的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://[email protected]:29418/REPOSITORY_NAME.g it Connection to localhost closed. 

从Gerrit通过SSH克隆一个项目:

 Administrator@SERVER~/test $ git clone ssh://[email protected]: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. 

如果你现在还没有放弃,你可以放松一下,你应该find一个由Windows 2008服务器托pipe的Gerrit代码审查系统:)它不像设置一样普通,你可以告诉所有额外的脚步。 但是,我们有些人资源有限,只能使用提供的资源。 我希望这个教程可以帮助那些试图在类似环境中运行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