ubuntu18.04搭建gerrit+gitweb代码审核系统(gerrit-3.2.3,自己亲手搭建经验总结贴)

4 篇文章 0 订阅
2 篇文章 0 订阅

一、Ubuntu新增gerrit账号

  • 配置gerrit的管理账号
    sudo adduser gerrit
  • 分配管理员权限给gerrit账号
    sudo usermod -a -G sudo gerrit
  • 后续操作切换到gerrit账号
    sudo su gerrit

二、Ubuntu安装java环境

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update    
sudo apt-get install openjdk-8-jdk

三、安装git

sudo apt-get install git

四、安装Apache2

sudo apt-get install apache2

五、配置Apache2

  1. 进入apache2设置目录
    cd /etc/apache2
  2. 修改三个配置文件:
    httpd.conf
    apache2.conf
    ports.conf

这三个文件都处于/etc/apache2目录,如下图所示:

gerrit@100ask:/etc/apache2$ ls
apache2.conf conf-available  conf-enabled  envvars  httpd.conf  magic  mods-available  mods-enabled  ports.conf  sites-available  sites-enabled

备注:httpd.conf文件没有的话需要手动创建,见下述步骤。

5.1 首先配置httpd.conf,文件httpd.conf输入以下配置信息

sudo touch /etc/apache2/httpd.conf
sudo vim /etc/apache2/httpd.conf
<VirtualHost *:8081>
#这里是反射代理的端口号,

    ServerName 192.168.8.191
    #这里是填写Apache反射代理的ip地址,也就是你服务器的ip地址

    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/passwords
        #这个路径是gerrit账户密码管理,后续的步骤中会创建此文件。路径有写正确
    </Location>

    AllowEncodedSlashes On

    ProxyPass / http://192.168.8.191:8091/
    #这里是代理反射,照着写就OK了
    ProxyPassReverse / http://192.168.8.191:8091/
    # Gerrit反向代理转发端口,应该与ProxyPass一致

</VirtualHost>

备注:192.168.8.191是我Ubuntu虚拟机在局域网的IP地址(使用ifconfig查询,修改为自己的实际地址)

5.2 文件apache2.conf末尾添加一行配置信息

sudo vim /etc/apache2/apache2.conf
.........
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.

# Include generic snippets of statements
IncludeOptional conf-enabled/*.conf

# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

#添加这行代码
Include httpd.conf

5.3 文件ports.conf新增一行配置信息

sudo vim /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

<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>

Listen 8081
#这里的8081端口号是上面配置的Apache2反射端口

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

5.4 开启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

六、安装gerrit

本教使用的gerrit版本是gerrit-3.2.3.war
备注:其他版本gerrit下载连接可参考https://www.gerritcodereview.com

6.1 进入gerrit安装包目录

本教材gerrit-3.2.3.war安装包的放置路径为/home/gerrit/download,读者可根据自己的实际路径操作

gerrit@100ask:~/download$ ls
gerrit-3.2.3.war
cd home/gerrit/download

6.2 解压安装gerrit-3.2.3.war安装包

java -jar gerrit-3.2.3.war init -d ~/review_site

6.3 配置gerrit.config文件

sudo vim /home/gerrit/review_site/etc/gerrit.config
[gerrit]
        basePath = git
        canonicalWebUrl = http://192.168.8.191:8081/
        serverId = 912a98d4-5e24-49f1-a7fe-912bc0bb4fa8
[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
[index]
        type = lucene
[auth]
        type = HTTP
[receive]
        enableSignedPush = false
[sendemail]
        smtpServer = localhost
[sshd]
        listenAddress = *:29418
[httpd]
        listenUrl = proxy-http://*:8091/
[cache]
        directory = cache
[gitweb]
    type = gitweb
    cgi = /usr/lib/cgi-bin/gitweb.cgi

6.4 新增管理员账号

//这个文件就是上面Apache配置的账号路径
touch /home/gerrit/review_site/passwords 
//新增账号admin和密码
sudo htpasswd -b /home/gerrit/review_site/passwords admin admin 

七、安装Gitweb

7.1 下载gitweb

sudo apt-get install gitweb

7.2 查看配置文件信息

dpkg -L gitweb

正确输入如下:

gerrit@100ask:~$ dpkg -L gitweb
/.
/etc
/etc/apache2
/etc/apache2/conf-available
/etc/apache2/conf-available/gitweb.conf
/etc/gitweb.conf
/usr
/usr/lib
/usr/lib/cgi-bin
/usr/share
/usr/share/doc
/usr/share/doc/gitweb
/usr/share/doc/gitweb/NEWS.Debian.gz
/usr/share/doc/gitweb/README
/usr/share/doc/gitweb/README.Debian
/usr/share/doc/gitweb/changelog.Debian.gz
/usr/share/doc/gitweb/changelog.gz
/usr/share/doc/gitweb/copyright
/usr/share/doc/gitweb/examples
/usr/share/doc/gitweb/examples/index.aux-generation
/usr/lib/cgi-bin/gitweb.cgi
gerrit@100ask:~$

八、重启Apache2和Gerrit

sudo /home/gerrit/review_site/bin/gerrit.sh restart
sudo /etc/init.d/apache2 restart

大功告成!

附录:Gerrit3.2.3启动效果
(以我自己的Ubuntu为例,浏览器输入:http://192.168.8.191:8081/)
在这里插入图片描述
至此Gerrit部署完毕,各位看官可以正式开始自己的代码管理之旅了,谢谢阅读,欢迎大家点赞关注!

参考文章:
https://blog.csdn.net/ducklikejava/article/details/80314617
https://www.jianshu.com/p/8f18964b8a47
https://www.jianshu.com/p/0593d888b2fe

备注:上述参考文章中有部分笔误,本文在此基础上进行了修改,感谢作者“一只胖胖胖胖猿baochuquan

  • 6
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值