Ubuntu下部署gerrit+报错分析(超详细)

本文详细描述了如何在Ubuntu系统上部署Gerrit代码审查平台,包括安装MySQL、配置Gerrit、设置Apache和Nginx代理,以及解决常见配置问题,确保顺利启动并访问Gerritweb界面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Ubuntu下部署gerrit代码平台

之前安装过几次 最后都在Apache代理这里失败了,如下图,总是gerrit.config与Apache2.config配置有问题,后面换了使用ngnix代理,简单多了
在这里插入图片描述

  1. 安装Mysql、gerrit、jdk、git
    这一步也是非必须得,也可以使用默认H2数据库,大型公司还是建议使用Mysql这种统一。使用apt直接安装mysql
    apt-get install git
	apt-get install mysql-server
	mysql_secure_installation
	systemctl status mysql.service
	mysqladmin -p -u root version 
	#登录mysql 创建用户与密码  刷新
	mysql -p
	CREATE USER 'gerrit'@'localhost' IDENTIFIED BY 'gerrit123';
	create database reviewdb;
	GRANT ALL ON reviewdb.* TO 'gerrit'@'localhost';
	FLUSH PRIVILEGES;
	#创建存储数据表
	CREATE TABLE account_group_by_id_aud(added_by INT DEFAULT 0 NOT NULL,removed_by INT,removed_on TIMESTAMP NULL DEFAULT NULL,group_id INT DEFAULT 0 NOT NULL,include_uuid VARCHAR(255) BINARY DEFAULT '' NOT NULL,added_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,PRIMARY KEY(group_id,include_uuid,added_on));

    CREATE TABLE account_group_members_audit (added_by INT DEFAULT 0 NOT NULL, removed_by INT,removed_on TIMESTAMP NULL DEFAULT NULL, account_id INT DEFAULT 0 NOT NULL, group_id INT DEFAULT 0 NOT NULL,added_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(account_id,group_id,added_on));

	CREATE TABLE changes(change_key VARCHAR(60) BINARY DEFAULT '' NOT NULL,created_on TIMESTAMP NOT NULL,last_updated_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,owner_account_id INT DEFAULT 0 NOT NULL,dest_project_name VARCHAR(255) BINARY DEFAULT '' NOT NULL, dest_branch_name VARCHAR(255) BINARY DEFAULT '' NOT NULL,status CHAR(1) DEFAULT '' NOT NULL,current_patch_set_id INT DEFAULT 0 NOT NULL,subject VARCHAR(255) BINARY
DEFAULT '' NOT NULL,topic VARCHAR(255) BINARY, original_subject VARCHAR(255) BINARY, submission_id VARCHAR(255) BINARY, note_db_state TEXT,row_version INT DEFAULT 0 NOT NULL,change_id INT DEFAULT 0 NOT NULL,PRIMARY KEY(change_id));
	#安装gerritweb
	sudo apt-get install gitweb
	sudo apt-get install git-review
	#下载gerrit
	#之前下载了gerrit-3.9.3.war 在java -jar部署的时候提示我的jdk版本不兼容。我的Ubuntu安装的jdk是jdk 11,后面换了一个更低的版本gerrit-3.4.1.war才ok。这里提供两个低版本下载地址
	 wget https://gerrit-releases.storage.googleapis.com/gerrit-3.1.3.war
     wget https://gerrit-releases.storage.googleapis.com/gerrit-3.4.1.war
	#运行gerrit war包
	sudo java -jar gerrit*.war init
	#安装的选项  注意这个type = HTTP
	[gerrit]
	basePath = git
	canonicalWebUrl = http://192.168.1.100
	serverId = c2681fe1-2f8f-4da4-b074-8e23f6dfe942
