使用阿里云Ubuntu 12.0.4 64位操作系统做git服务器。

首先git服务器有两种访问方式可以选择:http方式和ssh的方式,http方式更容易使用。

1、http方式的git服务器搭建以及使用git命令行访问:

On the Server

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

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

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:-

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:-

a2enmod dav_fs

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

/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..

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/

2、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

3、客户端的配置:

我们客户端使用VS2013的IDE,所以我们选择git extensions+git source control provider,在【工具】->【扩展和更新】->“联机”选项卡,搜索对应名字即可。

安装git extensions时如果没MsysGit和KDiff,则勾选安装。

4、服务器安装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,大功告成!

基于阿里云服务器的git服务器搭建的更多相关文章

  1. 【经验】基于阿里云 Ubuntu 的 LAMP 网站搭建及配置完全教程

    本文同步发表在负雪明烛的博客:https://fuxuemingzhu.cn/2016/03/02/My-Aliyun-Server-Setting/ 起因 最近老师让我做一个众筹系统,可以在微信公众 ...

  2. 一·创建Linux服务器(基于阿里云)

    本系统是基于阿里云服务器,购买请前往https://www.aliyun.com/?spm=5176.8142029.388261.1.taXish ,由于经济能力的限制,本人购买的是最低配置如下 其 ...

  3. 基于Apache的阿里云部署Node.js服务器(Windows环境)

    1 前言 由于nodejs项目对方开放了多个端口,而且阿里云上的Apache服务器(windows)已经挂载了网站,此时需要把此项目也挂上去,网上查询资料,方法略少,基本是基于nginx版本的. 2  ...

  4. 搭建基于金山快盘的Git服务器

    最近迷上了Git,这货堪称神器,用了它就再也不想用其他VCS了,就像上了高速就不想再走国道一样. 一般人使用Git+Github来搭建进行本地远程交互,不过Github弄个私人仓库是要刀乐思的,如果你 ...

  5. 阿里云RDS与ECS服务器数据库做主从

    阿里云RDS与ECS服务器数据库做主从 [精] 里云RDS(数据库)基于飞天大规模分布式计算和存储能力,提供超高性价比的单机版实例,同时利用读写分离横向扩展读能力,满足网站类的业务需求.提供稳定.高性 ...

  6. 基于金山快盘的Git服务器、快盘+ Git GUI 实现代码版本管理

        Git,这货堪称神器,用了它就再也不想用其他VCS了,就像上了高速就不想再走国道一样. Git的强大之处在于,你可以在局域网内的任何一个共享路径下创建仓库,而不需要运行任何服务.所有的操作都是 ...

  7. 基于阿里云server搭建SVNserver

    基于阿里云server搭建SVNserver 本系列文章由ex_net(张建波)编写,转载请注明出处. http://blog.csdn.net/ex_net/article/details/8577 ...

  8. 使用Navicat或者其他数据库工具连接阿里云EDS(数据库服务器)实例过程详解

    使用Navicat或者其他数据库工具连接阿里云EDS(数据库服务器)实例过程详解 背景:这几天从阿里云上面购买了云服务器,最垃圾的那种,还送oss和EDS数据库服务器,只不过EDS数据库服务器只有一个 ...

  9. 基于阿里云ECS的phpwind网站备案前如何远程访问调试?

    基于阿里云ECS的phpwind网站部署非常方便,但云主机的外网IP绑定域名却比较复杂.先要申请域名,成功后还需要备案.尤其是企业网站备案,需要提交的资料较多,准备资料以及审批的时间较长.这段时间在外 ...

  10. (二)基于阿里云的MQTT远程控制(购买阿里云,在云端安装MQTT,测试MQTT远程通信)

    QQ名称为Friday~的网友把他自己买MQTT的过程截图发给了我,今天就说一下如何购买阿里云,安装MQTT可以参考 http://www.cnblogs.com/yangfengwu/p/77646 ...

随机推荐

  1. FineUI中Newtonsoft.Json版本报错解决办法

    1.清空bin下的Newtonsoft.Json.dll 2.使用Nuget安装最新版本的Newtonsoft.Json.dll,安装脚本为 Install-Package Newtonsoft.Js ...

  2. JS解析XML文件和XML字符串

    JS解析XML文件 <script type='text/javascript'> loadXML = function(xmlFile){ var xmlDoc=null; //判断浏览 ...

  3. linux, configure --prefix=/有什么用

    作用就是指定安装路径不指定prefix,则可执行文件默认放在/usr /local/bin,库文件默认放在/usr/local/lib,配置文件默认放在/usr/local/etc.其它的资源文件放在 ...

  4. [转]Dll注入经典方法完整版

    Pnig0s1992:算是复习了,最经典的教科书式的Dll注入. 总结一下基本的注入过程,分注入和卸载 注入Dll: 1,OpenProcess获得要注入进程的句柄 2,VirtualAllocEx在 ...

  5. Object类概述

    Object:类 Object 是类层次结构的根类.每个类都使用 Object 作为超类.每个类都直接或者间接的继承自Object类. Object类的方法:public int hashCode() ...

  6. StringIO学习

    StringIO StringIO的行为与file对象非常像,但它不是磁盘上文件,而是一个内存里的“文件”,我们可以将操作磁盘文件那样来操作StringIO.一个简单的例子,让你对StringIO有一 ...

  7. [家里蹲大学数学杂志]第041期中山大学数计学院 2008 级数学与应用数学专业《泛函分析》期末考试试题 A

    1 ( 10 分 ) 设 $\mathcal{X}$ 是 Banach 空间, $f$ 是 $\mathcal{X}$ 上的线性泛函. 求证: $f\in \mathcal{L}(\mathcal{X ...

  8. search-a-2d-matrix(二维矩阵查找)

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  9. (转)JPEG图片数据结构分析- 附Png数据格式详解.doc

       一.简述 JPEG是一个压缩标准,又可分为标准JPEG.渐进式JPEG及JPEG2000三种: ①标准JPEG:以24位颜色存储单个光栅图像,是与平台无关的格式,支持最高级别的压缩,不过,这种压 ...

  10. Java正则表达式详解

    转自http://edu.yesky.com/edupxpt/18/2143018.shtml