条件:centos系统、gerrit2.12.war
搭建步骤:
1.新建mysql数据库gerrit。
语句如下:
create Database gerrit ;//建库
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON gerrit.* TO gerrit@localhost IDENTIFIED BY 'Gerrit@123';//建用户、授权限
FLUSH PRIVILEGES;//即时生效
2.搭建gerrit服务
java -jar gerrit-2.12.war init -d review //"review "为搭建的目录
搭建完成配置文件为:
[gerrit] basePath = /home/gerrit/git canonicalWebUrl = http://gerrit.wenbin.com [database] type = mysql hostname = localhost port = 3306 database = gerrit username = gerrit [index] type = LUCENE [auth] type = HTTP [receive] enableSignedPush = false [sendemail] smtpServer = smtp.163.com smtpServerPort = 25 smtpUser = guoquanxiangnba@163.com from = CodeReview<guoquanxiangnba@163.com> [container] user = gerrit javaHome = /opt/jdk1.8.0_191/jre [sshd] listenAddress = *:29419 [httpd] listenUrl = proxy-http://127.0.0.1:8081/ [cache] directory = cache
安装时数据库操作捣乱了不少,各种连不上。
3.nginx安装配置
yum install nginx;
新建http认证文件。
htpasswd -c /passwords admin执行后输入amdin密码。
配置nginx.conf文件,路径为/etc/nginx;
配置最终为
include /etc/nginx/conf.d/*.conf;
server { listen 8083 default_server; server_name gerrit.wenbin.com; root /usr/share/nginx/html;
# Load configuration files for the default server block. include /etc/nginx/default.d/*.conf;
location / { auth_basic "Gerrit Code Review"; auth_basic_user_file /passwords; proxy_pass http://127.0.0.1:8081; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $host; }
error_page 404 /404.html; location = /40x.html { }
error_page 500 502 503 504 /50x.html; location = /50x.html { } } 然后执行 systemctl restart nginx,启动nginx服务。
4.安装httpd服务,进行配置。
yum install httpd;
配置httpd.conf文件,路径为/etc/httpd/conf;
配置完成为:
# Load config files in the "/etc/httpd/conf.d" directory, if any. IncludeOptional conf.d/*.conf <VirtualHost *:80> ProxyRequests Off ProxyVia Off ProxyPreserveHost On <Proxy *> Order deny,allow Allow from all </Proxy> <Location /> AuthType Basic AuthName "Gerrit Code Review" Require valid-user AuthUserFile /passwords </Location>
AllowEncodedSlashes On ProxyPass /r/ http://127.0.0.1:8081/r/ nocanon </VirtualHost> 然后执行 systemctl restart httpd,启动httpd服务。
打开浏览器,输入IP:端口号就可以登录了;
遇到的问题:
1.安装gerrit起不来,经验证是mysql的问题,如遇到问题自行百度。
2.nginx和httpd配置了同一个端口:80,导致只能起来一个,改掉一个端口即可。
3.打开gerrit报错,The page you requested was not found, or you do not have permission to view
解决方案:
在httpd服务的配置文件里面加入
正常打开。