一台服务器上运行多个Gerrit服务

前端之家收集整理的这篇文章主要介绍了一台服务器上运行多个Gerrit服务前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
系统:Ubuntu 15.5

http://www.jb51.cc/article/p-uoetwqvn-gc.html

至于如何在Ubuntu上搭建Gerrit代码审核服务,基本操作网上都有;由于需要在一台服务器运行多个Gerrit服务,就把自己的搭建笔记记录下。流程及结果图示:

1、Java环境配置

配置环境变量而已,比如JDK安装在/usr/jdk_1_7/目录下,则配置可如下:

export JAVA_HOME=/usr/jdk_1_7/jdk1.7.0_80
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

2、Gerrit安装

我为运行的两个Gerrit服务建立了各自独立的用户,以user1为例:

[current user]$ su <-- 切换到root
[root]# adduser user1 <-- 创建user1
[current user]$ su user1 <-- 切换到user1,然后进入home目录/home/user1
[user1]$ java -jar gerrit-x-x.war init -d review_site <-- 安装,文件在~/review_site/目录

3、安装Apache2

4、配置user1下的gerrit运行环境:代理端口8081

[user1]$ cat /home/user1/review_site/etc/gerrit.config
[gerrit]
	basePath = git
	canonicalWebUrl = http://192.168.1.99:8081/gerrit
[database]
	type = h2
	database = db/ReviewDB
[index]
	type = LUCENE
[auth]
	type = HTTP
[sendemail]
	enable = true
        smtpServer = smtp.example.qq.com <-- 腾讯企业邮箱
        smtpServerPort = 465
        smtpEncryption = ssl
        smtpUser = xxxx@xxx.com
        smtpPass = ********
        sslVerify = false
        from = Code Review < xxxx@xxxx.com >
[container]
	user = user1
	javaHome = /usr/lib/jvm/java-7-openjdk-amd64/jre
[sshd]
	listenAddress = *:29418 <-- 多个Gerrit运行,记得该值不能重复
[httpd]
	listenUrl = proxy-http://*:8081/gerrit
[cache]
	directory = cache


5、配置user2下的gerrit运行环境:代理端口8091

[user2]$ cat /home/user2/review_site/etc/gerrit.config
[gerrit]
	basePath = git
	canonicalWebUrl = http://192.168.1.99:8091/gerrit2
[database]
	type = h2
	database = db/ReviewDB
[index]
	type = LUCENE
[auth]
	type = HTTP
[sendemail]
	enable = true
	smtpServer = smtp.example.qq.com <-- 腾讯企业邮箱
	smtpServerPort = 465
	smtpEncryption = ssl
	smtpUser = xxxx@xxx.com
	smtpPass = ********
	sslVerify = false
	from = Code Review < xxxx@xxxx.com >
[container]
	user = user2
	javaHome = /usr/lib/jvm/java-7-openjdk-amd64/jre
[sshd]
	listenAddress = *:39418 <-- 多个Gerrit运行,记得该值不能重复
[httpd]
	listenUrl = proxy-http://*:8091/gerrit2
[cache]
	directory = cache

6、Apache配置

  • 代理配置:

[root]# vi /etc/apache2/mods-enabled/proxy.conf
<IfModule mod_proxy.c>
	<VirtualHost 192.168.1.99:80> # for Gerrit on user1
		ServerName 192.168.1.99
		ProxyRequests Off
		ProxyVia Off
		ProxyPreserveHost On
		<Proxy *:80>
			Order deny,allow
			Allow from all
		</Proxy>
		<Location /gerrit/login/>
	  		AuthType Basic
	  		AuthName "Gerrit Code Review"
	  		Require valid-user
	  		AuthUserFile /home/user1/review_site/etc/gerrit.passwd
		</Location>
		AllowEncodedSlashes On # 浏览器访问http://192.168.1.99:80/gerrit/将会
		                       # 转到http://192.168.1.99:8081/gerrit/
		ProxyPass /gerrit/ http://192.168.1.99:8081/gerrit/
	</VirtualHost>

	<VirtualHost *:8090> # for Gerrit on user2
		ServerName 192.168.1.99
		ProxyRequests Off
		ProxyVia Off
		ProxyPreserveHost On
		<Proxy *:8090>
			Order deny,allow
			Allow from all
		</Proxy>
		<Location /gerrit2/login/>
	  		AuthType Basic
	  		AuthName "Gerrit Code Review"
	  		Require valid-user
	  		AuthUserFile /home/user2/review_site/etc/gerrit.passwd
		</Location>
		AllowEncodedSlashes On
		ProxyPass /gerrit2/ http://192.168.1.99:8091/gerrit2/
	</VirtualHost>
</IfModule>

  • 端口监听配置:

[root]# vi /etc/apache2/ports.conf
NameVirtualHost *:80
NameVirtualHost *:8090

Listen 80 # listen on port 80 for Gerrit on user1
Listen 8090 # listen on port 8090 for Gerrit on user2


<IfModule ssl_module>
	Listen 443
</IfModule>

<IfModule mod_gnutls.c>
	Listen 443
</IfModule>

7、运行服务

  • 重启Apache:

[root]# /etc/init.d/apache2 restart

  • 创建账户密码:

# Gerrit on user1
touch /home/user1/review_site/etc/gerrit.passwd
htpasswd -m /home/user1/review_site/etc/gerrit.passwd admin
提示输入秘密

# Gerrit on user2
touch /home/user2/review_site/etc/gerrit.passwd
htpasswd -m /home/user2/review_site/etc/gerrit.passwd admin


  • 重启Gerrit在user1:

[user1]$ ./review_site/bin/gerrit.sh restart

  • 重启Gerrit在user2:

[user2]$ ./review_site/bin/gerrit.sh restart

  • 访问:

http://192.168.1.99:80/gerrit/ <-- Gerrit on user1
http://192.168.1.99:8090/gerrit2/ <-- Gerrit on user2
原文链接:https://www.f2er.com/ubuntu/354925.html

猜你在找的Ubuntu相关文章