Gerrit,一种免费、开放源代码的代码审查软件,使用网页界面。利用网页浏览器,同一个团队的软件程序员,可以相互审阅彼此修改后的程序代码,决定是否能够提交,退回或者继续修改。它使用Git作为底层版本控制系统。
yum install
安装,需要下载后手动安装。gerrit-2.13.11.war
) , 以及 Gerrit 插件 (gerrit_lib.tar.gz
).后续将这两个文件上传到 centos 的根路径中。需要进行手动安装。yum -y install git
gerrit-2.13.11.war
和 gerrit_lib.tar.gz
软件包上传至 /root
目录yum -y install java
安装数据库mysql
yum -y install mariadb*
启动数据库
systemctl start mariadb
systemctl enable mariadb
初始化数据库
[root@codesweet ~]# mysql_secure_installation
Enter current password for root (enter for none): # 输入数据库超级管理员root的密码(注意不是系统root的密码),第一次进入还没有设置密码则直接回车
Set root password? [Y/n] # 设置密码,y
New password: # 新密码 123456
Re-enter new password: # 再次输入密码 123456
Remove anonymous users? [Y/n] # 移除匿名用户, y
Disallow root login remotely? [Y/n] # 拒绝root远程登录,n
Remove test database and access to it? [Y/n] # 删除test数据库,y
Reload privilege tables now? [Y/n] # 重新加载权限表,y。或者重启服务也许
数据库字符集配置
a. vim /etc/my.cnf
,在 [mysqld] 标签下添加:
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
b. vim /etc/my.cnf.d/client.cnf
,在 [client] 标签下添加:
default-character-set=utf8
c. /etc/my.cnf.d/mysql-clients.cnf
,在 [mysql] 标签下添加
default-character-set=utf8
d. 重启数据库服务
systemctl restart mariadb
mysql -p123456
create database reviewdb;
grant all privileges on reviewdb.* to "gerrit"@"%" identified by "123456";
flush privileges;
exit;
adduser gerrit
cd /
\cp gerrit-2.13.11.war /home/gerrit/
\cp gerrit_lib.tar.gz /home/gerrit/
su - gerrit
mkdir -p /home/gerrit/code_review
tar xf gerrit_lib.tar.gz -C code_review/
安装 gerrit
java -jar gerrit-2.13.11.war init -d /home/gerrit/code_review
ldap认证的初始化配置方式如下:
*** Gerrit Code Review 2.13.11
***
Create '/home/gerrit/code_review' [Y/n]? 回车
*** Git Repositories
***
Location of Git repositories [git]: 回车
*** SQL Database
***
Database server type [h2]:mysql
*** User Authentication
***
Authentication method [OPENID/?]: LDAP
LDAP server [ldap://localhost]: ldap://121.51.39.239
LDAP username : cn=admin,dc=codesweet,dc=com
cn=admin,dc=bkce,dc=com's password : 123456
confirm password : 123456
Account BaseDN [DC=168,DC=56,DC=85]: ou=users,dc=codesweet,dc=com
Group BaseDN [ou=users,dc=bkce,dc=com]: ou=users,dc=codesweet,dc=com
Enable signed push support [y/N]? n
*** Review Labels
***
Install Verified label [y/N]? 回车
*** Email Delivery
***
***
SMTP server hostname [localhost]: 回车
SMTP server port [(default)]: 回车
SMTP encryption [NONE/?]: 回车
SMTP username : 回车
*** Container Process
***
Run as [gerrit]: 回车
Java runtime [/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/jre]: 回车
Copy gerrit-2.13.11.war to /home/gerrit/code_review/bin/gerrit.war [Y/n]? y
Copying gerrit-2.13.11.war to /home/gerrit/code_review/bin/gerrit.war
*** SSH Daemon
***
Listen on address [*]: 回车
Listen on port [29418]: 回车
Gerrit Code Review is not shipped with Bouncy Castle Crypto SSL v152
If available, Gerrit can take advantage of features
in the library, but will also function without it.
Download and install it now [Y/n]? y
Downloading https://repo1.maven.org/maven2/org/bouncycastle/bcpkix-jdk15on/1.52/bcpkix-jdk15on-1.52.jar ... OK
Checksum bcpkix-jdk15on-1.52.jar OK
Gerrit Code Review is not shipped with Bouncy Castle Crypto Provider v152
** This library is required by Bouncy Castle Crypto SSL v152. **
Download and install it now [Y/n]? y
Downloading https://repo1.maven.org/maven2/org/bouncycastle/bcprov-jdk15on/1.52/bcprov-jdk15on-1.52.jar ... OK
Checksum bcprov-jdk15on-1.52.jar OK
Generating SSH host key ... rsa... dsa... done
*** HTTP Daemon
***
Behind reverse proxy [y/N]? 回车
Use SSL (https://) [y/N]? 回车
Listen on address [*]: 回车
Listen on port [8080]: 回车
Canonical URL [http://linux-node83.domain.local:8080/]: http://121.51.39.239:8080/
*** Cache
***
*** Plugins
***
Installing plugins.
Install plugin commit-message-length-validator version v2.13.11 [y/N]? y
Installed commit-message-length-validator v2.13.11
Install plugin download-commands version v2.13.11 [y/N]? y
Installed download-commands v2.13.11
Install plugin hooks version v2.13.11 [y/N]? y
Installed hooks v2.13.11
Install plugin replication version v2.13.11 [y/N]? y
Installed replication v2.13.11
Install plugin reviewnotes version v2.13.11 [y/N]? y
Installed reviewnotes v2.13.11
Install plugin singleusergroup version v2.13.11 [y/N]? y
Installed singleusergroup v2.13.11
Initializing plugins.
No plugins found with init steps.
启动 gerrit
/home/gerrit/code_review/bin/gerrit.sh restart
配置文件
上面的安装步骤后续如果有些配置想要更改的话,可以对 /home/gerrit/code_review/etc/gerrit.config
文件进行更改
vim /home/gerrit/code_review/etc/gerrit.config
然后重启 gerrit
/home/gerrit/code_review/bin/gerrit.sh restart
我的 gerrit.config 文件内容:
[gerrit]
basePath = git
serverId = 3c7f6094-4b63-4c30-a4e3-7e1805a3f1ed
canonicalWebUrl = http://121.51.39.239:8080/
[database]
type = mysql
hostname = localhost
database = reviewdb
username = gerrit
[auth]
type = LDAP
[ldap]
server = ldap://121.51.39.239
username = cn=admin,dc=codesweet,dc=com
accountBase = ou=users,dc=codesweet,dc=com
groupBase = ou=users,dc=codesweet,dc=com
[receive]
enableSignedPush = false
[sendemail]
#smtpServer = localhost
enable = true
smtpServer = smtp.qq.com
smtpServerPort = 465
smtpEncryption = SSL
sslVerify = true
smtpUser = 24611***@qq.com
smtpPass = dmytimlooemd***
from = 24611***@qq.com
[container]
user = gerrit
javaHome = /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-1.an7.x86_64/jre
[sshd]
listenAddress = *:29418
[httpd]
listenUrl = http://*:8080/
[cache]
directory = cache
[gitweb]
type = gitweb
cgi = /var/www/git/gitweb.cgi
配置 gerrit 服务器邮箱
a. 如果需要邮箱推服务,就是提交代码后,会有邮件告知 code review 审查人员。那么就需要配置 gerrit 服务器邮箱,可以在 gerrit.config 中进行配置。
b. gerrit 服务器邮箱只有一个,起转发作用,就是将某个 gerrit 客户端的信息转发给另一个或多个客户端。
c. 如果你的服务器邮箱配置的是 qq 邮箱 gerrit.config 中 sendemail 字段中如果是qq邮箱,则按照下述配置,里面最终要的一点不要搞错,smtpPass填的不是邮箱密码,而是授权码,这个授权码是需要提前到qq邮箱的设置中开启smtp授权的,开启后会得到授权码。开启方法:qq邮箱如何开启SMTP服务
[sendemail]
#smtpServer = localhost
enable = true
smtpServer = smtp.qq.com
smtpServerPort = 465
smtpEncryption = SSL
sslVerify = true
smtpUser = 24611***@qq.com
smtpPass = dmytimlooemd***
from = 24611****@qq.com
d. 163 邮箱也类似的步骤
[sendemail]
#smtpServer = localhost
enable = true
smtpServer = smtp.163.com
smtpServerPort = 465
smtpEncryption = SSL
sslVerify = true
smtpUser = 788844***@163.com
smtpPass = dmdddsemd***
from = 788844***@163.com
users
,再点击 创建一个子目录
users
,再点击 创建一个子目录
eric
,然后点击 添加新的属性
,然后在选框中选中 Email添加属性
栏中的下拉框选中 Email
,Update Object
eric
和密码 123456
,然后点击 Sign In
安装gitweb
yum install gitweb
安装完成后会有如下文件:/var/www/git/gitweb.cgi
配置gitweb
修改gitweb的配置文件(/etc/gitweb.conf),将配置项“$projectroot”修改为gerrit的git仓库目录
$projectroot = "/etc/gerrit/git"
配置gerrit
修改gerrit的配置文件(gerrit.config),添加如下配置
[gitweb]
type = gitweb
cgi = /var/www/git/gitweb.cgi