使用Gitorious搭建私有代碼倉庫


 簡介

平時,我們會把開源的項目托管在Github上,但是在工作中,我們往往會需要一個私有的代碼倉庫。Bitbucket是一個不錯的選擇,這里我們將動手來搭建一個私有的代碼倉倉庫系統。 Gitorious 是一個基於 Git 版本控制系統的Web項目托管平台,使用 Ruby on Rails 開發。安裝和配置起來相對繁瑣,為了簡化工作量,這里介紹一種比較簡單的安裝方法,即采用bitnami提供的stack包。

 

Gitorious安裝和配置

     首先,這里選擇下載Linux平台的64位包,如需其他類型請訪問http://bitnami.org/stack/gitorious :

wget  http://downloads.bitnami.org/files/stacks/gitorious/2.4.5-1/bitnami-gitorious-2.4.5-1-linux-x64-installer.run  
chmod +x bitnami-gitorious-2.4.5-1-linux-x64-installer.run && ./bitnami-gitorious-2.4.5-1-linux-x64-installer.run

     

      接着進行一些交互的設置,最后確認后就會進行安裝:

----------------------------------------------------------------------------
Welcome to the BitNami Gitorious Stack Setup Wizard.
----------------------------------------------------------------------------
Installation folder
Please, choose a folder to install BitNami Gitorious Stack
Select a folder [/opt/gitorious-2.4.5-0]: 
----------------------------------------------------------------------------
Create Admin account
BitNami Gitorious Stack admin user creation
Login [user]: admin
Password :
Please confirm your password :
Your real name [User Name]: admin
Email Address [user@example.com]: yuxcer@gmail.com
----------------------------------------------------------------------------
Web Server Port
Please enter the port that the bundled Apache Server will listen to by default.
Apache Web Server Port [80]: 
----------------------------------------------------------------------------
Hostname that will be used to create internal URLs. If this value is incorrect , 
you may be unable to access your Gitorious installation from other computers. It 
is advisable to use a Domain instead of an IP address for compatibility with 
different browsers.
Domain [172.16.156.2]: git.test.com
Do you want to configure mail support? [y/N]: Y
----------------------------------------------------------------------------
Configure SMTP Settings
This is required so your application can send notifications via email.
Default email provider:
[1] GMail
[2] Custom
Please choose an option [1] : 1
----------------------------------------------------------------------------
Configure SMTP Settings
Default mail server configuration.
GMail address []: example@gmail.com                                               
GMail password :
Re-enter :
----------------------------------------------------------------------------
Setup is now ready to begin installing BitNami Gitorious Stack on your computer.
Do you want to continue? [Y/n]:

 

   這里需要提醒的幾點:

  •       Gitorious必須要使用domain name來訪問(至少chrome和Safari不行),直接使用ip會導致無法登陸的問題,這在官網文檔以及網上能找到一大堆這樣的問題。
  •       你填寫的用戶是admin用戶
  •       MySQL root密碼是你前面輸入的admin用戶的密碼
  •       如果要使用注冊功能,那么需要配置郵件服務器,否則就無法完成用戶注冊(因為要發送郵件)
  •       Gitorious的配置文件在apps目錄下
  •       備份直接對gitorious目錄進行拷貝即可,可以跨不同的distro使用,注意權限正確

      安裝完成之后,所有相關服務都已經啟動。如果要重啟服務,修改配置文件,切換到 Gitorious安裝目錄下,執行ctlscript.sh腳本用於對服務進行相關操作。

root@git:/opt/gitorious-2.4.5-1# ./ctlscript.sh

usage: ./ctlscript.sh help

       ./ctlscript.sh (start|stop|restart|status)

       ./ctlscript.sh (start|stop|restart|status) mysql

       ./ctlscript.sh (start|stop|restart|status) apache

       ./ctlscript.sh (start|stop|restart|status) activemq

       ./ctlscript.sh (start|stop|restart|status) gitorious

help       - this screen

start      - start the service(s)

stop       - stop  the service(s)

restart    - restart or start the service(s)

status     - show the status of the service(s)

        如果要修改apache、mysql等端口、路徑的配置,不僅要對properties.ini文件進行編輯,還需要對相應服務的目錄下的配置文件進行修改。要獲得更詳細的說明,請閱讀README.txt文件和bitnami的wiki說明。

Gitorious的使用

      Gitorious的使用和github類似,很快可以上手。這里簡要地介紹一下。使用前面創建的admin用戶登陸,默認會讓你添加一個ssh Public key。這個key是你用於提交代碼的公鑰。

產生密鑰對的方法如下:

ssh-keygen –C “yourname@email.com”

         然后確認路徑以及不對密鑰設置密碼,生成后將home目錄下的~/.ssh/id_rsa.pub文件中的內容添加到瀏覽器中,即可完成。用戶面板如下所示:

        這里提醒一下,關於創建project的問題。當你點擊Create a project的時候,project是一個倉庫容器的概念,例如,我們創建一個稱為Openstack的project,然后在里面創建nova, keystone, glance等repository。

        對於clone repository,gitorious支持主流的三種協議,git只讀,http明文,ssh需上傳ssh public key。其中HTTP和git://是支持匿名訪問的,因此必須要把它們禁用。

 

Gitorious的安全策略

Gitorious的配置文件中有幾個選項與安全相關。

  • public_mode默認值是true,每個人都可以瀏覽和下載repository。為了安全需要將其設置為false,此時將禁止匿名用戶訪問或者用戶注冊。
  • enable_private_repositories默認是false,開啟這個選項將允許用戶可以控制所擁有的repository的讀取訪問。repository默認是public的,但是可以給單個用戶或去租分配讀權限來限制瀏覽和拉取代碼的權限。更詳細的說明參見https://gitorious.org/gitorious/pages/PrivateRepositories
  • only_site_admins_can_create_projects   默認false,看參數名字就明白這個參數表示是否只能由管理員用戶來創建project
  • hide_http_clone_urls   默認false, 是否隱藏http url
  • hide_git_clone_urls 默認false, 是否隱藏git:// url
  • always_display_ssh_url  默認false,如果你設置隱藏了http和git url,那么這個就需要設置為true。


免責聲明!

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



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