前言
搭建gerrit的时候需要确保服务器是否和当前gerrit版本适配(大部分都适配),而且不要用最新版本的gerrit,会出现各种各样的BUG,切记!而且本文是按照创建新用户来搭建gerrit,为了方便和主用户区分,最好机器联网哈~
更新源
sudo apt-get update #更新源
安装java版本,并确认默认版本
sudo apt-get install openjdk-11-jdk
sudo update-alternatives --config java
sudo update-alternatives --config java
配置好后验证一下:
Java –version
创建单独的管理员用户
登录root用户
Sudo -s
创建新用户
sudo useradd -r -m -s /bin/bash 用户名
手动为用户设置密码
sudo passwd 用户名
加权限
chmod u+w /etc/sudoers
vim编辑器 打开sudoers文件
vim /etc/sudoers
在 root ALL=(ALL) ALL 后面加上:
XXX ALL = (ALL) ALL ##其中XXX表示你的用户名,保存之后退出
如下图:
恢复sudoers文件原来的读写权限
chmod u-w /etc/sudoers
退出root用户
exit
注:创建好后,需要将/home/gerrit给加上权限,否则不好使
sudo chmod 777 /home/gerrit
将gerrit包放入gerrit目录下并安装
java -jar gerrit-3.6.1.war init -d /home/gerrit/review_site
安装过程中的详细参数配置选项如下(大佬也可以直接跳过更改后面的配置文件即可):
gerrit@scm:~$ java -jar gerrit-3.6.1.war init -d /home/gerrit/review_site
Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore
[2022-10-08 08:25:51,417] [main] INFO com.google.gerrit.server.config.GerritServerConfigProvider : No /home/gerrit/review_site/etc/gerrit.config; as suming defaults
*** Gerrit Code Review 3.6.1
***
Create '/home/gerrit/review_site' [Y/n]? Y
*** Git Repositories
***
Location of Git repositories [git]: 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]?
*** 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 [gerrit]:
Java runtime [/usr/local/jdk-11.0.10]:
Copy gerrit-3.4.0.war to /home/gerrit/review_site/bin/gerrit.war [Y/n]? Y
Copying gerrit-3.4.0.war to /home/gerrit/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]? y
Proxy uses SSL (https://) [y/N]?
Subdirectory on proxy server [/]:
Listen on address [*]:
Listen on port [8081]:
Canonical URL [http://gerrit/]:
*** Cache
***
*** Plugins
***
Installing plugins.
Install plugin codemirror-editor version v3.6.1 [y/N]? y
Installed codemirror-editor v3.6.1
Install plugin commit-message-length-validator version v3.6.1 [y/N]? y
Installed commit-message-length-validator v3.6.1
Install plugin delete-project version v3.6.1 [y/N]? y
Installed delete-project v3.6.1
Install plugin download-commands version v3.6.1 [y/N]? y
Installed download-commands v3.6.1
Install plugin gitiles version v3.6.1 [y/N]? y
Installed gitiles v3.6.1
Install plugin hooks version v3.6.1 [y/N]? y
Installed hooks v3.6.1
Install plugin plugin-manager version v3.6.1 [y/N]? y
Installed plugin-manager v3.6.1
Install plugin replication version v3.6.1 [y/N]? y
Installed replication v3.6.1
Install plugin reviewnotes version v3.6.1 [y/N]? y
Installed reviewnotes v3.6.1
Install plugin singleusergroup version v3.6.1 [y/N]? y
Installed singleusergroup v3.6.1
Install plugin webhooks version v3.6.1 [y/N]? y
Installed webhooks v3.6.1
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/gerrit/review_site
Init complete, reindexing accounts with: reindex --site-path /home/gerrit/review_site --threads 1 --index accountsReindexed 0 documents in accounts i ndex in 0.0s (0.0/s)
Index accounts in version 11 is ready
Collecting projects: 2 changes with: reindex --site-path /home/gerrit/review_site --threads 1 --index changes
Reindexing changes: project-slices: 100% (2/2), done
Reindexed 0 documents in changes index in 0.0s (0.0/s)
Index changes in version 61 is ready
Reindexing groups: 100% (2/2)ith: reindex --site-path /home/gerrit/review_site --threads 1 --index groups
Reindexed 2 documents in groups index in 0.2s (10.2/s)
Index groups in version 8 is ready
Reindexing projects: 100% (2/2) with: reindex --site-path /home/gerrit/review_site --threads 1 --index projects
Reindexed 2 documents in projects index in 0.1s (13.4/s)
Index projects in version 4 is ready
安装完成后,进入主目录和开始安装后的那个路径,本文命名为review_site
cd review_site/bin
./gerrit.sh start #启动gerrit
显示 OK ,说明 gerrit 启动正常,打开浏览器访问 gerrit 系统看看效果,这个ip就是当前ip,或者也可以是127.0.0.1也可以访问 (本机访问)
浏览器页面显示Check the HTTP server's authentication settings. 提示代理配置有问题,因为我们还没有安装,接着安装配置好代理服务器即可。
安装apache2
sudo apt-get install apache2
进入如下路径,如下图
cd /etc/apache2
先进入port.conf文件中,按照如下图进行更改即可
vim port.conf
保存好后进入如下文件中sites-enabled
创建文件gerrit.conf,进行如下更改即可
cd sites-enabled
sudo touch gerrit.conf
进入安装的gerrit根目录下
cd etc
vim gerrit.config
最终更改好后按照如下方式重启即可
重启apache2:
sudo systemctl restart apache2
重启gerrit:
#需要进入到gerrit根目录下
cd bin
./gerrit.sh restart
最后让我们登录对应的IP地址就可以正常访问gerrit服务器啦,gerrit里面的各种权限配置我放在下一章去写~