Gerrit与Gitlab同步配置replication&其他配置

摘要:
1、 Gerrit和Gitlab同步配置配置Gerrit环境后,需要将配置与现有的Gitlab库同步,否则将影响现有的开发和打包过程。

一、Gerrit与Gitlab同步配置

当配置好gerrit环境后,还需要与现有gitlab库进行同步配置,否则会影响现有开发与打包流程。

1.安装gerrit replication插件

unzip gerrit.war
cp WEB-INF/plugins/replication.jar ~/temp/
ssh -p 29418 admin@172.19.16.64 gerrit plugin install -n replication.jar - <~/temp/replication.jar
ssh -p 29418 admin@172.19.16.64 gerrit plugin ls
Name                           Version    Status   File
-------------------------------------------------------------------------------
replication                    v2.8       ENABLED  replication.jar

2.配置ssh config

cd ~/.ssh/
vim config
Host gitlab.***.cn
        User gitlabowner
        IdentityFile ~/.ssh/id_rsa #gitlab owner id_rsa
        StrictHostKeyChecking no
        UserKnownHostsFile /dev/null

3.替换gitlab lubase(project owner) ssh key

cd ~/.ssh/
rm id_rsa
rm id_rsa.pub
vim id_rsa
(粘贴owner的id_rsa)
vim id_rsa.pub
(粘贴owner的id_rsa.pub)
chmod 600 id_rsa
chmod 644 id_rsa.pub

4.加入gitlab pubkey到kown_hosts

sh -c "ssh-keyscan -t rsa gitlab.***.cn >> ~/.ssh/known_hosts"
sh -c "ssh-keygen -H -f ~/.ssh/known_hosts"

或者 