[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 = root
	javaHome = /usr/lib/jvm/java-11-openjdk-amd64
[database]
    type = mysql
    hostname = localhost
    database = reviewdb
    username = gerrit
[index]
	type = lucene
[auth]
	type = HTTP
[receive]
	enableSignedPush = false
[sendemail]
	smtpServer = localhost
[sshd]
	listenAddress = *:29418
[httpd]
	listenUrl = proxy-http://*:8081/
[cache]
directory = cache
	#利用lucene创建索引
    sudo java -jar gerrit-3.4.1.war reindex
    #启动gerrit   
    #进入到bin目录  执行启动脚本
    cd /opt/gerrit/bin
    ./gerrit.sh start  #启动脚本
    ./gerrit.sh stop   #停止
    ./gerrit.sh restart  #重启
    #root@ubuntu20:~# cd /opt/gerrit/bin/
	#root@ubuntu20:/opt/gerrit/bin# ./gerrit.sh restart
	#Stopping Gerrit Code Review: OK
	#Starting Gerrit Code Review: OK
	#ok 证明gerrit已经启动成功,但是当我们使用ip访问 页面报错 如开头web报错,这种是因为没有配置代理或者gerrit.config配置问题

在这里插入图片描述
在这里插入描述
二、安装代理
Apache代理坑有点多,搞了好久,还是有问题。我哩个豆
配置如下 启动apache服务报错

<VirtualHost *:80>
    ServerName 192.168.1.100
 
    ProxyRequests Off
    ProxyVia Off
    ProxyPreserveHost On
    <Proxy *>
          Order deny,allow
          Allow from all
    </Proxy>
    <Location '/login/'>
      AuthType Basic
      AuthName "Gerrit Code Review"
      Require admin
      AuthBasicProvider file
       # gerrit.assword就是你创建的登录用户、密码存储的地方 创建命令如下
       # htpasswd -c /opt/gerrit/etc/gerrit.password admin 
       # htpasswd -m /opt/gerrit/etc/gerrit.password zyp
      AuthUserFile  /opt/gerrit/etc/gerrit.password 
    </Location>
    AllowEncodedSlashes On
    ProxyPass / http://192.168.1.100:8081/
 
</VirtualHost>

gerrit.config配置文件:

[gerrit]
	basePath = git
	canonicalWebUrl = http://192.168.1.100:8081
	serverId = c2681fe1-2f8f-4da4-b074-8e23f6dfe942
[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 = root
	javaHome = /usr/lib/jvm/java-11-openjdk-amd64
[database]
  type = mysql
  hostname = localhost
  database = reviewdb
  username = gerrit
[index]
	type = lucene
[auth]
	type = HTTP
[receive]
	enableSignedPush = false
[sendemail]
	smtpServer = localhost
[sshd]
	listenAddress = *:29418
[httpd]
	listenUrl = proxy-http://192.168.1.100:8081/
[cache]
	directory = cache

报错截图如下 百度了下 说需要 在配置文件加下面三行 加了之后不报Invalid command ‘ProxyRequests’, perhaps misspelled or defined by a module not includ>这个错误,报另一个load加载下面这三行错误。草,哥放弃 用nginx代理

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_http2_module modules/mod_proxy_http2.so

在这里插入图片描述

Nginx代理

nginx安装看这里:https://www.cnblogs.com/taiyonghai/p/6728707.html

cd /etc/nginx/
vim nginx.config
#http标签添加下面的配置
server {
       listen 80;
       server_name 192.168.1.100;
       allow all;
       deny all;

       auth_basic "Welcome to Gerrit Code Review Site!";
       # **gerrit.assword就是你创建的登录用户、密码存储的地方**
       htpasswd -c /opt/gerrit/etc/gerrit.password admin 
       htpasswd -m /opt/gerrit/etc/gerrit.password zyp
       # gerrit.assword内容如下
       # admin:$apr1$yfDrZyx7$oLljjjMhseobpsGm5PiDU1
       # zyp:$apr1$QmHYzxYL$k5vUEyn02ZFyDyKaWz.or/

       auth_basic_user_file /opt/gerrit/etc/gerrit.password;


       location / {
         proxy_pass http://192.168.1.100:8081;
         proxy_set_header X-Forwarded-For $remote_addr;
         proxy_set_header Host $host;
      }
  }

启动nginx

启动
[root@localhost ~]# /usr/local/nginx/sbin/nginx
停止/重启
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s stop(quit、reload)
命令帮助
[root@localhost ~]# /usr/local/nginx/sbin/nginx -h
验证配置文件
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
配置文件
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf

确认gerrit.config与nginx.config文件无误,启动nginx与gerrit

/usr/local/nginx/sbin/nginx -s reload
cd /opt/gerrit/bin/
./gerrit.sh restart

浏览器 http://192.168.1.100:80或者8081端口 访问成功
在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值