gerrit3.0.8安装配置apache反向代理(ubuntu18.04)
1.准备工作
1.创建gerrit用户,授权sudo
sudo adduser gerrit //创建用户 sudo visudo //在/etc/sudoers文件的root下增加: gerrit ALL=(ALL:ALL) ALL
2.切换gerrit用户,准备安装环境
a)安装java1.8(java -version:1.8.0_252)
su gerrit (sudo apt-get install software-properties-common python-software-properties) sudo add-apt-repository ppa:openjdk-r/ppa sudo apt-get update sudo apt-get install openjdk-8-jdk
b)安装apache2并设置反向代理(apache2 -version:2.4.29)
sudo apt-get install apache2
也可以安装nginx进行反向代理,由于nginx和apache都监听80端口,当先安装了nginx后,会导致80端口被占用而无法启动apache。
sudo netstat -tunlp |grep :80 # 查看80端口的占用
apache和nginx选一使用,两个不能同时使用。实操我使用的是apache2。
apache2设置反向代理:
sudo vim /etc/apache2/sites-enabled/000-default.conf
在000-default.conf中增加如下内容:
<VirtualHost *:8082> ServerName 192.168.90.28 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/gerrit/review_site/etc/passwd </Location> AllowEncodedSlashes On ProxyPass / http://192.168.90.28:8081/ nocanon </VirtualHost>
修改配置文件,添加对8082端口的监听:
sudo vim /etc/apache2/ports.conf
添加:
Listen 8082
开启SSL、Proxy、Rewrite等模块:
cd /etc/apache2/mods-enabled/ sudo ln -s ../mods-available/proxy.load sudo ln -s ../mods-available/proxy.conf sudo ln -s ../mods-available/proxy_http.load sudo ln -s ../mods-available/proxy_balancer.conf sudo ln -s ../mods-available/proxy_balancer.load sudo ln -s ../mods-available/rewrite.load sudo ln -s ../mods-available/ssl.conf sudo ln -s ../mods-available/ssl.load sudo ln -s ../mods-available/slotmem_shm.load sudo ln -s ../mods-available/socache_shmcb.load
重启apache:
sudo /etc/init.d/apache2 restart
nginx设置反向代理:
sudo vim /etc/nginx/sites-enabled/default
在default中添加如下内容:
server { listen 8082; listen [::]:8082; server_name localhost; location / { auth_basic "Welcome to Gerrit Code Review Site"; auth_basic_user_file /home/gerrit/review_site/etc/passwd; proxy_pass http://localhost:8081; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $host; } location /login/ { proxy_pass http://localhost:8081; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $host; } }
加载nginx配置生效
sudo nginx –s reload
c)安装git(默认是git --version:2.17.1)
sudo apt-get install git
d)安装gitweb(可选)
Gitweb工具支持网页查看git版本库中的代码, 可以很直观的看见代码的提交记录
sudo apt-get install gitweb //安装gitweb dpkg –L gitweb //查看相关配置文件安装路径
2.安装gerrit3.0.8
1.下载安装包
下载地址: https://www.gerritcodereview.com/, 选择想安装的版本,本示例安装3.0.8版
2.安装过程(在gerrit的家目录执行)
gerrit@ubuntu:~$ java -jar gerrit-3.0.8.war init -d review_site Using secure store: com.google.gerrit.server.securestore.DefaultSecureStore [2020-04-28 20:30:53,238] [main] INFO com.google.gerrit.server.config.GerritServerConfigProvider : No /home/gerrit/review_site/etc/gerrit.config; assuming defaults *** Gerrit Code Review 3.0.8 *** Create '/home/gerrit/review_site' [Y/n]? *** Git Repositories *** Location of Git repositories [git]: *** 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]? *** Review Labels *** Install Verified label [y/N]? y *** Email Delivery *** SMTP server hostname [localhost]: smtp.163.com SMTP server port [(default)]: 25 SMTP encryption [none/?]: SMTP username [gerrit]: love@163.com loveee148@163.com's password : 输入密码 confirm password : 确认密码 *** Container Process *** Run as [gerrit]: Java runtime [/usr/lib/jvm/java-8-openjdk-amd64/jre]: Copy gerrit-3.0.8.war to review_site/bin/gerrit.war [Y/n]? Copying gerrit-3.0.8.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]? y Use SSL (https://) [y/N]? Listen on address [*]: Listen on port [8080]: 8081 Canonical URL [http://192.168.90.28:8081/]: http://192.168.90.28:8082 #这里一定要使用反向代理的端口号及具体的IP地址 *** Cache *** *** Plugins *** Installing plugins. Install plugin codemirror-editor version v3.0.8 [y/N]? y Installed codemirror-editor v3.0.8 Install plugin commit-message-length-validator version v3.0.8 [y/N]? y Installed commit-message-length-validator v3.0.8 Install plugin delete-project version v3.0.8 [y/N]? y Installed delete-project v3.0.8 Install plugin download-commands version v3.0.8 [y/N]? y Installed download-commands v3.0.8 Install plugin gitiles version v3.0.8 [y/N]? y Installed gitiles v3.0.8 Install plugin hooks version v3.0.8 [y/N]? y Installed hooks v3.0.8 Install plugin plugin-manager version v3.0.8 [y/N]? y Installed plugin-manager v3.0.8 Install plugin replication version v3.0.8 [y/N]? y Installed replication v3.0.8 Install plugin reviewnotes version v3.0.8 [y/N]? y Installed reviewnotes v3.0.8 Install plugin singleusergroup version v3.0.8 [y/N]? y Installed singleusergroup v3.0.8 Install plugin webhooks version v3.0.8 [y/N]? y Installed webhooks v3.0.8 Initializing plugins. Initialized /home/gerrit/review_site Init complete, reindexing projects with: reindex --site-path review_site --tReindexing projects: 100% (2/2) Reindexed 2 documents in projects index in 0.1s (32.3/s)
查看gerrit的配置文件(在/home/gerrit/review_site/etc/gerrit.config)
[gerrit] basePath = git #指定被gerrit管理的所有git仓库存放位置 canonicalWebUrl = http://192.168.90.28:8082 #gerrit的主页地址,这个地址要通过apache2反向代理到下面配置的http监听的地址端口上 serverId = 866a016a-eeee-48d0-b0da-76af742329e4 [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 = gerrit javaHome = /usr/lib/jvm/java-8-openjdk-amd64/jre [index] type = LUCENE [auth] type = HTTP #指定浏览器登录gerrit时的认证方式 [receive] enableSignedPush = false [sendemail] smtpServer = smtp.163.com smtpUser = love@163.com smtpServerPort = 25 from = love@163.com # 发送邮箱,这个项目安装配置项内没有,需要手动在配置文件中添加,不然gerrit3.0发送邮件失败 [sshd] listenAddress = *:29418 [httpd] listenUrl = http://*:8081/ # 监听地址和端口 [cache] directory = cache
[gitweb]
type = gitweb
cgi = /usr/lib/cgi-bin/gitweb.cgi
3.配置gerrit用户
htpasswd –b ./review_site/etc/passwd gerrit gerrit //账户:gerrit,密码:gerrit ./review_site/bin/gerrit.sh restart //重启gerrit
4.访问gerrit(实际访问地址为:http://192.168.90.28:8082)