https://cloud.tencent.com/developer/article/1722078

https://www.cnblogs.com/lonecloud/p/7528160.html

https://blog.csdn.net/peterxiaoq/article/details/73330314(相当的详细)

https://blog.csdn.net/benkaoya/article/details/8680886 (详细)

https://www.cnblogs.com/lexuele/p/5133601.html

下载指定版本的gerrit

https://www.gerritcodereview.com/#download
右击复制最新版本的地址,然后改为自己需要的版本号即可下载.

安装gerrit

java -jar gerrit-full-2.5.2.war init -d review_site
注意jdk与gerrit的版本要对应,否则安装报错。

安装后的目录:
- 配置文件
/review_gerrit/etc/gerrit.conf (review_gerrit不同版本的gerrit可能不一样,比如3.2.10是review_site)

[https://blog.csdn.net/nwpushuai/article/details/79250396](https://blog.csdn.net/nwpushuai/article/details/79250396)(gerrit配置文件详解)

如果gerrit服务没有启动,则会报错:502 Bad Gateway

切换gerrit的认证方式为http

https://blog.caoxudong.info/blog/2014/07/31/gerrit_http_basic_authentication

默认情况下gerrit.conf里auth-type为OPENID

点击登录,弹出的就是这个页面

那改成http登录,我们需要做以下几个操作:
1)将gerrit.conf里auth-type改为HTTP
2)设置动态代理,配置http认证.

server {
    listen    8082;
    server_name com.nginx.proxy.gerrit;
    location /{
      auth_basic       "Welcome to Gerrit Code Review !";
      auth_basic_user_file  /home/gerrit/review_site/etc/passwd;
      proxy_pass       http://127.0.0.1:8081;
      proxy_set_header    X-Forwarded-For $remote_addr;
      proxy_set_header    Host $host;
    }
}

3)将gerrit的安装目录/home/gerrit的权限改为755
$ chmod 755 /home/gerrit

退出登录

如果你已经成功登录了gerrit的网页,那么如果你想退出,请直接关闭整个浏览器,gerrit没有做logout的session清除,所以如果你直接点击网页右上角的logout,仍会返回到gerrit配置canonicalWebUrl的地址 。关于登出,gerrit给出的原因是:

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 close the Webbrowser.

卸载Gerrit

如果你的gerrit服务已经处于运行中,需要先执行下面的命令把它停掉:
gerrit/bin/gerrit.sh stop
删除reviewdb数据库中的内容,确保重新安装没有问题。
然后再试着删除整个 gerrit 文件目录就好了。

如果你没有停掉gerrit,就把gerrit的安装目录给删除了,可以通过查端口找到gerrit的进程id,然后将其kill掉。

建立与Gerrit的ssh服务的连接

参照https://blog.csdn.net/benkaoya/article/details/8680886
1)在主机上通过ssh-keygen -t rsa -C "管理员" -f ~/.ssh/zhchen,会在~/.ssh/下生成密钥对.注意记住自己输入的密码.

然后将zhchen.pub里的内容添加到gerrit中zhchen这个用户的公钥列表。

2)通过ssh指令看看是否可以连接得上gerrit

Gerrit指令操作

Gerrit控制台指令大全:https://www.cnblogs.com/gravity-126/p/13368410.html

设置用户的邮箱

1)添加用户
htpasswd -b passwords 用户名 用户密码
2)用添加的用户登录一下Gerrit网页
3)添加邮箱
执行指令之前,首先调用su gerrit将用户切换为安装Gerrit用户,否则会报Host key verification failed错误。

ssh -p 29418 admin@xxxx gerrit set-account --add-email 新用户的邮箱 新用户名
这样刷新网页就会发现新用户的邮箱已经添加上了

*记录一个bug:我是在root用户下安装的gerrit,然后遇到下面的问题


执行ssh -p 29418 zhchen@xx.xx.xx.xx gerrit set-account --add-email 1349308479@qq.com zhchen,会报permission denied (publickey)错误。

需要执行

ssh-agent bash(不执行此命令,ssh-add命令执行时会报错:Could not open a connection to your authentication agent)
ssh-add 密钥(不带public)

后来大神新建linux普通用户,重新装了一下,就莫名的好了。


分类: Gerrit

0 条评论

发表回复

您的电子邮箱地址不会被公开。