第一章(三):Gerrit代码检视工具

第一章(三):Gerrit代码检视工具

如果转载,还请注明我文章的链接,书写不易,互相珍重,期待技术交流

Gerrit简单说明:

​ 其是基于Git的,采用web界面的代码审查工具,主要应用于开发与git仓库之间,来限制直接 提交代码到git公共仓库,用于代码的人工审核和ci任务触发的验证。

其实gerrit自身是有仓库功能的,但是大部分应用场景,都是使用其他的仓库,比如gitlab这类,然后用gerrit做个审核工具,当gerrit和gitlab集成后,尽量的不要直接提交代码到gitlab。

其实这个工具,很多企业应该都是用不到的,所以,,大家有需要就看,没需要就略过吧。不过这篇笔记会讲与gitlab的集成,有兴趣的话,可以看看。

系统环境:centos7.8

JAVA:JRE11

Gerrit:3.2.5

Yu
2020年12月

在这里插入图片描述

本节目录

一、环境准备

二、环境配置

三、安装gerrit

四、配置并集成gitweb

五、集成gitlab

六、gerrit的基本使用与管理

一、环境准备

主机信息说明:

IP 主机名 作用 备注
192.168.80.151 node1 gitlab 访问url:http://local.gitlab.com
192.168.80.152 node2 sonarqube 访问url:http://local.sonar.com
192.168.80.153 node3 gerrit 访问url:http://local.gerrit.com
192.168.80.154 node4 email(后续jenkins也在这台) email域:local.cicdmail.com

一定要注意,这里的gerrit是在email服务搭建 (参见《番外篇之局域网邮件服务搭建》) 完成后开始的,因为gerrit要求邮箱验证,但是我不想使用真实的邮箱,所以采用了局域网搭建postfix的方式。

1、系统环境准备

关闭firewalld,selinux,NetworkManager
修改IP,hostname 配置 /etc/hosts
修改好时间

具体步骤不再赘述
[root@node* ~]# vim /etc/hosts
192.168.80.151    node1
192.168.80.152    node2
192.168.80.153    node3
192.168.80.154    node4
192.168.80.151    local.gitlab.com
192.168.80.152    local.sonar.com
192.168.80.153    local.gerrit.com
192.168.80.154    local.cicdmail.com

2、下载jre

根据官网说明,3.2.5.1版本(截止20年11月最新稳定版),最高支持java版本为13以下

To run the Gerrit service, the following requirement must be met on the host:

  • JRE, versions 1.8 or 11 Download

    Gerrit is not yet compatible with Java 13 or newer at this time.

我这里采用官方推荐的版本两个版本之一,JRE 11

下载地址:
http://jdk.java.net/java-se-ri/11

3、下载Gerrit

下载地址:
https://www.gerritcodereview.com/

下载插件可以去https://gerrit-ci.gerritforge.com/view/Plugins-stable-3.2/

5、配置yum源

一个是系统源,另外需要配置一下epel源(等下装nginx, git-review等)

当然这一步做不做,怎么做,都随意。这里仅做演示

系统源保持默认,

配置一下epel源
[root@node3 ~]# vim /etc/yum.repos.d/epel.repo
[epel]
name=tuna_epel
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/
enabled=1
gpgcheck=0

二、环境配置

1.安装 gitweb git-review

git-review 是facebook开源的,git-review为git新增了一个很方便的代码review途径,安装在这里的目的是借用git-review帮我们完成push代码到gerrit。

gitweb 提供了git版本库的图形化web浏览功能。

[root@node3 ~]# yum install -y gitweb git-review

2、配置git

[root@node3 ~]# git config --global user.name "ops01"
[root@node3 ~]# git config --global user.email "ops01@cicdmail.com"
[root@node3 ~]# git config --global color.ui true


查看配置
[root@node3 ~]# git config --list
user.name=ops01
user.email=ops01@cicdmail.com
color.ui=true
[root@node3 ~]#

还需要配置一下字符集,以解决Gerrit中文编码支持不好的问题
[root@node3 ~]# git config --global core.quotepath false
[root@node3 ~]# git config --global i18n.logoutputencoding utf8
[root@node3 ~]# git config --global i18n.commitencoding utf8


[root@node3 ~]# git config --list
user.name=ops01
user.email=ops01@cicdmail.com
color.ui=true
core.quotepath=false
i18n.logoutputencoding=utf8
i18n.commitencoding=utf8

3、安装jre

将前面下载的jdk11上传至服务器

[root@node3 ~]# ls openjdk-11+28_linux-x64_bin.tar.gz
openjdk-11+28_linux-x64_bin.tar.gz


解压:
[root@node3 ~]# tar xf openjdk-11+28_linux-x64_bin.tar.gz -C /usr/local/

配置环境变量

[root@node3 jdk-11]# vi /etc/profile
# jre11的环境变量
export JAVA_HOME=/usr/local/jdk-11
export JRE_HOME=\$JAVA_HOME/
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar



生效环境变量
[root@node3 jdk-11]# source /etc/profile

验证版本

[root@node3 jdk-11]# java --version
openjdk 11 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)

4、安装nginx

用于代理

[root@node3 ~]# yum -y install nginx

启动nginx

[root@node3 ~]# systemctl start nginx && systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

[root@node3 ~]# ss -naltp|grep 80
LISTEN     0      128          *:80                       *:*                   users:(("nginx",pid=66827,fd=6),("nginx",pid=66826,fd=6),("nginx",pid=66825,fd=6))
LISTEN     0      128       [::]:80                    [::]:*                   users:(("nginx",pid=66827,fd=7),("nginx",pid=66826,fd=7),("nginx",pid=66825,fd=7))

