Windows环境下配置Gerrit和GitWeb要点说明

Windows环境下Gerrit环境搭建

Gerrit的搭建在Linux系统下的资料比较多,而在Windows系统上的参考资料相对较少,有些配置也需要一定的技巧才能解决,这些记录说明一下过程。
另外,本次配置的环境也比较特别,运行Gerrit服务的主机IP是192.168.1.198, 它是一台局域网机器,通过共用的外网110.xx.xx.xx来连接外网。我们要从外网来访问这台局域网运行的gerrit服务器。

软件版本选择

所需基本软件版本都选择较新的:git-2.18, jdk-1.8, gerrit-2.15.3, apache 2.2.
这四者的安装都按照常规安装即可,最后所有的配置都通过修改配置文件来进行,具体安装过程可参考gerrit 在win7下安装总结. 安装完成后,要设置好这4个软件软件的PATH环境变量,方便后续执行。
以下主要列举说明主要配置的要点。

Apache配置

Apache的配置文件在D:\GIT\Apache2.2\conf\http.conf,首先打开如下模块,即去掉前面的#号即可:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule negotiation_module modules/mod_negotiation.so

然后设置

<VirtualHost *:8080>

ServerName localhost
ProxyRequests Off
ProxyVia Off
ProxyPreserveHost On
AllowEncodedSlashes On

<Proxy *:8080>
Order deny,allow
Allow from all
</Proxy>

<Location /login/>
AuthType Basic
AuthName “Gerrit Code Review”
Require valid-user
AuthUserFile D:/GIT/htpasswd
</Location>

ProxyPass / http://110.xx.xx.xx:9080/ nocanon
ProxyPassReverse / http://192.168.1.198:9080/

</VirtualHost>

其中

AllowEncodedSlashes On
ProxyPass / http://110.xx.xx.xx:9080/ nocanon

的设置非常重要,解决查看二级目录下Apache对”/”的编码导致的gerrit无法识别路径的问题。
上面还一个ProxyPassReverse的设置,并没有设置与ProxyPass相同,这也是根据实际调试结果,当Apache完成用户认证后进行跳转,需要此项。
在命令行中执行httpd.exe -k install ,安装apache到服务中,通过“计算机管理”-“服务”可查看,进行重启等操作,其默认服务名称为”Apache 2.2”.

gerrit配置

其配置文件在 D:\GIT\gerrit\etc\gerrit.config,内容配置如下:
>

[gerrit]
basePath = git
serverId = e6534ffd-9199-45a4-a2eb-177649829d1a
canonicalWebUrl = http://192.168.1.198:9080/
[database]
type = h2
database = D:\GIT\gerrit\db\ReviewDB
[noteDb “changes”]
disableReviewDb = true
primaryStorage = note db
read = true
sequence = true
write = true
[index]
type = LUCENE
[auth]
type = HTTP
logoutUrl = http://aa:[email protected]:8080/logout
[receive]
enableSignedPush = false
[sendemail]
[sendemail]
smtpServer = smtp.163.com
smtpUser = [email protected]
smtpPass = userpass
from = [email protected]
[container]
user = gerrit
javaHome = C:\Program Files\Java\jre1.8.0_181
[sshd]
listenAddress = *:29418
[httpd]
listenUrl = http://*:9080/
[cache]
directory = cache
[gitweb]
type = gitweb
cgi = “C:\Program Files\Git\mingw32\share\gitweb\gitweb.bat”

可通过执行gerrit.sh restart进行重启等操作。执行gerrit.sh run进行调试工作,实时打印log信息。
下面主要说明的是gitweb的配置

gitweb配置

其中gitweb.bat的内容如下:

@echo off
“C:\Program Files\Git\usr\bin\perl.exe” C:\”Program Files”\Git\mingw32\share\gitweb\gitweb.cgi %*

主要参考在window上集成Gitweb和Gerrit, 主要问题是在Windows版本的Git上,gitweb的支持并不好,需要安装CGI模块,可以从这里下载CGI.pm-3.65最新版本

然后把CGI.pm-3.65/lib/目录中的内容复制到C:\Program Files\Git\mingw32\share\perl5\site_perl中。 把创建的gitweb.bat放在C:\Program Files\Git\mingw32\share\gitweb\中。
在测试中发现执行gitweb.bat时,系统并不从mingw32目录中搜索相关CGI.pm,所以将mingw32\share\perl5\site_perl目录复制到usr\share\perl5中。

还需要修改C:\Program Files\Git\mingw32\share\gitweb\gitweb.cgi中如下两个设置:
>

# core git executable to use
# this can just be “git” if your webserver has a sensible PATH
our $GIT = “/mingw64/bin/git”;

# absolute fs-path which will be prepended to the project path
our $projectroot = “/d/GIT/gerrit/git”;

其中* our $GIT * 设置的git命令的安装位置,系统一般自动设置,此项一般不需要修改。

our $projectroot则需要设置gerrit中代码仓库的目录位置。

在上面gerrit.conf设置项[gitweb]配置中还要加上

type=gitweb

测试时发现,没有加此项gitweb仍无法正常工作。

另外注意,还要修改refs/meta/config权限,允许普通注册用户查看gitweb, 否则,即使前面都配置正确,仍然会页面Not Found的提示。

好了,基本要点完毕。

猜你喜欢

转载自blog.csdn.net/ygd11/article/details/81406791
今日推荐