gerrit服务端安装-linux(centos)

来源:互联网 发布:淘宝店铺html模板 编辑:程序博客网 时间:2024/06/03 22:44

操作系统:CentOS
操作系统版本:7.2.1511
操作系统位数:64位

一、创建gerrit用户
查看是否有gerrit用户: id gerrit
创建git的组: groupadd gerrit
新增git用户: adduser -g gerrit gerrit
验证是否创建成功:
用户列表: cat /etc/passwd
用户组列表: cat /etc/group
查看系统中有哪些用户: cut -d : -f 1 /etc/passwd
给用户设置密码: passwd gerrit

二、搭建java环境
1、下载jdk并解压
创建目录: mkdir /data/java/
去到目录: cd /data/java/
下载jdk:

wget http://download.oracle.com/otn-pub/java/jdk/8u121-b13/e9e7ea248e2c4826b92b3f075a80e441/jdk-8u121-linux-x64.tar.gz

或者通过链接:
http://www.oracle.com/technetwork/java/javase/overview/index.html下载后上传到该目录
解压文件: tar zxvf jdk-8u121-linux-x64.tar.gz
得到jdk的目录为: /data/java/jdk1.8.0_121

3、编辑配置文件,配置环境变量
查看配置文件: vi /etc/profile
添加如下内容:JAVA_HOME根据实际目录来

JAVA_HOME=/data/java/jdk1.8.0_121CLASSPATH=$JAVA_HOME/lib/PATH=$PATH:$JAVA_HOME/binexport PATH JAVA_HOME CLASSPATH

4、让配置生效
source /etc/profile

5、检查是否安装成功
输入:java -version
如果出现以下,代表安装成功

三、安装gerrit
1、下载gerrit
去到gerrit目录: cd /home/gerrit
下载gerrit: wget https://gerrit-releases.storage.googleapis.com/gerrit-2.11.war
查看是否下载成功: ls

2、安装gerrit
去到/home/gerrit目录: cd /home/gerrit
安装gerrit: java -jar gerrit-2.11.war init -d review_site
授权文件夹权限给gerrit用户: chown -R gerrit:gerrit review_site
一直按回车,之后再修改配置文件

验证是否安装成功:http://182.92.1.1:8080

四、安装apache
1、安装前准备
检查是否已经安装了下载工具wget和编译环境gcc、make、gcc-c++:
rpm -qa|grep -e wget -e ^gcc -e make

2、安装gcc和gcc-c++
安装gcc: yum install -y gcc
安装c++: yum install -y gcc-c++
验证gcc是否安装成功: gcc –version

3、安装APR
相关链接: http://apr.apache.org
去到该目录: cd /usr/local/src
下载安装包: wget http://mirrors.hust.edu.cn/apache//apr/apr-1.5.2.tar.gz
解压安装包: tar -zxf apr-1.5.2.tar.gz
去到安装文件夹中: cd /usr/local/src/apr-1.5.2
编译: ./configure
安装: make && make install

4、安装APR-Util
相关链接:http://apr.apache.org
去到该目录: cd /usr/local/src
下载安装包: wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.4.tar.gz
解压安装包: tar -zxf apr-util-1.5.4.tar.gz
去到安装文件夹中: cd /usr/local/src/apr-util-1.5.4
编译: ./configure –with-apr=/usr/local/apr/bin/apr-1-config
安装: make && make install

5、安装PCRE
下载链接:http://www.pcre.org
去到该目录: cd /usr/local/src
下载安装包: wget https://ftp.pcre.org/pub/pcre/pcre-8.37.tar.gz
解压安装包: tar -zxf pcre-8.37.tar.gz
**去到安装文件夹中:**cd pcre-8.37
编译: ./configure –prefix=/usr/local/pcre
安装: make && make install

6、安装apache
去到该目录: cd /usr/local/src
下载安装包: wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.25.tar.gz
解压安装包: tar -zxf httpd-2.4.25.tar.gz
去到安装文件夹中: cd /usr/local/src/httpd-2.4.25
编译: ./configure –prefix=/usr/local/apache –enable-so –enable-rewrite –with-apr=/usr/local/apr/bin/apr-1-config –with-apr-util=/usr/local/apr/bin/apu-1-config –with-pcre=/usr/local/pcre
安装: make && make install

7、修改servername
vi /usr/local/apache/conf/httpd.conf
ServerName localhost:80

