-
Gerrit+apache2服务器搭建
1.1配置gerrit管理帐号
sudo adduser gerrit
增加sudo权限:
sudo usermod -a -G sudo gerrit
sudo su gerrit
1.2 安装java
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-7-jdk
1.3 安装git
sudo apt-get install git
1.4. 安装配置apache2
sudo apt-get install apache2
1.5 修改配置文件
sudo vi /etc/apache2/httpd.conf``` <VirtualHost *:8081> ServerName 172.21.16.236 ProxyRequests Off ProxyVia Off ProxyPreserveHost On <Proxy *> Order deny,allow Allow from all </Proxy> <Location "/login/"> AuthType Basic AuthName "Gerrit Code Review" Require valid-user AuthBasicProvider file AuthUserFile /home/gerrit/review_site/passwords </Location> AllowEncodedSlashes On ProxyPass / http://127.0.0.1:8091/ nocanon </VirtualHost> ```
注:如httpd.conf没有Include到apache2.conf中,需手动添加
sudo vi /etc/apache2/apache2.conf
添加 Include httpd.conf
修改配置文件,添加对8081端口的监听:
sudo vi /etc/apache2/ports.conf
添加,
Listen 8081
配置如下:
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf
Listen 80
Listen 8081
<IfModule ssl_module>
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
开启SSL、Proxy、Rewrite等模块:
cd /etc/apache2/mods-enabled/
1 sudo ln -s ../mods-available/proxy.load
2 sudo ln -s ../mods-available/proxy.conf
3 sudo ln -s ../mods-available/proxy_http.load
4 sudo ln -s ../mods-available/proxy_balancer.conf
5 sudo ln -s ../mods-available/proxy_balancer.load
6 sudo ln -s ../mods-available/rewrite.load
7 sudo ln -s ../mods-available/ssl.conf
8 sudo ln -s ../mods-available/ssl.load
9 sudo ln -s ../mods-available/slotmem_shm.load
10 sudo ln -s ../mods-available/socache_shmcb.load
- 安装配置gerrit
下载地址:https://www.gerritcodereview.com/
本文用的版本是gerrit-2.13.6。
安装:
java -jar gerrit-2.13.6.war init -d ~/review_site
安装配置先选择默认配置,安装完成后再来修改配置文件:
vi ~/review_site/etc/gerrit.config
具体内容如下:
[gerrit]
basePath = git
canonicalWebUrl = http://172.21.16.236:8081/
[database]
type = h2
database = /home/gerrit/review_site/db/ReviewDB
[index]
type = LUCENE
[auth]
type = HTTP
[receive]
enableSignedPush = false
[sendemail]
smtpServer = localhost
[container]
user = gerrit
javaHome = /usr/lib/jvm/java-7-openjdk-amd64/jre
[sshd]
listenAddress = *:29418
[httpd]
listenUrl = proxy-http://*:8091/
[cache]
directory = cache
[gitweb]
type = gitweb
cgi = /usr/lib/cgi-bin/gitweb.cgi
接下来,配置gerrit账户:
touch ~/review_site/passwords
sudo htpasswd -b ~/review_site/passwords admin 123123
- 安装配置gitweb
sudo apt-get install gitweb
查看相关配置文件安装路径:
dpkg -L gitweb
得到输出如下:
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/gitweb
/usr/share/doc/gitweb/examples
/usr/share/doc/gitweb/examples/index.aux-generation
/usr/share/doc/gitweb/README.Debian
/usr/share/doc/gitweb/copyright
/usr/share/doc/gitweb/README
/usr/share/doc/gitweb/NEWS.Debian.gz
/usr/lib
/usr/lib/cgi-bin
/etc
/etc/apache2
/etc/apache2/conf.d
/etc/apache2/conf.d/gitweb
/etc/gitweb.conf
/usr/share/doc/gitweb/changelog.Debian.gz
/usr/lib/cgi-bin/gitweb.cgi
根据上面的地址在gerrit.conf中添加如下配置:
[gitweb]
type = gitweb
cgi = /usr/lib/cgi-bin/gitweb.cgi
相关说明:
gitweb集成gerrit后,默认只有管理员用户才能查看gitweb超链接,普通用打开链接后页面显示Not Found。如果想给普通的用户查看gitweb超链接的权限,则必须对项目设置refs/meta/config 的read权限。而这个权限在All-Projects的ACL里只对Administrators用户和Project Owners开放。
7. 重启gerrit和apache2
sudo ~/review_site/bin/gerrit.sh restart
sudo /etc/init.d/apache2 restart
- 访问gerrit 管理界面
浏览器输入:
http://172.21.16.236:8081/
在弹出框输入htpasswd命令设置的账号密码即可。
-
设置gerrit 开机自启动
复制 review_site/bin/gerrit.sh 到/etc/init.d/gerrit
并修改gerrit 文件,将GERRIT_SITE_1 改为你需要的路径
-
如果client 端是ubuntu16 以上,有可能会遇到如下无法读取远程仓库的问题。
Unable to negotiate with 172.21.16.199 port 29418: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1fatal:
无法读取远程仓库。
请确认您有正确的访问权限并且仓库存在。
为解决这个问题:可以在 ~/.ssh/config 文件加入:
Host *.*.*.*
KexAlgorithms +diffie-hellman-group1-sha1
如果没有~/.ssh/config文件,在该文件夹中创建config文件。
- 针对突然gerrit start 提示如下问题。 可以尝试用重新做一下java -jar gerrit-2.13.6.war init -d ~/review_site, 此命令只做做更新,不会覆盖你的配置。
做之前最好备份一下 review_site 下的git 和db 数据。