赞
踩
导入代码的时候,遇到了很多困难,查阅了多方资料,最终还是完成。
值得参考的文献:
[1]: 将AOSP完整导入Gerrit Server
[2]: Repo Gerrit进阶
[3]: Repo 命令参考资料
[4]: Repo 推送一个已有的代码到新的 gerrit 服务器
[5]: 本地git项目放到gerrit仓库的三种方法
下载gerrit安装包至/home/gerrit/gerrit_war/目录,然后执行一下命令:
java -jar /home/gerrit/gerrit_war/gerrit-3.5.0.1.war init -d review_site
过程可以默认回车安装,之后去修改gerrit.config配置文件即可。
gerrit安装目录:/home/gerrit/review_site
gerrit代码镜像:/home/gerrit/review_site/git
gerrit配置文件:/home/gerrit/review_site/etc/gerrit.config
gerrit.config文件内容如下:(账号登录方式我采用的是ldap模式,登录方式和邮箱请自行配置)
[gerrit] basePath = git canonicalWebUrl = http://gerritbak.com/ serverId = 74c71aa9-3f3d-4319-beb5-87d103fe31a4 [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-11-openjdk-amd64 [index] type = lucene [auth] type = LDAP gitBasicAuthPolicy = HTTP userNameCaseInsensitive = true [ldap] server = ldap://xxx.xxx.xxx.xxx username = cn=admin,dc=xxx,dc=xx accountBase = ou=peoples,dc=xxx,dc=xx groupBase = ou=peoples,dc=xxx,dc=xx [receive] enableSignedPush = false maxBatchCommits = 10000000 timeout = 120min [sendemail] smtpServer = localhost [sshd] listenAddress = *:29418 [httpd] listenUrl = proxy-http://*:8080/ [cache] directory = cache [sendemail] smtpServer = smtp.xxxxxxx.com smtpServerPort = 465 smtpEncryption = ssl smtpUser = xxxxxx@xxx.com smtpPass = xxxxxx sslVerify = false from = xxxxxx<xxxxxx@xxx.com> [download] command = checkout command = cherry_pick command = pull command = format_patch scheme = ssh scheme = http scheme = anon_http scheme = anon_git scheme = repo_download [gitweb] type = gitweb cgi = /usr/lib/cgi-bin/gitweb.cgi
gerrit服务重启命令:sudo sh /home/gerrit/review_site/bin/gerrit.sh restart
gerrit服务停止命令:sudo sh /home/gerrit/review_site/bin/gerrit.sh stop
gerrit服务开启命令:sudo sh /home/gerrit/review_site/bin/gerrit.sh start
gerrit创建仓库命令:
ssh -p 29418 gerrit@172.30.50.60 gerrit create-project --empty-commit [projectname]
apache2安装目录:/etc/apache2
apache2配置文件:/etc/apache2/sites-enabled/000-default.conf
000-default.conf文件内容如下:
<VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. ServerName gerritbak.com ServerAdmin webmaster@localhost DocumentRoot /var/www/html # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined ProxyRequests off ProxyVia Off ProxyPreserveHost On <Proxy *> Order deny,allow Allow from all </Proxy> AllowEncodedSlashes On ProxyPass / http://xxx.xxx.xxx.xxx:8080/ nocanon # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost>
apache2服务重启:sudo systemctl restart apache2
repo init, 我们一般下载code的方式为:
repo init -u xxx -b yyy -m zzz.xml
repo sync -c -j8 # -c:仅获取服务器中的当前清单分支; -j:将同步操作拆分成多个线程.
注意:
-m 当有多个清单文件,可以指定清单库的某个清单文件为有效的清单文件,如果省略该参数,则用该库里默认的清单文件;
repo init命令执行后主要干了两件事:
repo forall -c 'echo $REPO_PROJECT' | tee pro.log
#!/bin/bash USER_NAME="gerrit" SERVER_IP="172.30.50.60" SERVER_PORT="29418" function creatEmptyGerritProject() { for i in cat pro.log; do echo $i echo "ssh -p $SERVER_PORT $USER_NAME@$SERVER_IP gerrit create-project --empty-commit $i" ssh -p $SERVER_PORT $USER_NAME@$SERVER_IP gerrit create-project --empty-commit $i done } creatEmptyGerritProject
或者
repo forall -c 'pwd && ssh -p 29418 gerrit@172.30.50.60 gerrit create-project --empty-commit $REPO_PROJECT'
(repo forall -c 'pwd && git push -f --all ssh://gerrit@gerritbak.com:29418/$REPO_PROJECT')2>&1 | tee push.log
git push ssh://gerrit@gerritbak.com:29418/$REPO_PROJECT +refs/heads/*
git push ssh://gerrit@gerritbak.com:29418/$REPO_PROJECT +refs/heads/* +refs/tags/
git push -f --all ssh://gerrit@gerritbak.com:29418/$REPO_PROJECT
git push --mirror ssh://gerrit@gerritbak.com:29418/$REPO_PROJECT
创建好Gerrit备份服务器之后,需要迁移备份代码至新的服务器,以下是我尝试的多种方法,请根据自己的实际情况操作。
只讲方法,不贴具体命令了,这种方式只能单个分支推送代码。
克隆源码镜像,然后git push
git clone --mirror ssh://gerrit@gerrit.com:29418/$REPO_PROJECT(源码地址)
git push --mirror ssh://gerrit@gerritbak.com:29418/$REPO_PROJECT(新地址)
git clone --mirror $code_url#下载代码到任意位置
cd #进入下载完的代码目录下
git remote set-url origin $new_url#设置远程代码库地址为新建的库的地址
git push -f origin #推送代码至新建代码库
停止备份服务器的gerrit服务
sudo sh /home/gerrit/review_site/bin/gerrit.sh stop
克隆源码镜像至新的gerrit代码目录/home/gerrit/review_site/git;
git clone --mirror ssh://gerrit@gerrit.com:29418/$REPO_PROJECT(源码地址)
然后执行命令重建gerrit数据库索引,命令如下:
#review_site是gerrit的安装目录,gerrit-3.5.0.1.war是gerrit的war包
java -jar /home/gerrit/gerrit_war/gerrit-3.5.0.1.war reindex -d review_site
开启备份服务器的gerrit服务
sudo sh /home/gerrit/review_site/bin/gerrit.sh start
与方法3大致一样,只是直接复制源码目录至新的gerrit代码目录,然后重建gerrit索引,重启服务。
我们需要实现Gerrit服务器与它的备份服务器之间的代码同步,即当Gerrit有代码更新时,要实现能够实时同步到Gerrit备份服务器,我采用了以下冷备份的方式:
Ubuntu使用lsyncd实现远端目录实时同步
E
N
D
END
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。