目的,将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
十、参考文档
十一、附录:创建 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