Linux下搭建、部署 Apache2 + Gerrit 3.8.0

目的,将Gerrit的8081映射到Apache2的8090

一、安装 JDK11

sudo apt install openjdk-11-jdk
vim ~/.bashrc 
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

二、下载、安装 Gerrit

进入官网 或者
直接下载

java -jar gerrit-3.8.2.war init -d gerrit_site

三、安装 Apache2 、改端口号

sudo apt-get install apache2

浏览默认的 Apache2 Ubuntu Default Page

sudo vim /etc/apache2/apache2.conf
# + Include httpd.conf
 
sudo vim /etc/apache2/ports.conf
# + Listen 8090

四、配置代理

sudo vim /etc/apache2/httpd.conf
<VirtualHost *:8090>
    ServerName 172.29.36.11

    ProxyRequests Off
    ProxyVia Off
    ProxyPreserveHost On

    <Proxy *>
          Order deny,allow
          Allow from all
    </Proxy>

    <Location /login/>
      AuthType Basic
      AuthName "Gerrit Code Review"
      Require valid-user
      AuthBasicProvider file
      AuthUserFile /home/yuyan/opt/gerrit_site/etc/passwords
    </Location>


    AllowEncodedSlashes On
    ProxyPass / http://172.29.36.11:8081/
</VirtualHost>

五、Gerrit 注册账号

htpasswd -cb httppwd admin 12345678
htpasswd -b httppwd gerrti_1 ******
cp /home/yuyan/project/Gerrit/user/httppwd gerrit_site/etc/passwords

六、Gerrit 配置网址和端口

官方配置文档

vim /home/yuyan/opt/gerrit_site/etc/gerrit.config
git config --file /home/yuyan/opt/gerrit_site/etc/gerrit.config auth.type HTTP
[gerrit]
	basePath = git
	canonicalWebUrl = http://172.29.36.11:8081
	serverId = 72542828-55f1-4ff9-ba4d-ac2a54687412