8、启动apache
启动:/usr/local/apache/bin/httpd -k start
停止:/usr/local/apache/bin/httpd -k stop
或者
启动:/usr/local/apache/bin/apachectl start
停止:/usr/local/apache/bin/apachectl stop
验证是否安装成功:http://182.92.1.1
出现It works!代表安装成功

五、配置gerrit
1、创建密码文件
去到gerrit的安装目录:cd /home/gerrit/review_site/etc
创建密码文件:touch passwd
授权文件权限给gerrit用户:chown -R gerrit:gerrit passwd
将passwd文件变为可执行:chmod -R o+x passwd
生成密码:cd /usr/local/apache/bin/
生成密码:./htpasswd -b /home/gerrit/review_site/etc/passwd test 1234

2、配置反向代理
去到apache的配置文件目录:cd /usr/local/apache/conf
修改配置文件:vi httpd.conf
a、放开两行注释:

LoadModule proxy_module modules/mod_proxy.soLoadModule proxy_http_module modules/mod_proxy_http.so

b、在Listen 80下方添加如下内容

<VirtualHost *:80>ProxyRequests OffProxyVia OffProxyPreserveHost On<Proxy *>Order deny,allowAllow from all</Proxy><Location /login/>AuthType BasicAuthName "Gerrit Code Review"Require valid-userAuthUserFile /home/gerrit/review_site/etc/passwd</Location>ProxyPass / http://182.92.1.1:8080/</VirtualHost>

重启apache:
停止:/usr/local/apache/bin/httpd -k stop
启动:/usr/local/apache/bin/httpd -k start
查看apache是否启动成功:ps -ef|grep httpd

3、修改gerrit的配置文件
去到gerrit目录:cd /home/gerrit/review_site/etc
修改配置文件:vi /home/gerrit/review_site/etc/gerrit.config

[gerrit]basePath = gitcanonicalWebUrl = http://182.92.1.1:8080/[database]type = h2database = db/ReviewDB[index]type = LUCENE[auth]type = http[sendemail]smtpServer = smtp.163.comsmtpUser = test@163.comfrom = test@163.comsmtpPass = test[container]user = rootjavaHome = /data/java/jdk1.8.0_121/jre[sshd]listenAddress = *:29418[httpd]listenUrl = proxy-http://182.92.1.1:8080/[cache]directory = cache

4、重启gerrit服务:
去到gerrit目录:cd /home/gerrit/review_site/bin
启动:./gerrit.sh start
停止:./gerrit.sh stop
重启:./gerrit.sh restart

5、验证http认证是否生效
访问:182.92.1.1
输入用户名:test
输入密码:1234

6、查看apache日志用于排错
cd /usr/local/apache/logs
tail -f error_log

错误1:
出现这个错误时的解决方案:
[Sun Feb 12 23:03:48.582902 2017] [authn_file:error] [pid 13746:tid 139765264844544] (13)Permission denied: [client 14.127.233.169:63306] AH01620: Could not open password file: /home/gerrit/review_site/etc/passwd, referer: http://182.92.1.1/
将gerrit文件夹变为可执行:
cd /home
chmod -R o+x gerrit

7、安装gitweb
yum install gitweb

8、通过git config配置一下
查找gitweb.cgi的路径:find -name gitweb.cgi
我的路径为:/var/www/git/gitweb.cgi
git config –file /home/gerrit/review_site/etc/gerrit.config gitweb.cgi /var/www/git/gitweb.cgi
git config –file /home/gerrit/review_site/etc/gerrit.config –unset gitweb.url

注释:
git config –file /home/gerrit/review_site/etc/gerrit.config gitweb.cgi gitwebpath/gitweb.cgigitconfigfile/home/gerrit/reviewsite/etc/gerrit.configunsetgitweb.url:/gerritserver/reviewsitesgerritgitweb_path变量为gitweb安装目录,可以用“find - name gitweb.cgi”命令找到路径】

9、重启gerrit服务,使得gitweb生效
去到gerrit目录:cd /home/gerrit/review_site/bin
重启:./gerrit.sh restart

10、权限FAQ
在gerrit集成gitweb之后,发现只有我的root用户(gerrit里注册的第一个用户)才能够点gitweb链接正常打开gitweb页面。其他的普通用户点gitweb链接显示404错误,
解决:为项目的用户组增加了对refs/meta/config的read权限,即在read标签中加入注册的用户组即可

1 0
原创粉丝点击