安装gerrit
[root@rmq_3 home]# java -jar gerrit-2.8.war init -d gerrit *** Gerrit Code Review 2.8 *** Create '/home/gerrit' [Y/n]? *** Git Repositories *** Location of Git repositories [git]: *** SQL Database *** Database server type [h2]: *** User Authentication *** Authentication method [OPENID/?]: http Get username from custom HTTP header [y/N]? SSO logout URL : *** Email Delivery *** SMTP server hostname [localhost]: SMTP server port [(default)]: SMTP encryption [NONE/?]: SMTP username : *** Container Process *** Run as [root]: Java runtime [/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.95.x86_64/jre]: Copy gerrit-2.8.war to /home/gerrit/bin/gerrit.war [Y/n]? Copying gerrit-2.8.war to /home/gerrit/bin/gerrit.war *** SSH Daemon *** Listen on address [*]: Listen on port [29418]: Gerrit Code Review is not shipped with Bouncy Castle Crypto v144 If available, Gerrit can take advantage of features in the library, but will also function without it. Download and install it now [Y/n]? Downloading http://www.bouncycastle.org/download/bcprov-jdk16-144.jar ... OK Checksum bcprov-jdk16-144.jar OK Generating SSH host key ... rsa... dsa... done *** HTTP Daemon *** Behind reverse proxy [y/N]? y Proxy uses SSL (https://) [y/N]? Subdirectory on proxy server [/]: Listen on address [*]: Listen on port [8081]: 8080 Canonical URL [http://null/]: *** Plugins *** Install plugin reviewnotes version v2.8 [y/N]? Install plugin download-commands version v2.8 [y/N]? Install plugin replication version v2.8 [y/N]? Install plugin commit-message-length-validator version v2.8 [y/N]? Initialized /home/gerrit Executing /home/gerrit/bin/gerrit.sh start Starting Gerrit Code Review: OK
修改gerrit中的配置文件
[gerrit] basePath = git canonicalWebUrl = [database] type = h2 database = db/ReviewDB [auth] type = HTTP [sendemail] smtpServer = localhost [container] user = root javaHome = /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.95.x86_64/jre [sshd] listenAddress = *:29418 [httpd] listenUrl = proxy-http://172.16.80.238:8080/ [cache] directory = cache
在httpd.conf中添加
<VirtualHost 172.16.80.238:80> ServerName 172.16.80.238 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 /gerrit.password </Location> ProxyPass / http://172.16.80.238:8080/ </VirtualHost>
创建密码文件
touch /gerrit.password
注册管理员
[root@localhost ~]# htpasswd -m /gerrit.password admin New password: Re-type new password: Adding password for user admin
在浏览器输入http://172.16.80.238访问gerrit服务器,出现HTTP Basic Auth认证,输入刚才htpasswd命令创建的用户名和密码,系统就会自动将该用户注册为gerrit的账户。第一个登陆的用户自动注册为管理员(gerrit账号ID为1000000的账户)。
注册用户
[root@localhost ~]# htpasswd -m /gerrit.password zhangsan New password: Re-type new password: Adding password for user zhangsan
用户登录修改设置
添加公钥文件
setting->SSH Public Keys
[root@localhost .ssh]# ssh-keygen -t rsa -C "张三" -f ~/.ssh/zhangsan Generating public/private rsa key pair. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/zhangsan. Your public key has been saved in /root/.ssh/zhangsan.pub. The key fingerprint is: 6c:ed:04:ec:07:4a:4f:4a:15:fa:3d:62:a8:51:6d:e3 张三 The key's randomart image is: +--[ RSA 2048]----+ | o. | | = | | = O | | + % * | | . + E * | | o o = . | | . . | | | | | +-----------------+
复制公钥文件zhangsan.pub内容添加到注册页面的Add SSH Publi Key中,点击Add即可。
测试gerrit的SSH连接
[root@localhost .ssh]# ssh -p 29418 172.16.80.238 -l zhangsan The authenticity of host '[172.16.80.238]:29418 ([172.16.80.238]:29418)' can't be established. RSA key fingerprint is eb:2e:56:8e:49:28:58:c4:05:65:44:94:1b:e1:93:c3. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '[172.16.80.238]:29418' (RSA) to the list of known hosts. Permission denied (publickey).
如果出现权限问题,可以如下操作
[root@localhost ~]# ssh-agent bash [root@localhost ~]# ssh-add ~/.ssh/zhangsan Identity added: /root/.ssh/zhangsan (/root/.ssh/zhangsan)
再次测试
[root@localhost .ssh]# ssh -p 29418 172.16.80.238 -l zhangsan The authenticity of host '[172.16.80.238]:29418 ([172.16.80.238]:29418)' can't be established. RSA key fingerprint is eb:2e:56:8e:49:28:58:c4:05:65:44:94:1b:e1:93:c3. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '[172.16.80.238]:29418' (RSA) to the list of known hosts. **** Welcome to Gerrit Code Review **** Hi 张三, you have successfully connected over SSH. Unfortunately, interactive shells are disabled. To clone a hosted Git repository, use: git clone ssh://[email protected]:29418/REPOSITORY_NAME.git Connection to 172.16.80.238 closed.
每次ssh连接要输入很长命令,有点烦,可以配置~/.ssh/config文件来为ssh连接设置别名,如下所示:
[root@localhost ~]# cat ~/.ssh/config Host ha HostName 172.16.80.238 User zhangsan Port 29418
修改联系信息
setting->Contact Information
如果gerrit服务器所在环境发送邮件有困难,那么可以选择通过管理员账号远程设置/修改gerrit用户的邮箱地址。用该方法设置/修改email,方便快捷,而且能够立即生效。
修改gerrit用户的邮箱地址
管理员ssh的别名 [root@localhost ~]# cat ~/.ssh/config Host ha HostName 172.16.80.238 User admin Port 29418
[root@localhost ~]# ssh ha gerrit set-account --add-email [email protected] zhangsan
查看setting->Profile
Gerrit使用
配置用户名和邮箱
[root@localhost test]# git config --global user.name "zhangsan" [root@localhost test]# git config --global user.email "[email protected]" [root@localhost test]# git config --list core.quotepath=false i18n.logoutputencoding=utf8 i18n.commitencoding=utf8 user.name=zhangsan [email protected]
从远程主机克隆一个版本库
[root@localhost test]# git clone ssh://[email protected]:29418/test Cloning into 'test'... Checking connectivity... done. warning: remote HEAD refers to nonexistent ref, unable to checkout. [root@localhost test]# ls test
安装hook
钩子的目的是在提交信息中自动创建 'Change-Id' 标签
[root@localhost test]# scp -p -P 29418 [email protected]:hooks/commit-msg .git/hooks/ commit-msg 100% 4363 4.3KB/s 00:00
提交评审
[root@localhost test]# git add test.txt [root@localhost test]# git commit -m "zhangsan test" [master 41c00fe] zhangsan test 1 file changed, 2 insertions(+) create mode 100644 test.txt [root@localhost test]# git log commit 41c00fe70f6ed692174ed6ac25f435423945229d Author: zhangsan <[email protected]> Date: Fri Feb 19 13:49:16 2016 -0500 zhangsan test Change-Id: Iadaab91fe356cb8180e7882dc67f0a75ea8f1854 [root@localhost test]# git push origin Counting objects: 3, done. Delta compression using up to 2 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 329 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: Processing changes: new: 1, refs: 1, done remote: remote: New Changes: remote: http://172.16.80.238:8080/2 remote: To ssh://[email protected]:29418/test * [new branch] master -> refs/for/master
登录账号可以查看提交的内容等待审批