Gerrit服务器搭建

Ubuntu安装Gerrit

从Gerrit官网下载安装包:

Gerrit Code Review | Gerrit Code Reviewhttps://www.gerritcodereview.com/文档:

https://gerrit-documentation.storage.googleapis.com/Documentation/3.5.0.1/index.html

Gerrit config:

Gerrit Code Review - Configuration (storage.googleapis.com)https://gerrit-documentation.storage.googleapis.com/Documentation/3.5.0.1/config-gerrit.html#ssh

插件下载:

Plugins-stable-3.5 [Jenkins] (gerritforge.com)https://gerrit-ci.gerritforge.com/view/Plugins-stable-3.5/

 创建Gerrit账号

sudo useradd -d /home/gerrit -g 1001 -u 1001 -m -s /bin/bash gerrit
sudo adduser gerrit sudo
sudo passwd gerrit
su gerrit

安装命令:

java -jar gerrit.war init -d /home/gerrit

安装前提是系统已经安装Java

安装过程会提示一系列设置,参考如下:

[gerrit]
        basePath = GerritResource
        canonicalWebUrl = http://adress:8088  #Gerrit登录地址,设置为服务器IP地址
        serverId = a32dbca4-3237-4a99-960c-4b912a778351
[container]
        javaOptions = "-Dflogger.backend_factory=com.google.common.flogger.backend.log4j.Log4jBackendFactory#getInstance"
        javaOptions = "-Dflogger.logging_context=com.google.gerrit.server.logging.LoggingContext#getInstance"
        user = gerrit
        javaHome = /usr/lib/jvm/java-8-openjdk-amd64/jre

[index]
        type = lucene
[auth]
        type = OAUTH
        gitBasicAuthPolicy = HTTP
[plugins]
        allowRemoteAdmin = true #这项配置后才可以使用replication插件push代码
[plugin "gerrit-oauth-provider-gitlab-oauth"] #设置gitlab授权同步,使用gitlab账户数据库
        root-url = http://gitlab.test.cn
        client-id = gitlib上面ID值
        client-secret = gitlib上面ID值
[receive]
        enableSignedPush = false
        maxBatchCommits = 1000000
[change]
        submitWholeTopic = true
[sendemail]
        smtpServer = mail.cn
        smtpServerPort = 25
        smtpUser = jenkins
[sshd]
        listenAddress = *:29418  #默认29418
        maxConnectionsPerUser = 128
[httpd]
        listenUrl = http://*:8088/  #Gerrit监听端口,如果冲突可以修改为其它值
        listenUrl = proxy-http://*:8080/  #反向代理地址,与nginx代理配置中的端口要一致
[cache]
        directory = cache

添加Gerrit用户

sudo apt-get install apache2-utils

创建文件并添加用户Gerrit:

htpasswd -c /gerrit/gerrit.password gerrit  

添加用户jenkins:

htpasswd -c /gerrit/gerrit.password jenkins password

NGINX反向代理

安装nginx

sudo apt-get install nginx

启动服务:

/etc/init.d/nginx start
/etc/init.d/nginx restart
/etc/init.d/nginx stop

为Gerrit新建配置文件

cd /etc/nginx/conf.d/
vi gerrit.conf

编辑内容如下:

server {
     listen *:8081;   //监听8081端口
     server_name gerrit_IP; //浏览器访问地址,也可以设置为域名
     #server_name gerrit.net.cn;

     auth_basic "Welcomme to Gerrit Code Review Site!";
     auth_basic_user_file /home/gerrit/gerrit/gerrit.password;  //加载用户名密码文件,首个登录Gerrit的用户为管理员

     location / {
        proxy_pass  http://127.0.0.1:8080;  //反向代理的端口,端口要与gerrit中的代理端口一致
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
     }
     access_log /home/gerrit/gerrit/logs/gerrit_access.log; //log存放地址
   }
   

修改nginx默认设置:

cd /etc/nginx/
vi nginx.conf
在文件开头位置修改:
user gerrit wu;  //修改用户以及所在组,即搭建Gerrit的用户,否则nginx无法访问目录
worker_processes auto;
worker_rlimit_nofile 65535; //修改nginx访问文件数目,设置为最大
/var/log/nginx/: log位置
/usr/sbin/nginx:主程序
/etc/nginx:存放配置文件
/usr/share/nginx:存放静态文件

重启nginx

启动Gerrit服务

启动

/home/gerrit/bin/gerrit.sh start

关闭

/home/gerrit/bin/gerrit.sh stop

同步仓库,同步仓库前需要先关闭gerrit

sudo java -jar gerrit.war reindex --index projects -d /home/gerrit/

常用命令:

重新加载replication插件
ssh -p 29418 user@gerritIP gerrit plugin reload replication
同步仓库:
sudo java -jar /home/gerrit/gerritCD/bin/gerrit.war reindex --index projects -d /home/gerrit/gerritCD/
同步changes:
sudo java -jar /home/gerrit/gerritCD/bin/gerrit.war reindex --index changes -d /home/gerrit/gerritCD/
同步groups:
sudo java -jar /home/gerrit/gerritCD/bin/gerrit.war reindex --index groups -d /home/gerrit/gerritCD/
同步accounts:
sudo java -jar /home/gerrit/gerritCD/bin/gerrit.war reindex --index accounts -d /home/gerrit/gerritCD/

常用插件:

Plugin NameVersion
account06a381eb43
codemirror-editorv3.1.2
commit-message-length-validatorv3.1.2
delete-projectv3.1.2
download-commandsv3.1.2
egit2c97c54681
gerrit-oauth-provider0f807f6
gitilesv3.1.2
hooksv3.1.2
lfs2acd29ba7d
menuextender5137b54239
plugin-managerv3.1.2
rename-project31fdf52dc8
replicationv3.1.2
reviewnotesv3.1.2
serviceuser5beb111873
singleusergroupv3.1.2
webhooksv3.1.2

上传代码

#根据已有的源代码上传
1、创建仓库以及分支
repo forall -c 'echo $REPO_PATH; ssh -p 29418 gerrit@iZbp11tt1v8q02gcqcpxa5Z gerrit create-project $REPO_PATH --branch branchname --parent ALL-Project --empty-commit'
2、进入代码路径,添加远程库
repo forall -c 'echo $REPO_PATH; git remote add origin origin ssh://gerrit@iZbp11tt1v8q02gcqcpxa5Z:29418/$REPO_PATH'
3、push代码
repo forall -c 'echo $REPO_PATH; git push ssh://gerrit@iZbp11tt1v8q02gcqcpxa5Z:29418/$REPO_PATH develop:refs/heads/develop -f'

安装过程遇到的问题:

1、Starting Gerrit Code Review: FAILED

没有相关错误日志打印,查阅资料,安装haveged

sudo apt-get install haveged
/etc/init.d/haveged start

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值