Gerrit安裝及複製到Gitlab

# 直接下載jar文件後
java -jar gerrit-2.14.1.war init -d /opt/gerrit

# 安裝複製插件
unzip gerrit-2.14.1.war
ssh -p 29418 gerrit_admin_user@localhost gerrit plugin install -n replication.jar - < ./WEB-INF/plugins/replication.jar
# 如果安裝時提示權限問題,要在gerrit.config 上添加 allowRemoteAdmin 參數,文件見下面
# gerrit IP: 192.168.5.2
# gitlab IP: 192.168.5.3

# 在gerrit 上,把下面的結果放到gerrit賬號的 known_hosts 文件中
ssh-keyscan -t rsa 192.168.5.3 >> ~/.ssh/known_hosts
ssh-keyscan -t rsa gitlab.dns.name >> ~/.ssh/known_hosts
# 同時把gerrit用戶的ssh-key 添加到gitlab倉庫中,並設置爲需要同步倉庫的master
root@grt01:/opt/gerrit/etc# cat replication.config 
[remote "git01"]
	projects = grt_demo01
        url = [email protected]:mobile/grt_demo01.git      
        push = +refs/heads/*:refs/heads/*
        push = +refs/tags/*:refs/tags/*
        push = +refs/changes/*:refs/changes/*
        timtout = 30
        threads = 3
root@grt01:/opt/gerrit/etc# cat gerrit.config 
[gerrit]
	basePath = git
	serverId = 822d309b-9f9b-478b-21c7-1ca14f92abcf
	canonicalWebUrl = http://grt01.test.local:8080/
[database]
	type = h2
	database = /opt/gerrit/db/ReviewDB
[index]
	type = LUCENE
[auth]
	type = LDAP
	gitBasicAuthPolicy = HTTP
[ldap] 
        server = ldap://ad.test.local
        username = [email protected]
        password = 8888888
        accountBase = DC=test,DC=local
#        groupBase = DC=test,DC=local
        accountPattern = (&(objectClass=person)(sAMAccountName=${username}))
        accountFullName = displayName
        accountEmailAddress = mail
        accountSshUserName = sAMAccountName
#        groupMemberPattern = (sAMAccountName=${username})
#        groupName = cn
[receive]
	enableSignedPush = false
[sendemail]
        smtpServer = smtp.test.com
        smtpServerPort = 25 
        smtpUser = [email protected]
        enable=true
[container]
	user = gerrit
	javaHome = /usr/lib/jvm/java-8-openjdk-amd64/jre
[sshd]
	listenAddress = *:29418
[httpd]
	listenUrl = http://*:8080/
[cache]
	directory = cache
[plugins]
        # allow install plugin
        allowRemoteAdmin = true

上面使用的是域認證

root@grt01:/home/gerrit/.ssh# cat config 
Host git01
        IdentityFile ~/.ssh/id_rsa     #這裏的證書,是在gitlab上有master權限的用戶的證書
        PreferredAuthentications publickey
#把gitlab相關項目clone到gerrit
git clone --mirrror .....
#更改權限
chown gerrit:gerrit -R .....
#移動到gerrit的倉庫位置
mv src /opt/gerrit/git/
#重啓gerrit,即可在gerrit看見相關項目
/opt/gerrit/bin/gerrit.sh restart

apache2 代理轉發

	<VirtualHost *>
	  ServerName grt01 

	  ProxyRequests Off
	  ProxyVia Off
	  ProxyPreserveHost On

	  <Proxy *>
	    Order deny,allow
	    Allow from all
	    # Use following line instead of the previous two on Apache >= 2.4
	    # Require all granted
	  </Proxy>

	  AllowEncodedSlashes On
	  ProxyPass / http://127.0.0.1:8080/ nocanon
	</VirtualHost>
#replication時出現 "channel is not opened" 錯誤, 使用非ssh方式解決
root@grt01:/opt/gerrit/etc# cat replication.config 
[remote "git01"]
	projects = grt_demo01
#        url = [email protected]:mobile/grt_demo01.git      
        url = http://git:[email protected]/mobile/grt_demo01.git
        push = +refs/heads/*:refs/heads/*
        push = +refs/tags/*:refs/tags/*
        push = +refs/changes/*:refs/changes/*
        timtout = 30
        threads = 3


參考1

參考2

參考3

參考4

賬號管理參考

config參數

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章