Gerrit and Gitlab other configuration synchronization configuration replication &

A, Gerrit and Gitlab synchronization configuration

When configured gerrit environment, you need to configure synchronization with existing gitlab library, otherwise it will affect the existing development and packaging processes.

1. Install the plug-gerrit replication

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

Copy the code

2. Configure ssh config

Copy the code

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

Copy the code

3. Alternatively gitlab lubase (project owner) ssh key

Copy the code

cd ~/.ssh/
rm id_rsa
rm id_rsa.pub
vim id_rsa
(Id_rsa owner of Paste)
vim id_rsa.pub
(Paste owner of id_rsa.pub)
chmod 600 id_rsa
chmod 644 id_rsa.pub

Copy the code

4. Add gitlab pubkey to kown_hosts

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

or 

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. Configuration replication.config

Copy the code

[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

Copy the code

6. Start replication

~/gerrit_code/bin/gerrit.sh restart
ssh -p 29418 [email protected] gerrit plugin reload replication
ssh -p 29418 [email protected] replication start ***

 

Two, Gerrit additional configuration

1.invalid committer problem

gerrit off by default normal user rights directly push the master, and ordinary users need to configure git config consistent with global user.email gerrit account information email

Now that can not use the email function, consider turning off email functions and turn forge committer function, or modify the email account information by gerrit gerrit remote database

* Use forge committer way

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

Join forge authority in the following diagram

* The use of modified gerrit database mode

Copy the code

ssh -p 29418 [email protected] 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

Copy the code

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

2.admin remote access问题

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

解决方法:

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

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

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

3.replication rejected问题

在执行ssh -p 29418 [email protected] 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 [email protected] 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

Copy the code

[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

Copy the code

 

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

Copy the code

[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

Copy the code

 

Third, the authorization profile reference

 

Reference links

Installation and Configuration gerrit replication plug-in

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

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

gerrit host SSHKEY added gitlab  http://www.cnblogs.com/zhanchenjin/p/5032218.html

Published 44 original articles · won praise 31 · views 60000 +

Guess you like

Origin blog.csdn.net/u013463707/article/details/102742463