Ubuntu下搭建基於apache2的gerrit+gitweb服務器


說明:Ubuntu版本12.04

 

1. 配置gerrit管理帳號

sudo adduser gerrit

  增加sudo權限:

sudo usermod -a -G sudo gerrit

  切換到gerrit賬號:

sudo su gerrit

 

 

2. 安裝java

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-7-jdk

 

 

3. 安裝git

sudo apt-get install git

 

 

4. 安裝配置apache2

sudo apt-get install apache2

修改配置文件:

sudo vi /etc/apache2/httpd.conf

具體內容如下:

<VirtualHost *:8081>
    
    ServerName 192.168.130.10

    ProxyRequests Off
    ProxyVia Off
    ProxyPreserveHost On

    <Proxy *>
          Order deny,allow
          Allow from all
    </Proxy>

    <Location "/login/">
        AuthType Basic
        AuthName "Gerrit Code Review"
        Require valid-user
        AuthBasicProvider file
        AuthUserFile /home/gerrit/review_site/passwords
    </Location>

    AllowEncodedSlashes On
   
    ProxyPass / http://127.0.0.1:8091/ nocanon

</VirtualHost>

注:如httpd.conf沒有Include到apache2.conf中,需手動添加:

sudo vi /etc/apache2/apache2.conf

添加,

Include httpd.conf

 

修改配置文件,添加對8081端口的監聽:

sudo vi /etc/apache2/ports.conf

添加,

Listen 8081

 

開啟SSL、Proxy、Rewrite等模塊:

cd /etc/apache2/mods-enabled/

 

sudo ln -s ../mods-available/proxy.load
sudo ln -s ../mods-available/proxy.conf
sudo ln -s ../mods-available/proxy_http.load
sudo ln -s ../mods-available/proxy_balancer.conf
sudo ln -s ../mods-available/proxy_balancer.load
sudo ln -s ../mods-available/rewrite.load
sudo ln -s ../mods-available/ssl.conf
sudo ln -s ../mods-available/ssl.load
sudo ln -s ../mods-available/slotmem_shm.load
sudo ln -s ../mods-available/socache_shmcb.load

 

 

5. 安裝配置gerrit

本文用的版本是gerrit-2.13.6。
安裝:
java -jar gerrit-2.13.6.war init -d ~/review_site

 

安裝配置先選擇默認配置,安裝完成后再來修改配置文件:

vi ~/review_site/etc/gerrit.config

具體內容如下:

[gerrit]
        basePath = git
        serverId = 02481fa0-9b63-4b6a-9869-8b4e2a4364ee
        canonicalWebUrl = http://192.168.130.10:8081/
[database]
        type = h2
        database = /home/gerrit/review_site/db/ReviewDB
[auth]
        type = HTTP
[receive]
        enableSignedPush = false
[sendemail]
        smtpServer = smtp.company.com 
        smtpServerPort = ***
        smtpEncryption = ssl  
        smtpUser = user@company.com 
        smtpPass = ****** 
        sslVerify = false  
        from = Code Review < gerrit@company.com > 
[container]
        user = gerrit
        javaHome = /usr/lib/jvm/java-7-openjdk-amd64/jre
[sshd]
        listenAddress = *:29418
[httpd]
        listenUrl = proxy-http://*:8091/
[cache]
        directory = cache
 
接下來,配置gerrit賬戶:
 
touch ~/review_site/passwords
sudo htpasswd -b ~/review_site/passwords admin 123123

 

 

6. 安裝配置gitweb

sudo apt-get install gitweb

查看相關配置文件安裝路徑:

dpkg -L gitweb

得到輸出如下:

/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/gitweb
/usr/share/doc/gitweb/examples
/usr/share/doc/gitweb/examples/index.aux-generation
/usr/share/doc/gitweb/README.Debian
/usr/share/doc/gitweb/copyright
/usr/share/doc/gitweb/README
/usr/share/doc/gitweb/NEWS.Debian.gz
/usr/lib
/usr/lib/cgi-bin
/etc
/etc/apache2
/etc/apache2/conf.d
/etc/apache2/conf.d/gitweb
/etc/gitweb.conf
/usr/share/doc/gitweb/changelog.Debian.gz
/usr/lib/cgi-bin/gitweb.cgi

根據上面的地址在gerrit.conf中添加如下配置:

[gitweb]
    type = gitweb
    cgi = /usr/lib/cgi-bin/gitweb.cgi

相關說明:

gitweb集成gerrit后,默認只有管理員用戶才能查看gitweb超鏈接,普通用打開鏈接后頁面顯示Not Found。如果想給普通的用戶查看gitweb超鏈接的權限,則必須對項目設置refs/meta/config 的read權限。而這個權限在All-Projects的ACL里只對Administrators用戶和Project Owners開放。

 

 

7. 重啟gerrit和apache2

sudo ~/review_site/bin/gerrit.sh restart
sudo /etc/init.d/apache2 restart

 

 

8. 訪問gerrit 管理界面

瀏覽器輸入:

http://192.168.130.10:8081/

在彈出框輸入htpasswd命令設置的賬號密碼即可。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM