Git服務器Gitosis安裝設置

1. 準備環境,安裝更新

<!-- lang: shell -->
sudo apt-get update 
sudo apt-get upgrade

2. 安裝 openssh服務器

<!-- lang: shell -->
sudo apt-get install openssh-server openssh-client

3. 安裝 git服務器

<!-- lang: shell -->
sudo apt-get install git-core

4. 配置 git服務器

  • 建立git服務器管理用戶javascript

    <!-- lang: shell -->
      sudo useradd -m git
      sudo passwd git

用戶名和密碼均爲gitcss

  • 建立git倉庫存儲目錄html

    <!-- lang: shell -->
     sudo mkdir /home/git/repositories
  • 設置git倉庫權限java

    <!-- lang: shell -->
      sudo chown git:git /home/git/repositories
      sudo chmod 755 /home/git/repositories
  • 初始化全局設置python

    <!-- lang: shell -->
      git config --global user.name "myname"
      git config --global user.email "myname@server"

5. 安裝python的setup tool

<!-- lang: shell -->
sudo apt-get install python-setuptools

6. 獲取並安裝gitosis

<!-- lang: shell -->
cd /tmp
git clone https://github.com/res0nat0r/gitosis.git
cd gitosis
sudo python setup.py install

7. 配置gitosis

<!-- lang: shell -->
cp ~/.ssh/id_rsa.pub /tmp
sudo -H -u git gitosis-init < /tmp/id_rsa.pub
sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

8.建立我的公鑰和私鑰,另一臺pc機(git客戶端)

  • 在默認用戶的主目錄路徑下,運行如下命令,按照提示建立公鑰和私鑰git

    <!-- lang: shell -->
      ssh-keygen -t rsa
  • 默認狀況下,公鑰和私鑰會保存在~/.ssh目錄下,以下所示:github

    <!-- lang: shell -->
      id_rsa  id_rsa.pub  known_hosts

9. 管理gitosis配置

  • 在git客戶端web

    <!-- lang: shell -->
      cd ~
      git clone git@hostname:用戶名/gitosis-admin.git
      cd gitosis-admin/
  • 各個用戶按照前面提到的辦法生成各自的ssh公鑰文件後,服務器管理員把全部人的 ssh公鑰文件都拿來,拷貝到keydir目錄下。修改gitosis.conf文件,以下所示shell

    <!-- lang: shell -->
      [gitosis]
    
      [group gitosis-admin]
      writable = gitosis-admin
      members = a@server1
    
      [group developers]
      writable = helloworld
      members = a@server1 b@server2
    
      [group test] 
      readonly = helloworld
      members = c@server3
  • 這個配置文件表達了以下含義:gitosis-admin組成員有a,該組對gitosis-admin倉庫有讀寫權限; developers組有a,b兩個成員,該組對helloworld倉庫有讀寫權限; test組有c一個成員,對helloworld倉庫有隻讀權限。 固然目前這些配置文件的修改只是在你的本地,你必須推送到gitserver上才能真正生效。 加入新文件、提交併push到git服務器:apache

    <!-- lang: shell -->
      git add .
      git commit -am "add helloworld project and users"
      git remote add origin ssh://git@hostname/helloworld.git
      git push origin master

10. 安裝apache2 

<!-- lang: shell -->
sudo apt-get install apache2

11. 安裝gitweb

<!-- lang: shell -->
sudo apt-get install gitweb

12. 配置 gitweb

  • 默認沒有 css 加載,把 gitweb 要用的靜態文件鏈接到 DocumentRoot 下:

    <!-- lang: shell -->
      cd /var/www/
      sudo ln -s /usr/share/gitweb/* .
  • 修改配置:

    <!-- lang: shell -->
      sudo vi /etc/gitweb.conf

將 $projectroot 改成git倉庫存儲目錄(例如:/home/git/repositories),保存後刷新瀏覽器。 若是沒有找到項目,你須要將$projectroot/*.git 的屬性改成755,讓apache用戶有可讀權限。能夠只改你須要讓別人經過web訪問的那個git。 http://localhost/cgi-bin/gitweb.cgi

  • 修改/etc/gitweb.conf 內容:

    <!-- lang: shell -->
      # path to git projects (<project>.git)
      #$projectroot = "/var/cache/git";
      $projectroot = "/home/git/repositories";
    
      # directory to use for temp files
      $git_temp = "/tmp";
    
      # target of the home link on top of all pages
      $home_link = $my_uri || "/";
    
      # html text to include at home page
      $home_text = "indextext.html";
    
      # file with project list; by default, simply scan the projectroot dir.
      $projects_list = $projectroot;
    
      # stylesheet to use
      @stylesheets = ("/gitweb/static/gitweb.css");
    
      # javascript code for gitweb
      $javascript = "/gitweb/static/gitweb.js";
    
      # logo to use
      $logo = "/gitweb/static/git-logo.png";
    
      # the 'favicon'
      $favicon = "/gitweb/static/git-favicon.png";
    
      # git-diff-tree(1) options to use for generated patches
      #@diff_opts = ("-M");
      @diff_opts = ();

13. 配置apache2

ubuntu中默認的web目錄是/var/www,默認的cgi目錄是 /usr/lib/cgi-bin/,安裝完成gitweb後,gitweb的gitweb.cgi會自動放置到該目錄下。

若是你的cgi路徑不是默認的/usr/lib/cgi-bin/,須要將gitweb安裝在/usr/lib/cgi-bin中的gitweb.cgi複製到原來配置的cgi-bin路徑,並在apache的配置文件/etc/apache2/apache.conf末尾加上如下內容:

<!-- lang: shell -->
SetEnv  GITWEB_CONFIG   /etc/gitweb.conf 
<Directory "/srv/www/cgi-bin/gitweb">           
     Options FollowSymlinks ExecCGI          
     Allow from all                          
     AllowOverride all                       
     Order allow,deny                        
     <Files gitweb.cgi> 
          SetHandler cgi-script 
     </Files>                    
     RewriteEngine on 
     RewriteCond %{REQUEST_FILENAME} !-f 
     RewriteCond %{REQUEST_FILENAME} !-d 
     RewriteRule ^.* /gitweb.cgi/$0 [L,PT] 
</Directory>

從新啓動apache:sudo /etc/init.d/apache2 restart,訪問http://localhost/cgi-bin/gitweb.cgi

相關文章
相關標籤/搜索