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的整合使用

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