Gerrit安裝手冊

1.安裝git


2.安裝java


3.下載gerrit 安裝包
官網:https://code.google.com/p/gerrit/


4.可以選擇新建一個專用用戶gerrit




5.安裝過程中一直選擇默認就可以,安裝完後再手動修改配置文件即可,注意有幾個地方需要手動輸入


安裝方法:


java -jar gerrit-2.6.1.war init -d review_site_project/
•Git代碼庫的位置 [git]


•導入現有代碼庫 [Y/n]


•數據庫服務器類型 [H2/?]


•身份驗證方法 [OPENID/?]   HTTP  (採用http的反向代理 HTTP)
{development_become_any_account 這種模式不需要任何認證}(不建議用於實際使用)


•SMTP服務器主機名 [localhost]


•SMTP服務器端口 [(default)]


•SMTP加密 [NONE/?]


•SMTP用戶名


•以何種身份運行 [you]


•Java運行時 [/path/to/jvm]


•將gerrit.war複製到/path/to/location/bin/gerrit.war [Y/n]


•監聽地址 [*]


•監聽端口 [29418]  (ssh監聽的端口。默認不做改動)


•下載並安裝Bouncy Castle[Y/n]


•位於HTTP反向代理之後 [y/N]


•使用SSL [y/N]


•監聽地址 [*]


•監聽端口 [8080] (web瀏覽的apache端口,注意不要與apache現有端口重複)


6.安裝完後gerrit自我啓動


可以使用
netstat -ltpn | grep -i gerrit 查看端口使用情況


7.啓動gerrit的腳本


/home/user/review_site/bin/gerrit.sh start
/home/user/review_site/bin/gerrit.sh restart
/home/user/review_site/bin/gerrit.sh stop
如果啓動不了,可能需要關掉防火牆 service iptables stop


8.配置文件
etc/gerrit.config
[gerrit]
#倉庫文件夾
basePath = git
#瀏覽地址
canonicalWebUrl = http://192.168.0.33
#數據庫配置
[database]
type = h2
database = db/ReviewDB
[index]
type = LUCENE
#代理模式
[auth]
type = HTTP
#郵箱配置
[sendemail]
  enable = true
smtpServer = smtp.exmail.qq.com
smtpServerPort = 465
smtpEncryption = ssl
smtpUser = [email protected]
smtpPass = xxx
sslVerify = false
from = CodeReview<[email protected]
[container]
user = user
javaHome = /usr/lib/jvm/java-7-openjdk-amd64/jre
[sshd]
listenAddress = *:29418
[httpd]
listenUrl = proxy-http://*:8081/
[cache]
directory = cache




9.apache反向代理


user@cshaoyi:~/review_site$ nl /etc/apache2/sites-enabled/gerrit
<VirtualHost 192.168.0.33:80>
此處的80端口號不能跟gerritconfig的listenURL重複
sudo netstat -lnp | grep 80 查看端口使用情況




NameVirtualHost 192.168.0.33:80
<VirtualHost 192.168.0.33:80>  
ServerName localhost


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
AuthUserFile /home/user/review_site/etc/passwd
</Location>


AllowEncodedSlashes On
ProxyPass / http://192.168.0.33:8081/
ProxyPassReverse / http://192.168.0.33:8081/
</VirtualHost>




PS:安裝完gerrit會發現賬號無法sign out
爲什麼不能Sign Out
發現用gerrit+HTTP認證,通過web登陸後,點擊右上角的Sign Out無法登出。要麼是依然保持登陸的狀態,要麼就是直接出錯。
不要以爲怎麼了,其實這是正常現象,以下這段話是從網上看到的:You are using HTTP Basic authentication. There is no way to tell
abrowser to quit sending basic authentication credentials, to logout with basicauthentication is to
這個時候需要關閉瀏覽器重新打開gerrit就可以正常sign out


10.配置了apache反向代理需要打開module配置


cd /etc/apache2/mods-enabled
$sudo ln -s /etc/apache2/mods-available/proxy.conf proxy.conf


$sudo ln -s /etc/apache2/mods-available/proxy.load proxy.load


$sudo ln -s /etc/apache2/mods-available/proxy_http.load proxy_http.load




啓動apache2
sudo /etc/init.d/apache2 restart
sudo services apache2 restart


11.新建gerrit個人賬號
htpasswd -cb /path/password username passwd
-c 新建文件(只需第一次)
-b 新建帳號




12.登錄註冊帳號(系統默認第一個登錄gerrit用戶爲01管理員用戶)




13.遠程查詢數據庫


ssh -p 24918 帳號@地址 gerrit gsql


PS:可以單獨配置遠程連接設置
在.ssh/config
Host xunhu
HostName 192.168.0.33
User caishaoyi
Port 29418
IdentityFile ~/.ssh/id_rsa.pub



$ ssh xunhu gerrit --help
gerrit COMMAND [ARG ...] [--] [--help (-h)]


--help (-h) : display this help text


Available commands of gerrit are:
approve
ban-commit
create-account
create-group
create-project
flush-caches
gsql
ls-groups
ls-projects
plugin
query
receive-pack
rename-group
review
set-account
set-project
set-project-parent
set-reviewers
show-caches
show-connections
show-queue
stream-events
test-submit-rule
version






14.h2數據庫查詢語言,參考mysql
查詢數據庫
select * from ACCOUNT_EXTERNAL_IDS order by ACCOUNT_ID;
select FULL_NAME, PREFERRED_EMAIL, ACCOUNT_ID from ACCOUNTS;


15:hooks腳本,拷貝gerrit提供的文件
scp -r xunhu:/ gerrit-files
scp xunhu:/hooks/commit-msg commit-msg


16.純遠程建立新用戶
ssh-keygen -t rsa -C "張三" -f ~/.ssh/user1
cat ~/.ssh/user1.pub | ssh xunhu gerrit create-account --email [email protected] --full-name張三 --ssh-key -<it
create-account--email [email protected] --full-name張三 --ssh-key - user1






17.我這裏介紹三種方法來設置/修改gerrit用戶的郵箱地址。
a)gerrit自動發送確認郵件(默認方法);


設置代轉郵箱
  enable = true
smtpServer = smtp.exmail.qq.com
smtpServerPort = 465
smtpEncryption = ssl
smtpUser = [email protected]
smtpPass = trf123
sslVerify = false
from = CodeReview<[email protected]>


2)通過gerrit set-account修改(強烈推薦);gerrit服務器所在環境發送郵件有困難,那麼你可以選擇通過管理遠程設置/修改gerrit用戶的郵箱地址


ssh ha gerrit set-account --add-email [email protected] user99




3)通過SQL語法修改數據庫(建議不要用);
select * from ACCOUNT_EXTERNAL_IDS;
insert into ACCOUNT_EXTERNAL_IDS
-> values
-> ('1000000', '[email protected]', 'NULL', 'mailto:[email protected]');






18.
新建項目


創建代碼庫,以manifest爲例命令如下:
ssh -p 29418 [email protected] gerrit create-project -p All-Projects -n manifest --empty-commit --permissions-only


批量建庫,可以通過整理庫列表,使用如下腳本來完成
for i in `cat project-list`;do ssh -p 29418 [email protected] gerrit create-project -p project -n project/$i --empty-commit;done


移入已有項目
ln -s xx xxx  可通過軟鏈接關聯到配置的gerrit倉庫文件夾


19.參照使用手冊
權限管理


組別創建


用戶分組


20.gitweb的整合使用

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章