基於阿里雲服務器的git服務器搭建

使用阿里雲Ubuntu 12.0.4 64位操做系統作git服務器。html

首先git服務器有兩種訪問方式能夠選擇:http方式和ssh的方式,http方式更容易使用。java

一、http方式的git服務器搭建以及使用git命令行訪問:git

On the Server

1) Install Ubuntu Server, this is the base of our git server obviously :-)github

2) Now we need to install a couple of packages, these being ‘git-core’ and ‘apache2′, we do this like so:-web

apt-get update
apt-get install apache2 git-core

3) Now we need to create a new folder for your new repository and set some inital permissons, we do this like so:-apache

cd /var/www
mkdir test-repo.git
cd test-repo.git
git --bare init
git update-server-info
chown -R www-data.www-data .

4)  We now need to enable WebDAV on Apache2 of which we will use to serve the repository:-ubuntu

a2enmod dav_fs

5) We now need to configure the access restrictions to our repository by creating the following file:-vim

/etc/apache2/conf.d/git.conf

Then fill it in with the following content:-服務器

<Location /test-repo.git>
        DAV on
        AuthType Basic
        AuthName "Git"
        AuthUserFile /etc/apache2/passwd.git
        Require valid-user
</Location>

Then save and close the file, lets move on to the next bit..ssh

6) Next we need to create a user account of which you will need to use to browse of commit to the repository..

htpasswd -c /etc/apache2/passwd.git <user>

You could then be prompted to enter the password for the user too and confirm it!

7) Ok that’s it for the server side configuration… we just need to restart Apache2 like so and then we should be ready to move on to the client side stuff!

/etc/init.d/apache2 restart

…you can now move on to the client side stuff!

On the client side

Ok so now we need to create a local (on your desktop machine) repository and then we’ll initiate the new remote repository… So, if your using Linux/MacOSX bring up the terminal and type the following commands:-

mkdir ~/Desktop/test-project
cd ~/Desktop/test-project
git init
git remote add origin http://<user>@<server name or IP address>/test-project.git
touch README
git add .
git commit -a -m 「Initial import」
git push origin master

Done! – Your intiial file named ‘README’ which currently is just blank has now been committed and you’ve pushed your code to your new git server which has now completed the Git reposity creation process, now in future you can ‘clone’ your resposity like so:-

git clone <user>@<server name or IP address>/test-project.git

 

注意上面鏈接http://<user>@<server name or IP address>/test-project.git中的user就是你htpasswd -c /etc/apache2/passwd.git <user>輸入的用戶名。

另外新建倉庫的時候,只需執行:

cd /var/www
mkdir 項目名
cd 項目名
git --bare init
git update-server-info
chown -R www-data.www-data .

而後在/etc/apache2/conf.d/git.conf中對應添加上面相似段便可。

其中:

AuthUserFile 密碼文件名

 後面的文件就是你指定的密碼文件,你能夠

htpasswd -c 密碼文件名 <user>

對應指定該項目的用戶名和密碼便可。添加用戶是不要-c參數:

htpasswd 密碼文件名 <user>

參考資料:http://blog.bobbyallen.me/2012/07/23/installing-a-git-server-using-apache-webdav-on-ubuntu-server-12-04/

 

二、ssh方式訪問的git服務器:

參考:http://blog.csdn.net/sbvfhp/article/details/8013945以及http://www.blogjava.net/jasmine214--love/archive/2014/01/15/408987.html

主要參考第一個博客,但第一個博客中的:git clone git://eagain.net/gitosis.git的地址是不能用的,使用第二個博客中的git clone https://github.com/res0nat0r/gitosis.git

 

三、客戶端的配置:

咱們客戶端使用VS2013的IDE,因此咱們選擇git extensions+git source control provider,在【工具】->【擴展和更新】->「聯機」選項卡,搜索對應名字便可。

安裝git extensions時若是沒MsysGit和KDiff,則勾選安裝。

 

四、服務器安裝GitWeb:

GitWeb能夠使用網頁的方式查看各個倉庫的狀態,提交的信息等,比較方便。

依次執行下面操做便可:

sudo apt-get  install gitweb

sudo ln -sf /usr/share/gitweb /var/www

將gitweb.cgi拷貝到/var/www下

添加文件:/etc/apache2/httpd.conf 添加以下內容:

ServerName 127.0.0.1:80

而後修改:/etc/gitweb.conf

sudo vim /etc/gitweb.conf
# change $projectroot to /var/www
# change $projects_list to /var/www
# Add Highlighting at the end
$feature{'highlight'}{'default'} = [1];

而後將/etc/apache2/conf.d/gitweb改成以下:

    Alias /gitweb /usr/share/gitweb
    <Directory /usr/share/gitweb>
        Options FollowSymLinks +ExecCGI
        AddHandler cgi-script .cgi
    </Directory>

或者這樣能夠:

Alias /gitweb /usr/share/gitweb
<Directory /usr/share/gitweb>
    Options +Indexes +ExecCGI +FollowSymLinks
    AllowOverride All
    order allow,deny
    allow from all
    AddHandler cgi-script cgi
    DirectoryIndex gitweb.cgi
</Directory>

另外若是想給gitweb添加密碼,則在/etc/apache2/conf.d/gitweb剛纔的後面添加:

    <Location /gitweb>
        DAV on
        AuthType Basic
        AuthName "Git"
        AuthUserFile 密碼文件
        Require valid-user
    </Location>

    <Directory /usr/lib/cgi-bin>
        AllowOverride None
        Options None
        Order allow,deny
        Allow from all

        AuthType Basic
        AuthName "Scripts"
        AuthUserFile 密碼文件

        Require valid-user
        Satisfy All
    </Directory>

給cgi-bin加密部分參考的:http://forums.whirlpool.net.au/archive/898604

而後重啓Apache服務

 sudo /etc/init.d/apache2 restart(或者:service apache2 restart)

gitweb參考:http://www.cnblogs.com/wanghongmei/archive/2011/06/22/2087391.html和http://blog.countableset.ch/2012/04/29/ubuntu-12-dot-04-installing-gitolite-and-gitweb/

主要參考第一個網址的:Gitweb配置不用虛擬機方式。 

而後訪問:http://服務器IP或域名/gitweb

 

OK,大功告成!

相關文章
相關標籤/搜索