5、创建Gerrit用户

该用户用于安装及启动Gerrit

[root@node3 ~]# useradd gerrit
[root@node3 ~]# passwd gerrit
Changing password for user gerrit.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.

6、下载/上传Gerrit软件包至Gerrit可访问的目录

[root@node3 ~]# ls /home/gerrit/
gerrit-3.2.5.1.war

三、安装Gerrit

1、初始化

先使用root用户创建安装目录

[root@node3 jdk-11]# mkdir /usr/local/gerrit
[root@node3 jdk-11]# chown gerrit. /usr/local/gerrit

切换至gerrit用户完成初始化

[root@node3 jdk-11]# su - gerrit

初始化

需要操作的项目较多,注意我这里写的解释

[gerrit@node3 ~]$ java -jar gerrit-3.2.5.1.war init -d /usr/local/gerrit
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.assistedinject.FactoryProvider2 (file:/home/gerrit/.gerritcodereview/tmp/gerrit_12210446950063492415_app/guice-assistedinject-4.2.3.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of com.google.inject.assistedinject.FactoryProvider2
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore
[2020-11-30 17:18:50,665] [main] INFO  com.google.gerrit.server.config.GerritServerConfigProvider : No /usr/local/gerrit/etc/gerrit.config; assuming defaults

*** Gerrit Code Review 3.2.5.1
***

Create '/usr/local/gerrit'     [Y/n]? y  ## 是否创建该文件

*** Git Repositories
***

Location of Git repositories   [git]: /usr/local/gerrit  ## 指定git存储目录

*** Index
***

Type                           [lucene]:   ## 默认

*** User Authentication
***

Authentication method          [openid/?]: HTTP  ##选择HTTP
Get username from custom HTTP header [y/N]? n    ##是否从自定义HTTP头获取用户名,选否 
SSO logout URL                 :  ## 默认
Enable signed push support     [y/N]? y   ## 签名推送

*** Review Labels
***

Install Verified label         [y/N]?  ## 安装以验证标签

*** Email Delivery
***

SMTP server hostname           [localhost]: local.cicdmail.com   ##  ## 自动发送邮件的smtp服务器
SMTP server port               [(default)]: 25    ##  ssl协议端口号 465/994,非ssl是25号端口
SMTP encryption                [none/?]:  ## 如果上面写了465/994端口号,这里就写 SSL,我们邮箱自己搭的,这里默认none就好
SMTP username                  [gerrit]: ops01@cicdmail.com   ## 定义自动发送邮件的邮箱地址 
ops01@cicdmail.com's password  :  ##  授权码或者密码
              confirm password :  ##  二次输入


*** Container Process
***

Run as                         [gerrit]:  ## 指定运行用户
Java runtime                   [/usr/local/jdk-11]:  ## java路径,如果不对,自己写
Copy gerrit-3.2.5.1.war to /usr/local/gerrit/bin/gerrit.war [Y/n]?  y      ## 是否拷贝gerrit软件包
Copying gerrit-3.2.5.1.war to /usr/local/gerrit/bin/gerrit.war

*** SSH Daemon
***

Listen on address              [*]:   ## ssh监听地址
Listen on port                 [29418]:  ## 监听端口
Generating SSH host key ... rsa... ed25519... ecdsa 256... ecdsa 384... ecdsa 521... done

*** HTTP Daemon
***

Behind reverse proxy           [y/N]?  y  ## 使用反向代理
Proxy uses SSL (https://)      [y/N]? n   ## 不用ssl
Subdirectory on proxy server   [/]:  ## 代理服务器子目录
Listen on address              [*]:  local.gerrit.com ## gerrit的监听地址
Listen on port                 [8080]:   ## 监听端口
Canonical URL                  [http://local.gerrit.com:8080/]:    ## url

*** Cache
***


*** Plugins
***

Installing plugins.
Install plugin codemirror-editor version v3.2.5.1 [y/N]? y  ## 下面的都是问装不装插件,全 y 就行了
Installed codemirror-editor v3.2.5.1
Install plugin commit-message-length-validator version v3.2.5.1 [y/N]? y
Installed commit-message-length-validator v3.2.5.1
Install plugin delete-project version v3.2.5.1 [y/N]? y
Installed delete-project v3.2.5.1
Install plugin download-commands version v3.2.5.1 [y/N]? y
Installed download-commands v3.2.5.1
Install plugin gitiles version v3.2.5.1 [y/N]? y
Installed gitiles v3.2.5.1
Install plugin hooks version v3.2.5.1 [y/N]? y
Installed hooks v3.2.5.1
Install plugin plugin-manager version v3.2.5.1 [y/N]? y
Installed plugin-manager v3.2.5.1
Install plugin replication version v3.2.5.1 [y/N]? y
Installed replication v3.2.5.1
Install plugin reviewnotes version v3.2.5.1 [y/N]? y
Installed reviewnotes v3.2.5.1
Install plugin singleusergroup version v3.2.5.1 [y/N]? y
Installed singleusergroup v3.2.5.1
Install plugin webhooks version v3.2.5.1 [y/N]? y
Installed webhooks v3.2.5.1
Initializing plugins.

.......
Starting Gerrit Code Review: WARNING: Could not adjust Gerrit's process for the kernel's out-of-memory killer.
         This may be caused by /usr/local/gerrit/bin/gerrit.sh not being run as root.
         Consider changing the OOM score adjustment manually for Gerrit's PID=70752 with e.g.:
         echo '-1000' 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值