gerrit_0">Ubuntu下部署gerrit代码平台
之前安装过几次 最后都在Apache代理这里失败了,如下图,总是gerrit.config与Apache2.config配置有问题,后面换了使用ngnix代理,简单多了
- 安装Mysql、gerrit、jdk、git
这一步也是非必须得,也可以使用默认H2数据库,大型公司还是建议使用Mysql这种统一。使用apt直接安装mysql
apt-get install gitapt-get install mysql-servermysql_secure_installationsystemctl status mysql.servicemysqladmin -p -u root version #登录mysql 创建用户与密码 刷新mysql -pCREATE 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));#安装gerritwebsudo apt-get install gitwebsudo 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.warwget https://gerrit-releases.storage.googleapis.com/gerrit-3.4.1.war#运行gerrit war包sudo java -jar gerrit*.war init#安装的选项 注意这个type = HTTP[gerrit]basePath = gitcanonicalWebUrl = http://192.168.1.100serverId = 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 = rootjavaHome = /usr/lib/jvm/java-11-openjdk-amd64
[database]type = mysqlhostname = localhostdatabase = reviewdbusername = 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.100ProxyRequests OffProxyVia OffProxyPreserveHost On<Proxy *>Order deny,allowAllow from all</Proxy><Location '/login/'>AuthType BasicAuthName "Gerrit Code Review"Require adminAuthBasicProvider file# gerrit.assword就是你创建的登录用户、密码存储的地方 创建命令如下# htpasswd -c /opt/gerrit/etc/gerrit.password admin # htpasswd -m /opt/gerrit/etc/gerrit.password zypAuthUserFile /opt/gerrit/etc/gerrit.password </Location>AllowEncodedSlashes OnProxyPass / http://192.168.1.100:8081/</VirtualHost>
gerrit.config配置文件:
[gerrit]basePath = gitcanonicalWebUrl = http://192.168.1.100:8081serverId = 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 = rootjavaHome = /usr/lib/jvm/java-11-openjdk-amd64
[database]type = mysqlhostname = localhostdatabase = reviewdbusername = 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端口 访问成功