环境ubuntu,地址192.168.100.131
root@ubuntu:/home/gerrit# cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
UBUNTU_CODENAME=xenial
root@ubuntu:/home/gerrit# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:68:2e:95 brd ff:ff:ff:ff:ff:ff
inet 192.168.100.131/24 brd 192.168.100.255 scope global dynamic ens33
valid_lft 1565sec preferred_lft 1565sec
inet6 fe80::1150:53a2:e6b2:b640/64 scope link
valid_lft forever preferred_lft forever
安装jdk
sudo apt-get install openjdk-8-jdk
安装apache
root@ubuntu:~# sudo apt-get install apache2
root@ubuntu:~# service apache2 start
安装gerrit
root@ubuntu:~# sudo adduser gerrit
Adding user `gerrit' ...
Adding new group `gerrit' (1002) ...
Adding new user `gerrit' (1002) with group `gerrit' ...
Creating home directory `/home/gerrit' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
Sorry, passwords do not match
passwd: Authentication token manipulation error
passwd: password unchanged
Try again? [y/N] y
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for gerrit
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n]
Home Phone []:
Other []:
Is the information correct? [Y/n]
root@ubuntu:~#
vi /etc/sudoer
#添加以下内容
gerrit ALL=(ALL:ALL) ALL
https://gerrit-releases.storage.googleapis.com/gerrit-2.12.4.war下载gerrit安装包
root@ubuntu:~# cp gerrit-2.12.4.war /home/gerrit/
root@ubuntu:~# cd /home/gerrit/
root@ubuntu:/home/gerrit# chown gerrit:gerrit gerrit-2.12.4.war
root@ubuntu:/home/gerrit# su - gerrit
gerrit@ubuntu:~$ java -jar gerrit-2.12.4.war init --batch -d ~/review_site
[2022-04-05 08:46:22,789] [main] INFO com.google.gerrit.server.config.GerritServerConfigProvider : No /home/gerrit/review_site/etc/gerrit.config; assuming defaults
Generating SSH host key ... rsa(simple)... done
Initialized /home/gerrit/review_site
Executing /home/gerrit/review_site/bin/gerrit.sh start
配置gerrit
root@ubuntu:/home/gerrit# cat review_site/etc/gerrit.config
[gerrit]
basePath = git
canonicalWebUrl = http://192.168.100.131:8081/
[database]
type = h2
database = /home/gerrit/review_site/db/ReviewDB
[index]
type = LUCENE
[auth]
type = http
[receive]
enableSignedPush = false
[sendemail]
smtpServer = localhost
[container]
user = gerrit
javaHome = /usr/lib/jvm/java-8-openjdk-amd64/jre
[sshd]
listenAddress = *:29418
[httpd]
listenUrl = http://*:8081/
[cache]
directory = cache
[http]
proxy = http://192.168.100.131:8090
proxyUsername = gerrit1
proxyPassword = 123456
配置apache
root@ubuntu:/home/gerrit# cat /etc/apache2/sites-enabled/gerrit-httpd.conf
ServerName 192.168.100.131
<VirtualHost *:8090>
ProxyRequests Off
ProxyVia Off
ProxyPreserveHost On
AllowEncodedSlashes On
RewriteEngine On
RewriteRule ^/(.*) http://192.168.100.131:8081/$1 [NE,P]
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location /login/>
AuthType Basic
AuthName "Gerrit Code Review"
Require valid-user
AuthBasicProvider file
AuthUserFile /etc/apache2/passwords
</Location>
ProxyPass / http://127.0.0.1:8081/
</VirtualHost>
root@ubuntu:/etc/apache2/mods-enabled# touch /etc/apache2/passwords
root@ubuntu:/etc/apache2/mods-enabled# htpasswd -b /etc/apache2/passwords admin 123456
Adding password for user admin
root@ubuntu:/etc/apache2/mods-enabled# htpasswd -b /etc/apache2/passwords gerrit1 123456
Adding password for user gerrit1
root@ubuntu:/etc/apache2/mods-enabled# htpasswd -b /etc/apache2/passwords alice 123456
Adding password for user alice
root@ubuntu:/home/gerrit# cat /etc/apache2/ports.conf
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf
Listen 80
Listen 8090
<IfModule ssl_module>
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
访问登录
alice用户使用
Admin@PS2020XTKFOPCF MINGW64 /d/IdeaProjects/J2EE (master)
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Admin/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Admin/.ssh/id_rsa
Your public key has been saved in /c/Users/Admin/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:61B4H/c9dHB73d4aidPxaKibA2b9EzugAXlz+xZ8wj0 Admin@PS2020XTKFOPCF
The key's randomart image is:
+---[RSA 3072]----+
| |
| |
| . . .|
| o.o . o+|
| .oS+.+...o=|
| o=o+o*=EB+|
| .o.+.++*Bo=|
| o. .oBo o.|
| . ++ o. |
+----[SHA256]-----+
id_rsa.pub中的内容拷贝到
测试Alice是否能够登录gerrit服务器
(默认缺少协商协议,.ssh目录中增加一个config文件后,问题解决)
Admin@PS2020XTKFOPCF MINGW64 /d/IdeaProjects/J2EE (master)
$ ssh alice@192.168.100.131 -p 29418
Unable to negotiate with 192.168.100.131 port 29418: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1
Admin@PS2020XTKFOPCF MINGW64 /d/IdeaProjects/J2EE (master)
$ cat /c/Users/Admin/.ssh/config
Host *
KexAlgorithms +diffie-hellman-group1-sha1
Admin@PS2020XTKFOPCF MINGW64 /d/IdeaProjects/J2EE (master)
$ ssh alice@192.168.100.131 -p 29418
The authenticity of host '[192.168.100.131]:29418 ([192.168.100.131]:29418)' can't be established.
RSA key fingerprint is SHA256:hHie0ykoa0kObQev9P6SGLG3wFkOGzmFwovOMGbkB9M.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[192.168.100.131]:29418' (RSA) to the list of known hosts.
**** Welcome to Gerrit Code Review ****
Hi Alice Taylor, you have successfully connected over SSH.
Unfortunately, interactive shells are disabled.
To clone a hosted Git repository, use:
git clone ssh://alice@192.168.100.131:29418/REPOSITORY_NAME.git
Connection to 192.168.100.131 closed.
Admin@PS2020XTKFOPCF MINGW64 /d/study/gerrit
$ git clone ssh://alice@192.168.100.131:29418/J2EE.git
Cloning into 'J2EE'...
remote: Counting objects: 2, done
remote: Finding sources: 100% (2/2)
remote: Total 2 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (2/2), done.