Set up Gerrit environment Ubuntu

Set up Gerrit environment

1.Install apache

	sudo apt-get install apache2
注意:To run Gerrit behind an Apache server using 'mod_proxy', enable the necessary 
Apache2 modules:
执行:sudo a2enmod proxy_http
执行:sudo a2enmod ssl 
使新的配置生效,需要执行如下命令:
  service apache2 restart

2. Install PostgreSQL database

sudo apt-get install postgresql
注意:安装完postgresql后,会自动创建一个用户名和密码均为postgres的账户。

3. Add the database required by Gerrit

执行:sudo -u postgres createuser -RDIElPS zmj
执行:sudo -u postgres createdb -E UTF-8 -O zmj reviewdb

4.Install Gerrit

Download the Gerrit installation package from the Gerrit official website https://www.gerritcodereview.com/ Click Download to download gerrit-3.7.0.war

Create directory mkdir gerrit

Enter the directory cd gerrit

如果zmj@ubuntu:~/gerrit$ java -jar gerrit-3.7.0.war init -d review_site   提示
Command 'java' not found, but can be installed with:

sudo apt install default-jre            
sudo apt install openjdk-11-jre-headless
sudo apt install openjdk-8-jre-headless 
下载sudo apt install openjdk-11-jre-headless  后再次执行命令

Specify the git storage warehouse gerr and change the gerr file name to git

[root@localhost gerrit]# java -jar gerrit-3.1.3.war init -d review_site

根据提示一步步安装gerrit


*** Gerrit Code Review 3.1.3

***

Create '/usr/local/src/gerrit/review_site' [Y/n]? y

#程序会自动创建该文件,必须输入”Y“,如果输入"N"则程序会退出,默认就是"Y",因此我们直接回车应该也可以的
 

*** Git Repositories

***

Location of Git repositories   [git]:/home/zmj/gerr

#指定Git存储库,最好指定一个不存在的目录,他会自动创建。

*** Index***

Type                           [lucene/?]:

#默认即可。

 
*** User Authentication***

Authentication method          [openid/?]: HTTP

#认证方法输入HTTP,我们要使用反向代理

Get username from custom HTTP header [y/N]? n

#询问咱们是否从自定义HTTP头获取用户名,我们输入”n“

SSO logout URL                 :

Enable signed push support     [y/N]? y

#启用签名的推送支持

*** Review Labels***

Install Verified label         [y/N]?

#安装已验证标签,默认即可。

 

SMTP server hostname           [localhost]: smtp.exmail.qq.com

#输入自动发送邮件的smtp服务器,这里我们用的是腾讯企业邮箱

SMTP server port               [(default)]: 465

#465/994时SSL协议端口后,25是非SSL协议端口号

SMTP encryption                [none/?]: SSL

#如果上一步输入的是465/994,此处输入SSL,否则直接回车即可

SMTP username                  [root]: [email protected]

#此处是你定义自动发送邮件的邮箱地址

[email protected]'s password :

#接着我们需要输入2次咱们邮箱的授权码。              

confirm password :

Run as                         [root]: #指定容器运行的进程用户,默认为root用户,我们默认即可

Java runtime                   [/yinzhengjie/softwares/jdk1.8.0_201/jre]:

#JAVA的运行环境。如果它识别的有误,你可以指定你服务器的环境

Copy gerrit-3.1.3.war to review_site/bin/gerrit.war [Y/n]? y

#拷贝gerri安装包

Copy gerrit-3.1.3.war to review_site/bin/gerrit.war

*** SSH Daemon***
 

Listen on address              [*]: n   

#指定SSH后台服务的监听地址

Listen on port                 [29418]:

#指定SSH后台服务的端口号

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]? n

#不适用SSL

Subdirectory on proxy server   [/]:

#指定代理服务器的子目录,默认为"/"路径,默认即可

Listen on address              [*]:

#只当gerrit服务的监听地址

Listen on port                 [8081]: 8888

#指定gerrit的服务端口

Canonical URL                  [[http://localhost/]:

#指定标准连接,咱们默认即可

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-AgXDzd1d-1678182424984) (C:\Users\zhangmj2\Desktop\VMware Workstation\Picture\image-20230110113520808.png )]

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-nhw43NoT-1678182424986) (C:\Users\zhangmj2\Desktop\VMware Workstation\Picture\image-20230110113545210.png )]

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-4Pk7yWDj-1678182424987) (C:\Users\zhangmj2\Desktop\VMware Workstation\Picture\image-20230110113602761.png )]

5. Email configuration

Enter the corresponding directory /home/zmj/gerrit/review_site/etc