[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 = yuyan
	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://*:8081/
[cache]
	directory = cache
[plugins]
	allowRemoteAdmin = true

七、启动代理

sudo a2enmod proxy
sudo a2enmod proxy_http
sudo apache2ctl -M
a2enmod ssl          ; # optional, needed for HTTPS / SSL

八、操作重启 Apache2 等

sudo /etc/init.d/apache2 restart
sudo /etc/init.d/apache2 start
sudo /etc/init.d/apache2 stop
sudo /etc/init.d/apache2 status

九、操作重启 Gerrit

/home/yuyan/opt/gerrit_site/bin/gerrit.sh start
/home/yuyan/opt/gerrit_site/bin/gerrit.sh stop
/home/yuyan/opt/gerrit_site/bin/gerrit.sh restart

十、参考文档

  1. Gerrit代码审计系统实战-Gerrit 3.0.0版本快速搭建

  2. 部署gerrit 3.7.0

  3. 最新版 Gerrit 3.5.0.1 详细安装配置指南

  4. linux下搭建Gerrit

  5. linux下搭建Gerrit

  6. Apache:设置jenkins时命令ProxyRequests无效

  7. gerrit安装指南

十一、附录:创建 Gerrit 的勾勾选选

$ java -jar gerrit-3.8.2.war init -d gerrit_site
Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore
[2023-11-07 01:09:15,752] [main] INFO  com.google.gerrit.server.config.GerritServerConfigProvider : No /home/yuyan/opt/gerrit_site/etc/gerrit.config; assuming defaults

*** Gerrit Code Review 3.8.2
*** 

Create '/home/yuyan/opt/gerrit_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]? N
SSO logout URL                 : 
Enable signed push support     [y/N]? 
Use case insensitive usernames [Y/n]? 

*** Review Labels
*** 

Install Verified label         [y/N]? y

*** Email Delivery
*** 

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

*** Container Process
*** 

Run as                         [yuyan]: 
Java runtime                   [/usr/lib/jvm/java-11-openjdk-amd64]: 
Copy gerrit-3.8.2.war to gerrit_site/bin/gerrit.war [Y/n]? y
Copying gerrit-3.8.2.war to gerrit_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]? y
Proxy uses SSL (https://)      [y/N]? 
Subdirectory on proxy server   [/]: 
Listen on address              [*]: 
Listen on port                 [8081]: 
Canonical URL                  [http://Desktop-LocalPC.localdomain/]: 172.29.36.11    

*** Cache
*** 


*** Plugins
*** 

Installing plugins.
Install plugin codemirror-editor version v3.8.2 [y/N]? y
Installed codemirror-editor v3.8.2
Install plugin commit-message-length-validator version v3.8.2 [y/N]? y
Installed commit-message-length-validator v3.8.2
Install plugin delete-project version v3.8.2 [y/N]? y
Installed delete-project v3.8.2
Install plugin download-commands version v3.8.2 [y/N]? y
Installed download-commands v3.8.2
Install plugin gitiles version v3.8.2 [y/N]? y
Installed gitiles v3.8.2
Install plugin hooks version v3.8.2 [y/N]? y
Installed hooks v3.8.2
Install plugin plugin-manager version v3.8.2 [y/N]? y
Installed plugin-manager v3.8.2
Install plugin replication version v3.8.2 [y/N]? y
Installed replication v3.8.2
Install plugin reviewnotes version v3.8.2 [y/N]? y
Installed reviewnotes v3.8.2
Install plugin singleusergroup version v3.8.2 [y/N]? y
Installed singleusergroup v3.8.2
Install plugin webhooks version v3.8.2 [y/N]? y
Installed webhooks v3.8.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/yuyan/opt/gerrit_site
Init complete, reindexing accounts,changes,groups,projects with: reindex --site-path gerrit_site --threads 1 --index accounts --index changes --index groups --index projectsReindexed 0 documents in accounts index in 0.0s (0.0/s)
Index accounts in version 12 is ready
Reindexing groups:      100% (2/2)
Reindexed 2 documents in groups index in 0.2s (10.6/s)
Index groups in version 9 is ready
Reindexing changes: Slicing projects: 100% (2/2), done    
Reindexed 0 documents in changes index in 0.0s (0.0/s)
Index changes in version 82 is ready
Reindexing projects:    100% (2/2)
Reindexed 2 documents in projects index in 0.0s (60.6/s)
Index projects in version 5 is ready
Executing /home/yuyan/opt/gerrit_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/yuyan/opt/gerrit_site/bin/gerrit.sh not being run as root.
         Consider changing the OOM score adjustment manually for Gerrit's PID=403 with e.g.:
         echo '-1000' | sudo tee /proc/403/oom_score_adj
OK
Linux环境下搭建git+repo+gerrit的代码评审服务器,并配置相应的权限管理涉及多个步骤,需要仔细操作来确保系统的稳定和安全。这里以《详述git+repo+gerrit代码评审服务器搭建教程》为参考,提供详细的搭建指南。 参考资源链接:[详述git+repo+gerrit代码评审服务器搭建教程](https://wenku.csdn.net/doc/6412b4acbe7fbd1778d40697) 首先,需要在服务器上安装必要的软件,包括gitgitosis。可以通过包管理器安装git,而gitosis的安装需要下载源码进行。安装过程中可能还需要安装python-setuptools,以便顺利安装gitosis。 接着,创建一个名为git的系统用户,并禁用其密码,只通过SSH公钥进行访问。这一步是为了增强系统的安全性,防止未授权的登录。 随后,使用客户端的SSH公钥初始化gitosis,并将公钥复制到服务器上。管理员可以通过`gitosis-init`命令来管理用户的权限和项目的访问,这意味着要编辑`gitosis.conf`文件以设置不同的权限。 配置git-daemon-run时,需要指定监听的端口和仓库路径,这样可以确保只有授权的用户能够访问到代码库。配置完成后,重启git-daemon服务来应用更改。 搭建repo服务器需要在客户端进行,首先下载`git-repo.git`,然后配置环境变量,将repo脚本添加到PATH中,这样可以全局地使用repo命令来管理多个Git仓库。 整个搭建过程涉及到的配置和步骤较多,每一步都需要按照指南精确执行。由于搭建环境可能因具体版本和需求有所不同,建议在每一步都进行仔细的测试,确保系统运行无误后,再进行下一步。 完成以上步骤后,系统将具备基本的代码版本控制和权限管理功能。最后,可以安装Gerrit,这是用于实现代码审查的Web界面工具,通过与git协同工作,可以为团队提供一个高效的代码审查流程。这一步骤包括配置Gerrit的SSH公钥、设置项目权限以及配置Gerrit的Web界面,从而使得团队成员可以提交代码前进行审查。 通过上述步骤,你将搭建起一个完整的代码评审环境,不仅能够进行代码版本控制,还能有效管理权限,并通过审查提升代码质量。这个过程中,《详述git+repo+gerrit代码评审服务器搭建教程》将是你的得力助手,它不仅涵盖了搭建教程,还提供了实战经验分享,帮助你解决实际遇到的问题。 参考资源链接:[详述git+repo+gerrit代码评审服务器搭建教程](https://wenku.csdn.net/doc/6412b4acbe7fbd1778d40697)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值