安裝gerrit服務器
阿新 • • 發佈:2019-05-01
passwd www. view oracl sig requests via open ali
一、環境準備
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等模塊:
[[email protected] 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
安裝gerrit服務器