您的位置:首页 > 运维架构 > Apache

Gerrit+apache+H2数据库简单安装配置

2015-07-13 17:12 671 查看



Gerrit+apache+H2数据库简单安装配置

1、Ubuntu Gerrit 安装

Gerrit 是一个基于 Web 的代码评审和项目管理的工具,面向基于 Git 版本控制系统的项目。因此需要Apache、Mysql(暂使用H2)、GIT等相关软件的支持

安装Gerrit

1.1 创建一个新用户,以gerrit为例(如已创建可省)

$sudo adduser gerrit

以新用户身份操作

$sudo su - gerrit

1.2 创建安装目录,以项目名命令。(建议直接拷贝使用其它项目的gerrit安装目录)

$mkdir -p gerrit

1.3 下载gerrit
http://code.google.com/p/gerrit/downloads/list?can=1&q=&colspec=Filename+Summary+Uploaded+ReleaseDate+Size+DownloadCount
也可以直接在百度上搜索gerrit下载(最新版本是2.11)

1.4 安装并配置初始化gerrit

java -jar gerrit-2.11.war init -d gerrit/

Create '/home/gerrit/gerrit' [Y/n]?

*** Git Repositories

***

Location of Git repositories [git]:

*** SQL Database

***

Database server type [H2/?]: //可以改成MYSQL或者使用H2

*** User Authentication

***

Authentication method [OPENID/?]: HTTP //注意这个不要按回车跳过去了,否则不是HTTP认证,是需要用google的OPENID

Get username from custom HTTP header [y/N]? :

SSO logout URL :

*** Email Delivery

***

SMTP server hostname [localhost]: smtp.exmail.qq.com //自己改成自己的邮箱smtp

SMTP server port [(default)]:465

SMTP encryption [NONE/?]:ssl

SMTP username [?]: yourname@company.com //自己改成自己的邮箱,比如victor.yuan@cloudminds.com

yourname@xxxxx.com's password :

confirm password :

*** Container Process

***

Run as [project]:

Java runtime [/usr/lib/jvm/java-6-sun-1.6.0.24/jre]:

Copy gerrit.war to /home/gerrit/gerrit/bin/gerrit.war [Y/n]?

Copying gerrit.war to /home/gerrit/gerrit/bin/gerrit.war

*** SSH Daemon

***

Listen on address [*]:

Listen on port [29418]: //如果同一个用户下建多个gerrit,请不用都公用29418这个端口号 如39418 49418

Gerrit Code Review is not shipped with Bouncy Castle Crypto v144

If available, Gerrit can take advantage of features

in the library, but will also function without it.

Download and install it now [Y/n]?

Downloading http://www.bouncycastle.org/download/bcprov-jdk16-144.jar ... OK

Checksum bcprov-jdk16-144.jar OK

Generating SSH host key ... rsa... dsa... done

*** HTTP Daemon

***

Behind reverse proxy [y/N]? y //使用反向代理的话必须选择y来配置,默认是N

