前言

现状:我们一直使用的是集中式的版本管理工具SVN,由专人维护,个人管理个人的代码,代码比较分散,代码分支和合并比较混乱,由此,考虑使用分布式版本管理工具git,但是对于android这种超大型的项目(数百个git库),使用单纯的git服务器已经不能满足需求了,需要采用google原厂的repo方式 (封装了git服务器),经过查找资料,服务端决定采用gitolite + gerrit + repo的方式管理源代码,以下是版本管理的必要性,引用自《git权威指南》:
在这里插入图片描述
正好我们新安装了一台服务器,在这台服务器上折腾一下gerrit3 的安装,目前最新3.6 ,没调通,最后选择了gerrit-3.1.16

一、安装git服务器

sudo apt-get install git

生成秘钥

ssh-keygen -t rsa -C xxx@xxxx.com

二、gerrit 服务器

1 安装java环境

sudo apt install default-jre            
sudo apt install openjdk-11-jre-headless
sudo apt install openjdk-8-jre-headless 

2 安装gerrit服务器

2.1 下载
https://www.gerritcodereview.com/releases-readme.html

我下载的是gerrit-3.1.16 重装了好几遍,只有这个能用,WTF!

2.2 安装
#gerrit3最新版没调通,装完后没有插件 安装3.5.2后所有的用户都能推送版本!!!
java -jar   gerrit-3.1.16.war init -d review_site

按照提示一步步完成安装。
只有Authentication method [openid/?]: http 其他默认,我的配置过程如下

git@pzdf-PowerEdge-R740:~$ java -jar gerrit-3.1.16.war init -d review_site
Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore
[2022-10-01 18:17:35,896] [main] INFO  com.google.gerrit.server.config.GerritServerConfigProvider : No /home/git/review_site/etc/gerrit.config; assuming defaults

*** Gerrit Code Review 3.5.2
*** 

Create '/home/git/review_site' [Y/n]? y

*** Git Repositories
*** 

Location of Git repositories   [git]: 

*** JGit Configuration
*** 

Auto-configured "receive.autogc = false" to disable auto-gc after git-receive-pack.

*** Index
*** 

Type                           [lucene]: 

*** User Authentication
*** 

Authentication method          [openid/?]: http
Get username from custom HTTP header [y/N]? 
SSO logout URL                 : 
Enable signed push support     [y/N]? 
Use case insensitive usernames [Y/n]? 

*** Review Labels
*** 

Install Verified label         [y/N]? 

*** Email Delivery
*** 

SMTP server hostname           [localhost]: 
SMTP server port               [(default)]: 
SMTP encryption                [none/?]: 
SMTP username                  : 

*** Container Process
*** 

Run as                         [git]: 
Java runtime                   [/usr/lib/jvm/java-11-openjdk-amd64]: 
Copy gerrit-3.5.2.war to review_site/bin/gerrit.war [Y/n]? 
Copying gerrit-3.5.2.war to review_site/bin/gerrit.war

*** SSH Daemon
*** 

Listen on address              [*]: 
Listen on port                 [29418]: 
Generating SSH host key ... rsa... ed25519... ecdsa 256... ecdsa 384... ecdsa 521... done

*** HTTP Daemon
*** 

Behind reverse proxy           [y/N]? 
Use SSL (https://)             [y/N]? 
Listen on address              [*]: 
Listen on port                 [8080]: 8888
Canonical URL                  [http://pzdf-PowerEdge-R740:8888/]: 

*** Cache
*** 


*** Plugins
*** 

Installing plugins.
Install plugin codemirror-editor version v3.5.2 [y/N]? y
Installed codemirror-editor v3.5.2
Install plugin commit-message-length-validator version v3.5.2 [y/N]? y
Installed commit-message-length-validator v3.5.2
Install plugin delete-project version v3.5.2 [y/N]? y
Installed delete-project v3.5.2
Install plugin download-commands version v3.5.2 [y/N]? y
Installed download-commands v3.5.2
Install plugin gitiles version v3.5.2 [y/N]? y
Installed gitiles v3.5.2
Install plugin hooks version v3.5.2 [y/N]? y
Installed hooks v3.5.2
Install plugin plugin-manager version v3.5.2 [y/N]? y
Installed plugin-manager v3.5.2
Install plugin replication version v3.5.2 [y/N]? y
Installed replication v3.5.2
Install plugin reviewnotes version v3.5.2 [y/N]? y
Installed reviewnotes v3.5.2
Install plugin singleusergroup version v3.5.2 [y/N]? y
Installed singleusergroup v3.5.2
Install plugin webhooks version v3.5.2 [y/N]? y
Installed webhooks v3.5.2
Initializing plugins.

============================================================================
Welcome to the Gerrit community

Find more information on the homepage: https://www.gerritcodereview.com
Discuss Gerrit on the mailing list: https://groups.google.com/g/repo-discuss
============================================================================
Initialized /home/git/review_site
Init complete, reindexing accounts,changes,groups,projects with: reindex --site-path review_site --threads 1 --index accounts --index changes --index groups --index projects --disable-cache-statsReindexed 0 documents in accounts index in 0.0s (0.0/s)
Index accounts in version 11 is ready
Reindexing groups:      100% (2/2)
Reindexed 2 documents in groups index in 0.3s (6.8/s)
Index groups in version 8 is ready
Reindexing changes: Slicing projects: 100% (2/2), done    
Reindexed 0 documents in changes index in 0.5s (0.0/s)
Index changes in version 71 is ready
Reindexing projects:    100% (2/2)
Reindexed 2 documents in projects index in 0.0s (45.5/s)
Index projects in version 4 is ready
Executing /home/git/review_site/bin/gerrit.sh start
Starting Gerrit Code Review: WARNING: Could not adjust Gerrit's process for the kernel's out-of-memory killer.
         This may be caused by /home/git/review_site/bin/gerrit.sh not being run as root.
         Consider changing the OOM score adjustment manually for Gerrit's PID=32313 with e.g.:
         echo '-1000' | sudo tee /proc/32313/oom_score_adj
OK
Waiting for server on pzdf-PowerEdge-R740:8888 ... OK
Opening http://pzdf-PowerEdge-R740:8888/#/admin/projects/ ...OK
2.3 测试
curl http://localhost:8888

git@pzdf-PowerEdge-R740:~$ curl http://pzdf-PowerEdge-R740:8888/
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <title>Gerrit Code Review</title>
    <script type="text/javascript">
      var href = window.location.href;
      var query = "";
      var q = href.indexOf('?');
      if (q >= 0) {
        query = href.substring(q);
        href = href.substring(0,q);
      }
      var p = href.indexOf('#');
      var token;
      if (p >= 0) {
        token = href.substring(p);
        href = href.substring(0, p);
      } else {
        token = '';
      }
      window.location.replace(href + 'login/' + token + query);
    </script>
  </head>
  <body>
    <p>Redirecting to <a href="login/">Gerrit Code Review</a>.</p>
  </body>
</html>
2.4 配置gerrit服务器

参考配置如下:
注意我们要使用Nginx代理服务器,
listenUrl = http://:8888/ 改为
listenUrl = proxy-http://
:8888/

vi review_site/etc/gerrit.config 
[gerrit]
        basePath = git
        canonicalWebUrl = http://pzdf-PowerEdge-R740:8888/
        serverId = c0f0955f-a2e2-4b40-9e0c-c598069aced6
[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 = git
        javaHome = /usr/lib/jvm/java-11-openjdk-amd64
[index]
        type = lucene
[auth]
        type = HTTP
        userNameCaseInsensitive = true
[receive]
        enableSignedPush = false
[sendemail]
        smtpServer = localhost
[sshd]
        listenAddress = *:29418
[httpd]
        listenUrl = proxy-http://*:8888/
[cache]
        directory = cache
[sendemail]
    #smtpServer = localhost
    enable = true
    smtpServer = smtp.163.com
    smtpServerPort = 465
    smtpEncryption = SSL
    sslVerify = true
    smtpUser = xxxx@163.com
    from = xxxx@163.com

vi ./etc/secure.config

[sendemail]
smtpPass = xxxxxx #这里是授权码 不是密码 这里需要登录相应官网生成

按照如上内容配置完 Gerrit Server 之后,可以通过如下命令重新启动它以应用新的配置:

$ review_site/bin/gerrit.sh restart

三、安装nginx服务器

sudo  apt-get install nginx
sudo vim /etc/nginx/conf.d/gerrit.conf 

server {
        listen 9091;
        server_name 192.168.0.128;

        auth_basic "welcome to pzdf gerrit code review site";
        auth_basic_user_file /home/git/review_site/etc/git_passwords;

        location / {
                root html;
                #index index.html index.htm;
                #auth_basic "Gerrit Code Review";
                #auth_basic_user_file /etc/httpd/passwords;
                proxy_pass http://192.168.0.128:8888;
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_set_header Host $host;
                #indx index.html index.html;
                }
        }

#测试配置是否正确

sudo nginx -t

添加用户
sudo htpasswd -cb  review_site/etc/git_passwords xxx xxxxxx

开启nginx
nginx  #启动nginx

#重新加载文件
sudo nginx -s reload

最后在浏览器输入http://192.168.0.128:9090
在这里插入图片描述
有这个图片表示ok

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