git clone git@gitlab.***.cn:mobile/***.git
Warning: Permanently added the RSA host key for IP address '172.19.14.64' to the list of known hosts.

5.配置replication.config

[remote "gitlab.***.cn"]
        url = git@gitlab.***.cn:mobile/${name}.git
        push = +refs/heads/*:refs/heads/*
        push = +refs/tags/*:refs/tags/*
        push = +refs/changes/*:refs/changes/*
        timtout = 30
        threads = 3

6.启动replication

~/gerrit_code/bin/gerrit.sh restart
ssh -p 29418 admin@172.19.16.64 gerrit plugin reload replication
ssh -p 29418 admin@172.19.16.64 replication start ***

二、Gerrit其他配置

1.invalid committer问题

gerrit默认关闭普通用户直接push master的权限,且普通用户需要配置git config global user.email与gerrit账户信息中的email一致

由于现在无法使用email功能,可考虑关闭email功能并开启forge committer功能,或者通过gerrit数据库远程修改gerrit账户中的email信息

*采用forge committer方式

vim ~/gerrit_code/etc/gerrit.config
[sendemail]
        enable = false

按照下图加入forge权限

Gerrit与Gitlab同步配置replication&amp;其他配置第1张

*采用修改gerrit数据库方式

ssh -p 29418 admin@172.19.16.64 gerrit gsql
gerrit>select * from account_external_ids;
 ACCOUNT_ID | EMAIL_ADDRESS              | PASSWORD | EXTERNAL_ID
 -----------+----------------------------+----------+----------------------------------
 1000000    | NULL                       | NULL     | gerrit:admin
 1000000    | NULL                       | NULL     | username:admin
 1000005    | NULL                       | NULL     | gerrit:yanjunjie363
 1000005    | NULL                       | NULL     | username:yanjunjie363
gerrit>insert into account_external_ids values('1000005', 'yanjunjie363@***.com.cn', 'NULL', 'yanjunjie363@***.com.cn');
gerrit>select * from account_external_ids;
 ACCOUNT_ID | EMAIL_ADDRESS              | PASSWORD | EXTERNAL_ID
 -----------+----------------------------+----------+----------------------------------
 1000000    | NULL                       | NULL     | gerrit:admin
 1000000    | NULL                       | NULL     | username:admin
 1000005    | NULL                       | NULL     | gerrit:yanjunjie363
 1000005    | NULL                       | NULL     | username:yanjunjie363
 1000005    | yanjunjie363@***.com.cn | NULL     | mailto:yanjunjie363@***.com.cn

按照以上任意一种方式配置后,可git push origin HEAD:refs/for/master成功

2.admin remote access问题

在远程执行ssh -p 29418 admin@172.19.16.64 gerrit plugin ls时会提示报错,因为gerrit默认关闭远程admin操作权限

解决方法:

vim ~/gerrit_code/etc/gerrit.config
[plugins]
        allowRemoteAdmin = true

在远程执行ssh -p 29418 admin@172.19.16.64 gerrit gsql时会提示报错,因为gerrit默认关闭操作database权限

解决方法:在Projects-Access中加入如上图中的Access Database功能

3.replication rejected问题

在执行ssh -p 29418 admin@172.19.16.64 replication start lubase时,gerrit replication日志中报错:replication_log

[2016-10-18 15:09:40,861] [eb662c68] Created remote repository: git@gitlab.***.cn:mobile/All-Projects.git
[2016-10-18 15:09:40,861] [eb662c68] Missing repository created; retry replication to git@gitlab.***.cn:mobile/All-Projects.git

这个问题是因为gerrit有两个默认git库All-Projects和All-Users,用来默认配置gerrit项目和账户权限,因为gitlab未开启创建git库权限,所以提示失败。

在执行ssh -p 29418 admin@172.19.16.64 replication start lubase时,gerrit replication日志中报错:replication_log

[2016-10-17 17:26:46,210] [b716d4c2] Failed replicate of refs/changes/02/2/1 to git@gitlab.***.cn:mobile/***.git, reason: pre-receive hook declined

这个问题是因为gitlab库权限问题导致,当***开启master protected,并使用yanjunjie363(master用户)的ssh-key push并replication时,会报该错误。

可关闭***的master protected权限,或者使用ufo(owner用户)的ssh-key push并replication即刻解决。

如果出现如下log,则表示replication插件安装成功:error_log

[2016-10-18 11:19:51,301] [main] INFO  com.google.gerrit.server.plugins.PluginLoader : Loading plugins from /home/gerrit/workspaces/gerrit_code/plugins
[2016-10-18 11:19:51,381] [main] WARN  com.googlesource.gerrit.plugins.replication.ReplicationFileBasedConfig : Config file /home/gerrit/workspaces/gerrit_code/etc/replication.config does not exist; not replicating
[2016-10-18 11:19:51,383] [main] INFO  com.google.gerrit.server.plugins.PluginLoader : Loaded plugin replication, version v2.12
[2016-10-18 11:19:51,542] [main] INFO  com.google.gerrit.server.change.ChangeCleanupRunner : Ignoring missing changeCleanup schedule configuration
[2016-10-18 11:19:51,579] [main] INFO  com.google.gerrit.sshd.SshDaemon : Started Gerrit SSHD-CORE-0.14.0 on *:29418
[2016-10-18 11:19:51,581] [main] INFO  org.eclipse.jetty.server.Server : jetty-9.2.13.v20150730
[2016-10-18 11:19:51,798] [main] INFO  org.eclipse.jetty.server.handler.ContextHandler : Started o.e.j.s.ServletContextHandler@1304204{/,null,AVAILABLE}
[2016-10-18 11:19:51,800] [main] INFO  org.eclipse.jetty.server.ServerConnector : Started ServerConnector@189a9e6{HTTP/1.1}{0.0.0.0:8088}
[2016-10-18 11:19:51,801] [main] INFO  org.eclipse.jetty.server.Server : Started @4615ms

如果出现如下log,该表示gerrit与gitlab同步成功:replication_log

[2016-10-18 15:15:48,160] [] scheduling replication ***:refs/heads/master => git@gitlab.***.cn:mobile/***.git
[2016-10-18 15:15:48,160] [] scheduled ***:refs/heads/master => [9000013d] push git@gitlab.***.cn:mobile/***.git to run after 15s
[2016-10-18 15:16:03,160] [9000013d] Replication to git@gitlab.***.cn:mobile/***.git started...
[2016-10-18 15:16:03,161] [9000013d] Push to git@gitlab.***.cn:mobile/***.git references: [RemoteRefUpdate[remoteName=refs/heads/master, NOT_ATTEMPTED, (null)...a2e1f13bd12cd398ed45ab06fa231cac6334f0c8, srcRef=refs/heads/master, forceUpdate, message=null]]
[2016-10-18 15:16:03,820] [9000013d] Replication to git@gitlab.***.cn:mobile/***.git completed in 660ms, 15000ms delay, 0 retries

三、权限配置参考

Gerrit与Gitlab同步配置replication&amp;其他配置第2张

参考链接

安装与配置gerrit replication插件

https://gerrit.libreoffice.org/plugins/replication/Documentation/config.html 

https://gist.github.com/Aricg/56f1a769cbdcbb93b459

gerrit主机中加入gitlab sshkey http://www.cnblogs.com/zhanchenjin/p/5032218.html

免责声明:文章转载自《Gerrit与Gitlab同步配置replication&amp;amp;其他配置》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇requests.exceptions.SSLError: HTTPSConnectionPool(host='cn.bing.com', port=443)报错解决方案eclipse 配置tomcat运行环境下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

GitLab实战操作指南

一、Git原理 1、Git是什么? Git是目前世界上最先进的分布式版本控制系统(没有之一)。 2、Git有什么特点? 简单来说就是:高端大气上档次! 3、GIt与SVN区别 SVN管理: 属于集中式版本控制系统,版本库是集中存放在中央服务器,必须联网才能工作,脱离局域网,采取互联网提交大文件会比较慢   Git管理: 属于分布式版本控制系统,根...

关于linux免密登录的配置及ssh客户端基于私钥文件的登录

操作系统环境: CentOS Linux release 7.7.1908 (Core) 1、首先在linux服务器上,使用ssh-keygen命令生成密钥对文件(一直回车即可,默认使用rsa算法),如下所示       其中还支持的算法有dsa | ecdsa | ed25519 | rsa | rsa1,使用其他算法只需要使用-t选项指定即可    ...

替代Xshell的良心国产软件 FinalShell

今年8月份NetSarang公司旗下软件家族的官方版本被爆被植入后门着实让我们常用的Xshell,Xftp等工具火了一把,很长时间都是在用Xshell,不过最近发现了一款同类产品FinalShell,还是一块良心国货。初步体验了一下,确实是良心之作。且免费(通用版),支持国货。 下面附上一些截图和官方连接: 官网:http://www.hostbuf.co...

配置ssh免密登录

1、在生成新的 SSH 密钥对之前,首先检查客户端机器上是否已有 SSH 密钥,主要是为了不覆盖现有密钥。运行以下Is 命令以查看是否存在现有 SSH 密钥: Is -al ~/.ssh/id_*.pub 2、如果没有:生成新的 SSH 密钥对。 ssh-keygen -t rsa 生成密钥过程中,建议采用默认值,只需要按三次回车之后,就会再~/.ssh目...

centos 7 搭建git远程仓储 免密登录

第一步.安装git服务 yum install git 第二步.创建git用户 adduser git 第三步开启公钥验证 vi /etc/ssh/sshd_config 讲文件中的 #PubkeyAuthentication yes #最前方的#删掉 PubkeyAuthentication yes 重启ssh服务 service sshd res...

Gitlab配置webhooks实现自动化部署

Gitlab 自动化部署 原理介绍 配置gitlab当push动作的时候,访问服务器上的一个链接比如www.shenke.group/hook.php hook.php里面写着一行代码,会让服务器git pull相应项目的代码到web目录。 pull结束,代码就在web目录了,我们只要重新访问网站就可以了。     核心就是push的时候,gitlab...