Proxy uses SSL (https://) [y/N]? n

Subdirectory on proxy server [/]: /project/ //可以选择直接跳过,那样你的gerrit最后的URL是http://192.168.0.107:80

Listen on address [*]:

Listen on port [8081]: //切记,此端口号一定不要和apache2占用相同的端口号,多个gerrit可以8082 8083 8084 , 否则就会Starting Gerrit Code Review:Failed

Canonical URL [http://*/]:http://192.168.0.107/project/ //上一步Subdirectory on proxy server 跳过不填则是http://192.168.0.107:80 (80为你将要在apache 给gerrit设置的端口)

Initialized /home/gerrit2/review-siteExecuting

/home/gerrit2/review-site/bin/gerrit.sh start

Starting Gerrit Code Review: OK

=========================================QA=======================================================================================

Q:Configuration ErrorCheck the HTTP server's authentication settings.The HTTP server did not provide the username in the Authorizationheader when it forwarded the request to Gerrit Code Review.If the HTTP server is Apache HTTPd, check the proxy configurationincludes
an authorization directive with the proper location, ensuringit ends with '/':

In error_log:ERROR com.google.gerrit.httpd.auth.container.HttpLoginServlet : Unableto authenticate user by Authorization request header. Check containeror server configuration.

A:You cannot run these on the same port. Your Apache NameVirtualHostshould be on a different port than the internal Jetty web sever thatGerrit is using.

即gerrit和apache2占用相同的端口号

例如:

cat gerrit/etc/gerrit.config:

[httpd] listenUrl = http://x.x.x.x:8081/
cat /etc/apache2/apache2.conf :

NameVirtualHost x.x.x.x:8081

<VirtualHost x.x.x.x:8081>

apache2和gerrit都使用了8081,肯定有一个启动不来的,一般是gerrit

1.5 按下面内容修改gerrit/etc/gerrit.conf 及GERRIT的配置文件

[gerrit]

basePath = git //指定被gerrit管理的所有git库存放位置,即gerrit/git/

canonicalWebUrl = http://192.168.0.107/project/ //指定web访问gerrit的网址//填自己的ip和端口号,勿完全抄

[database]

type = H2 //指定gerrit所默认数据库类型,可以选用mysql

database = db/ReviewDB

[auth]

type = HTTP //指定浏览器登录gerrit时的认证方式

[sendemail]

smtpServer = smtp.exmail.qq.com //指定smtp服务器地址

smtpUser = yourname@company.com

[container]

user = project //指定gerrit所在机器的用户身份与上文创建的用户对应一致

javaHome = /usr/lib/jvm/java-6-sun-1.6.0.24/jre //系统本身自带

[sshd]

listenAddress = *:29418 //指定sshd服务监听的端口号

[httpd]

listenUrl = proxy-http://127.0.0.1:8081/project/ //指定http代理地址

[cache]

directory = cache //缓存位置

2、配置Apache

$sudo apt-get install apache2 apache2-utils

2.1 创建编辑apache配置文件,添加如下内容(下面以Ubuntu系统为例请注意不同操作系统apache配置文件的区别)也可配置 apache2.conf httpd.conf,我们这里配置的是/etc/apache2/sites-available/gerrit.conf

$sudo vi /etc/apache2/sites-available/gerrit.conf

NameVirtualHost 192.168.0.107:80 //填自己的ip和端口号,勿完全抄

<VirtualHost 192.168.0.107:80> //填自己的ip和端口号,勿完全抄

ServerName 192.168.0.107

ProxyRequests Off

ProxyVia Off

ProxyPreserveHost On

<Proxy *>

Order deny,allow

Allow from all

</Proxy>

<Location "/project/login/">

AuthType Basic

AuthName "Gerrit Code Review"

Require valid-user

AuthUserFile /etc/apache2/passwords //指定http登录认证的的paassword文件所在位置,放哪都行,根据后来

//sudo htpasswd -cb /etc/apache2/passwords scm scm

</Location>

AllowEncodedSlashes On

RedirectMatch ^/project$ /project/

ProxyPass /project/ http://127.0.0.1:8081/project/
ProxyPassReverse /project/ http://127.0.0.1:8081/project/
</VirtualHost>

保存退出

$cd /etc/apache2/sites-enabled/

$sudo ln ../sites-available/gerrit.conf .

2.2 创建passwd文件,添加gerrit登录用户,-c参数为创建,仅限第一次添加用户时使用

$sudo htpasswd -cb /etc/apache2/passwords admin admin

第二次添加其他用户时,不要加-c了:

$sudo htpasswd -b /etc/apache2/passwords test test

2.3 配置apache2

$sudo vi /etc/apache2/http.conf //在文件中加入以下内容

ServerName localhost

$cd /etc/apache2/mods-enabled

$sudo ln -s /etc/apache2/mods-available/proxy.conf proxy.conf

$sudo ln -s /etc/apache2/mods-available/proxy.load proxy.load

$sudo ln -s /etc/apache2/mods-available/proxy_http.load proxy_http.load

2.3.1 配置apache2的监听端口:

/etc/apache2$sudo vi ports.conf

NameVirtualHost *:80

Listen 80

Listen 8080 //不要给gerrit!

Listen 8000 //不要给gerrit!

添加apache2的tcp端口号,切记不要把gerrit的,即

Listen on port [8081]: 不要输入上面配置给apache2的端口号,切记!!!

可以用sudo netstat -lnp | grep 80 查看相关80的所有端口使用情况

否则gerrit 起不来的

搭建多个gerrit 时Listen on port [8081]:可以用8082 8083 8084 等

2.4 Apache2 配置安装 FQA:

Q:启动apache报错

Syntax error on line 300 of /etc/apache2/apache2.conf:Invalid command 'ProxyPass', perhaps misspelled or defined by a module not included in the server configuration ...fail!

A:配置了反向代理,但是没有打开module,执行下面操作

cd /etc/apache2/mods-enabled

ln -s /etc/apache2/mods-available/proxy.conf proxy.conf

ln -s /etc/apache2/mods-available/proxy.load proxy.load

ln -s /etc/apache2/mods-available/proxy_http.load proxy_http.load

Q:启动Apache报错

No apache MPM package installed

A:安装apache2-mpm-worker软件包

$sudo apt-get install apache2-mpm-worker

Q:启动Apache报错

apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

A:修改/etc/apache2/http.conf文件,在文件中加入以下内容

ServerName localhost

Q:(13)Permission denied: make_sock: could not bind to address 0.0.0.0:80

A:需要用ROOT用户执行 直接 sudo /etc/init.d/apache2 restart 就OK了

启动服务

1.启动apache

sudo /etc/init.d/apache2 restart

2.启动gerrit服务

$review_site_project/bin/gerrit.sh start

gerrit服务自动启动

sudo ln -snf /home/gerrit/review_site/bin/gerrit.sh /etc/init.d/gerrit.sh

sduo ln -snf /etc/init.d/gerrit.sh /etc/rc2.d/S90gerrit

sduo ln -snf /etc/init.d/gerrit.sh /etc/rc3.d/S90gerrit

服务自动启动脚本/etc/init.d/gerrit.sh需要通过/etc/default/gerritcodereview文件来提供一些配置。该文件的内容为:

GERRIT_SITE=/home/gerrit/review_site

NO_START=0

登录gerrit

在浏览器地址栏中输入

192.168.0.107/project/

注:Subdirectory on proxy server [/]:选择直接跳过 则192.168.0.107:80

在显示的登录框中输入用户名/密码,

即之前配置passwords

$sudo htpasswd -cb /etc/apache2/passwords admin admin

admin

admin

Note: 请注意第一个登入的用户,Gerrit会自动将其定义为管理员
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: