一、环境准备
1.Java环境
gerrit依赖,用于安装gerrit环境。
下载:jdk-7u79-linux-x64.tar.gz http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html 安装:tar zxvf ./jdk-7u79-linux-x64.tar.gz -C /usr/local
配置:vim ~/.bashrc(针对当前用户) or vim /etc/profile(针对所有用户,推荐)
export JAVA_HOME=/usr/local/jdk1.8
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
验证java环境
java -version
2.git环境
gerrit依赖,用来操作git repository。
yum install git
3.gerrit环境
下载:Gerrit 2.12.4 https://www.gerritcodereview.com/download/gerrit-2.12.4.war
4.apache2环境
yum -y install httpd mod_ssl
5.gerrit管理帐号(可选,使用独立账号配置gerrit)
gerrit依赖,用来管理gerrit。
sudo adduser gerrit sudo passwd gerrit
并将gerrit加入sudo权限
visudo gerrit ALL=(ALL:ALL) ALL
二、安装与配置gerrit
1.配置gerrit
默认安装:java -jar gerrit-2.12.4.war init --batch -d ~/review_site
更新配置文件:vim ~/review_site/etc/gerrit.config
[gerrit]
basePath = git #默认gerrit对应的git库
canonicalWebUrl = http://10.121.8.179:8081/ #gerrit web管理界面
[database]
type = h2 #h2数据库
database = db/ReviewDB #数据库路径
[index]
type = LUCENE
[auth]
type = HTTP #auth模式,默认为OPENID,配置为HTTP,需要apache配置反向代理
[receive]
enableSignedPush = false
[sendemail]
enable=false #关闭邮件提醒
[container]
user = gerrit #linux user for gerrit
javaHome = /usr/local/jdk1.8/jre #java home
[sshd]
listenAddress = *:29418 #default gerrit port
[httpd]
listenUrl = http://*:8081/
[cache]
directory = cache
[http]
proxy = http://10.121.8.179:8080 #proxy server
proxyUsername = gerrit #proxy user & password
proxyPassword = 123456
2.配置apache2反向代理
更新配置文件:sudo vim /etc/apache2/sites-enabled/gerrit-httpd.conf
<VirtualHost *:8080>
ServerName 10.121.8.179
ProxyRequests Off
ProxyVia Off
ProxyPreserveHost On
AllowEncodedSlashes On
RewriteEngine On
RewriteRule ^/(.*) http://10.121.8.179:8081/$1 [NE,P] <Proxy *>
Order deny,allow
Allow from all
</Proxy> <Location /login/>
AuthType Basic
AuthName "Gerrit Code Review"
Require valid-user
AuthBasicProvider file
AuthUserFile /etc/httpd/passwords
</Location> ProxyPass / http://10.121.8.179:8081/ </VirtualHost
开启SSL、Proxy、Rewrite等模块:
[username@hostname apache2]$ vi conf/http.conf
# Open LoadModule
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule rewrite_module modules/mod_rewrite.so
# Gerrit config
Include conf/extra/gerrit-httpd.conf
其中apache2/conf/extra/gerrit-httpd.conf内容同上,apache2/sites-enabled/gerrit-httpd.conf。
3.配置gerrit账户密码
touch /etc/apache2/passwords htpasswd -b /etc/apache2/passwords admin 123456(管理员) htpasswd -b /etc/apache2/passwords gerrit1 123456(普通用户)
4.启动gerrit&启动apache2
/home/review_site/bin/gerrit.sh restart
systemctl restart httpd
5.访问gerrit 管理界面 http://10.121.8.179:8080/
第一次访问,需要输入第3步设置的admin及密码,该账户将作为gerrit管理员账户。进入后可设置FullName: GerritAdmin。
下载代码
git clone ssh [email protected]:29418/demo-project
上传代码
git push origin HEAD:refs/for/master