Modify the gerrit.config file and add the from configuration in the sendemail section

    [sendemail]     发送邮件
            smtpServer = smtp.mxhichina.com
            smtpServerPort = 25       端口号
            smtpUser = 邮箱地址        
            from=CodeReview<邮箱地址>    代码审查 邮箱地址
            
 [gerrit]
basePath = git
canonicalWebUrl = http://192.168.168.128/                  //nginx的代理端口 

.........

[httpd]
listenUrl = http://*:8080/

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-HKAhw2f0-1678182424988) (C:\Users\zhangmj2\Desktop\VMware Workstation\Picture\image-20230110115804892.png )]

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-jrCs0Ujy-1678182424989) (C:\Users\zhangmj2\Desktop\VMware Workstation\Picture\image-20230110145430678.png )]

6. Restart Gerrit

cd gerrit/review_site/
./bin/gerrit.sh restart

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-nTiyINun-1678182424990) (C:\Users\zhangmj2\Desktop\VMware Workstation\Picture\image-20230110132740585.png )]

7.Apache reverse proxy configuration

Edit /etc/apache2/sites-enabled/000-default.conf

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-33ZnGl73-1678182424990) (C:\Users\zhangmj2\Desktop\VMware Workstation\Picture\image-20230110133931636.png )]

vim 000-default.conf modifies the file. After modifying the file, the file is now a link file and cannot be saved.

Command line sudo vim 000-default.conf and enter the password

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-ZGegykYh-1678182424991) (C:\Users\zhangmj2\Desktop\VMware Workstation\Picture\image-20230110142115615.png )]

注意:The ProxyPass 8080 must be same with the ./review_site/etc/gerrit.config.
When access the http://192.168.168.128:80,Apache2 will lead you to 
http://192.168.168.128:8080.
ProxyPass 8080必须和./review_site/etc/gerrit.config里的端口配置一致。当登录http://192.168.168.128:80的时候,Apache2会帮助打开http://192.168.168.128:8080。
<VirtualHost 192.168.1.179:80>

        ProxyRequests Off
        ProxyVia Off
        ProxyPreserveHost On
<Proxy *> 
    Order deny,allow
    Allow from all  
</Proxy>
<Location /login/>
    AuthType Basic
    AuthName "Welcome to Gerrit Code Review Site!"
    Require valid-user
    AuthUserFile /home/zmj/gerrit/review_site/etc/passwords
</Location>
AllowEncodedSlashes On
ProxyPass / http://127.0.0.1:8080/
</VirtualHost>

8. Restart the Apache service

service apache2 restart

9. Add Gerrit account

touch /home/zmj/gerrit/review_site/etc/passwords     创建密码文件
要在Gerrit的配置文件下创建用户
cd /home/zmj/gerrit/review_site/etc
htpasswd -m passwords zmj     创建zmj用户 密码为1

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-pNLCJ43f-1678182424991) (C:\Users\zhangmj2\Desktop\VMware Workstation\Picture\image-20230110140818329.png )]

10. Visit http://192.168.168.128:80

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-0qr0gFQA-1678182424992) (C:\Users\zhangmj2\Desktop\VMware Workstation\Picture\image-20230110151237692.png )]

Install php

sudo apt-get update更新
sudo apt-get install language-pack-en-base software-sudo properties-common -y			解决语言冲突和中文乱码
sudo locale-gen en_US.UTF-8			语言环境
sudo apt-get install vim -y         安装vim
sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php            使用ppa安装php (需要回车)
sudo apt-get update			再次更新
sudo apt-get install php7.4 php7.4-fpm php7.4-cli php7.4-dev php7.4-redis php7.4-mysql php7.4-curl php7.4-xml php7.4-json php7.4-gd php7.4-mbstring php7.4-zip php7.4-bcmath -y   	安装php和相关组件
php -v查看php版本
sudo apt-get install nginx -y     下载nginx
nginx -v    显示版本
sudo apt-get install mysql-server -y  
nginx -v    显示版本

11.Build gitweb

 sudo apt-get install gitweb

Configure it through git config

git config --file /home/zmj/gerrit/review_site/etc/gerrit.config gitweb.cgi /var/www/git/gitweb.cgi 
git config --file /home/zmj/gerrit/review_site/etc/gerrit.config --unset gitweb.url

Restart Gerrit

cd gerrit/review_site/
./bin/gerrit.sh restart
git config --global --unset /home/zmj/gerrit/review_site/etc/gerrit.config gitweb.cgi /var/www/git/gitweb.cgi 
git config --unset /home/zmj/gerrit/review_site/etc/gerrit.config --unset gitweb.url



Guess you like

Origin blog.csdn.net/weixin_48824655/article/details/129387588