转自:http://blog.csdn.net/transformer_han/article/details/6450200

git服务器搭建过程

参考网上资料搭建git服务器过程记录 如下:

需求

硬件需求:一台Ubuntu或者debian电脑(虚拟机),能通过网络访问到。

软件需求:git-core, gitosis, openssh-server, openssh-client, Apache2(Gitweb)

安装配置git服务器

安装git和openssh:
a@server:~$ sudo apt-get install git-coreopenssh-serveropenssh-client
新加用户git, 该用户将作为所有代码仓库和用户权限的管理者:
a@server:~$ sudo useradd -m git
a@server:~$ sudo passwd git
建立一个git仓库的存储点:
a@server:~$ sudo mkdir /home/repo
让除了git以外的用户对此目录无任何权限:
a@server:~$ sudo chown git:git /home/repo
a@server:~$ sudo chmod 700 /home/repo

安装配置gitosis

初始化一下服务器的git用户,这一步其实是为了安装gitosis做准备。在任何一 台机器上使用git,第一次必须要初始化一下:
a@server:~$ git config –global user.name “myname”
a@server:~$ git config –global user.email “myname@server“
安装一下python的setup tool, 这个也是为了gitosis做准备:
a@server:~$ sudo apt-get install python-setuptools
获得gitosis包:
a@server:~$ cd /tmp
a@server:/tmp$ git clone git://eagain.net/gitosis.git
a@server:/tmp$ cd gitosis
a@server:/tmp/gitosis$ sudo python setup.py install
切换到git用户下:
a@server:/tmp/gitosis$ su git
默认状态下,gitosis会将git仓库放在 git用户的home下,所以我们做一个链接到/home/repo
$ ln -s /home/repo /home/git/repositories
再次返回到默认用户
$ exit
如果你将作为git服务器的管理员,那么在你的电 脑上(另一台pc)生成ssh公钥:
usr@pc1:~$ ssh-keygen -t rsa
将公钥拷贝到服务器的/tmp下:
usr@pc1:~$ scp .ssh/id_rsa.pubgit@<server>:/tmp
回到git服务器上
a@server:/tmp/gitosis$ sudo chmod a+r /tmp/id_rsa.pub
让gitosis运行起来:
a@server:/tmp/gitosis$ sudo -H -u git gitosis-init < /tmp/id_rsa.pub
Initialized empty Git repository in /home/repo/gitosis-admin.git/
Reinitialized existing Git repository in /home/repo/gitosis-admin.git/
gitosis的有趣之处在于,它通过一个git仓库来管理配置文件,仓库就放在了/home/repo/gitosis- admin.git。我们需要为一个文件加上可执行权限:
a@server:/home/git$ sudo passwd root
a@server:/home/git$ su
root@server:/home/git# cd repositories
root@server:/home/git/repositories# cd gitosis-admin.git/
root@server:/home/git/repositories/gitosis-admin.git#sudo
chmod 755 /home/repo/gitosis-admin.git/hooks/post-update

root@server:/home/git/repositories/gitosis-admin.git# exit

在服务器上新建一个测试项目仓库

我建了一个叫“teamwork”的仓库。
切换到Git用户:
a@ubuntu:/home/git$ su - git
$ cd /home/prj_git
$ mkdir teamwork.git
$ cd teamwork.git
$ git init --bare
$ exit

但是,到目前为止,这只是一个空仓库,空仓库是不能clone下来的。为了能做clone,我们必须先让某个有权限的人放一个初始化的版本到仓库中。
所以,我们必须先修改一下gitosis-admin.

管理gitosis的配置文件

刚刚提到,gitosis本身的配置也是通过git来实现的。在你自己的开发机里,把gitosis-admin.git这个仓库clone下来,就可以以管理员的身份修改配置了。

在你的电脑里:
usr@pc1:~/work$ git clonegit@<server>:gitosis-admin.git
如果出现:
fatal: '~/gitosis-admin.git' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
改成:
usr@pc1:~/work$ cd gitosis-admin/
该目录下的keydir目录是用来存放所有需要访问git服务器的用户的ssh公钥:
各个用户按照前面提到的办法生成各自的ssh公钥文件后,把所有人的 ssh公钥文件都拿来,按名字命名一下,比如b.pub, lz.pub等,统统拷贝到keydir下:
修改gitosis.conf文件,我的配置大致如下:
[gitosis]
[group gitosis-admin]
writable = gitosis-admin
members = a@serverusr@pc1
[group hello]
writable = teamwork
members = a@server b
[group hello_ro]
readonly = teamwork
members = lz
这个配置文件表达了如下含义:gitosis-admin组成员有a, usr,该组对gitosis-admin仓库有读写权限;
team组有a,b两个成员,该组对teamwork仓库有读写权限;
team_ro组有lz一个成员,对teamwork仓库有只读权限。
当然目前这些配置文件的修改只是在你的本地,你必须推送到远程的gitserver上才能真正生效。
加入新文件、提交并push到git服务器:
usr@pc1:~/work/gitosis-admin$ git add .
usr@pc1:~/work/gitosis-admin$ git commit -am “add teamweok prj and users”
usr@pc1:~/work/gitosis-admin$ git push origin master

初始化测试项目

好了,现在服务器就搭建完了,并且有一个空的项目teamwork在服务器上。接下来呢?当然是测试一下,空仓库是不能clone的,所以需要某一个有写权限的人初始 化一个版本。就我来做吧,以下是在客户端完成。
usr@pc1:~/work$ mkdir teamwork-ori
usr@pc1:~/work$ cd teamwork-ori/
usr@pc1:~/work/teamwork-ori$ git init
usr@pc1:~/work/teamwork-ori$ echo “/*add something*/” > hello
usr@pc1:~/work/teamwork-ori$ git add .
usr@pc1:~/work/teamwork-ori$ git commit -am “initial version”
到此为止teamwork已经有了一个版本了,team的其他成员只要先clone一下 teamwork仓库,就可以任意玩了。
$ cd teamwork
$ vim hello
$ git add .
$ git commit -am “b add”
$ git push origin master
$ exit

添加已有git项目

另外:如果你有一个现成的git仓库,想放到 gitserver上供team使用(比如你clone了一个官方的kernel仓库,想在内部使用它作为基础仓库),怎么办呢。
首先需要从你的工作仓库中得到一个纯仓库, 比如你的工作目录为~/kernel, 你想导出纯仓库到你的优盘里,然后拷贝到gitserver上去。
$ git clone –bare ~/kernel /media/udisk
然后就拿着优盘,交给gitserver的管理员,让他拷贝到/home/repo/下,同时需要配置 gitosis相关配置文件哦,这个就不用再说了吧。比如:下载ALSA库:
git clone git://android.git.kernel.org/platform/external/alsa-lib.git
git clone git://android.git.kernel.org/platform/external/alsa-utils.git
生成bare库
git clone –bare alsa-lib alsa-lib.git
git clone –bare alsa-utils alsa-utils.git
将bare 库移动到git服务器目录
cp alsa-lib.git /home/repo
注意变更所有者,以获取提交权限。
chown -R git alsa-lib.git
然后就O 了,呵呵.

配置gitweb

1. 安装gitweb

sudo apt-get install gitweb

2. 安装apache2

sudo apt-get install apache2

3. 配置gitweb
(1)默认没有 css 加载,把 gitweb 要用的静态文件连接到 DocumentRoot 下:
   cd /var/ www/
   sudo ln -s / usr/ share/ gitweb/* .

(注意后面的点)

(2)修改配置:

sudo vi /etc/ gitweb.conf

将 $projectroot 改为gitosis-admin.git所在目录:
/home/git/repositories

(3)修改 /home/git/repositories权限,默认情况下,gitosis将repositories权限设置为不可读的

sudo chmod 777 -R /home/git/repositories

11.编辑apache2配置文件,建立web站点 (默认情况下可以忽略此步骤)

(1) 编辑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:

SetEnv  GITWEB_CONFIG   /etc/gitweb.conf
    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>

(2)重新启动apache:sudo /etc/init.d/apache2 restart,访问http://localhost/cgi-bin/gitweb.cgi

<以下未经测试>

配 置web访问方式:
Apache常用命令:
a2dissite gitserver 禁用
a2ensite gitserver  使能
/etc/init.d/apache2 restart 重启
1.apt-get install apache2
2.手动安 装gitweb
git clone git://git.kernel.org/pub/scm/git/git.git
cd git
make GITWEB_PROJECTROOT=”/home/repo” prefix=/usr gitweb/gitweb.cgi
cd gitweb
cp -av git* /home/repo/
3.vim /etc/apache2/sites-available/gitserver
<VirtualHost 172.20.146.39:80>
ServerName 172.20.146.39
DocumentRoot /home/repo
ScriptAlias /cgi-bin/ /home/repo
<Directory /home/repo>
Options ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch
AllowOverride All
order allow,deny
Allow from all
AddHandler cgi-script cgi
DirectoryIndex gitweb.cgi
</Directory>
</VirtualHost>
4.赋予权限,很重要:
chgrp -R www-data /home/repo
chmod a+r repo
chmod a+x repo
mv hooks/post-update.sample hooks/post-update
5.a2ensite gitserver
6./etc/init.d/apache2 restart
匿名访问方式:
git clone http://192.168.1.1/alsa-lib.git
git clone http://192.168.1.1/alsa-utils.git
git访问方式:
git clone git@192.168.1.1:alsa-lib.git
Web网页浏览:
http://192.168.1.1
遇到的问题:
1.windows文件命名不区分大小 写,而linux支持。这样android源码下载时会出现一下问题。大约有15个文件存在这个问题。
2.库的描述文件在.git文件夹的description文件中。编辑该文件,在gitweb页中就会有 description。
3.gitosis库hooks下的post- update不是由post-update.sample重命名过来的,它们不一样。post-update可以更新工作目录,保持与库一致。没有它配置 文件是不会更新的。
4.(1)git@hello:/home/git$ git add .
error: readlink(“external/openssl/apps/md4.c”): No such file or directory
error: unable to index file external/openssl/apps/md4.c
fatal: adding files failed

(2)root@/external/openssl# git init
Initialized empty Git repository in /external/openssl/.git/
root@/external/openssl# git add .
error: readlink(“apps/md4.c”): No such file or directory
error: unable to index file apps/md4.c
fatal: adding files failed
(3)root@android-2.1_r2$ rm -Rf .repo
root@android-2.1_r2$ find . -name “.git”
| xargs rm -Rf

架设git服务器--使用git-daemon 架设基于git 协议服务器:

git是一个不错的版本管理的工具。现在自己在搞一个简单的应用程序开发,想使用git来进行管理。在Google了配置文档后,还是受了N多的挫折。某些文档质量不高,浪费了好多时间......

好,切入正题:

安装必要的git工具

#apt-get install git git-core

安装好了以后,进行设置

1. 创建一个git目录

#mkdir /git

#cd /git/

#mkdir myproject

2. 创建一个空的git仓库

#git-init-db

3. 创建工程的文件

# echo "My test project" > test.txt

* 此步很重要,如果要在远程clone这个project, 这个project必须是非空的,否则会失败。

4. 使用git命令添加并提交新的文件

#git-add test.txt

#git-commit -m "Init"

至此,本地的git 仓库就创建好了。想要在远程clone这个project,还需要使用git-daemon

5. 安装git-daemon-run.  git-daemon-run实际是一个脚本管理工具,用来启动git-daemon.

#apt-get install git-daemon

6. 配置git-daemon-run

#vi /etc/sv/git-daemon/run

可以看到

#!/bin/sh
exec 2>&1
echo 'git-daemon starting.'
exec chpst -m64000000 /

git-daemon --verbose --base-path=/var/cache /var/cache/git

将最后一句的git-daemon修改为

git-daemon --verbose --export-all --base-path=/git/

* 这里,我加上了一个--export-all.看下man手册就可以知道,使用该选项后,在git仓库中就不必创建git-daemon-export-ok文件。如果不使用该选项,则在第4步还需要创建该文件,即

#touch git-daemon-export-ok

7.重启系统

由于小弟还不知道如何使用git-daemon-run工具重启git-daemon,干脆重启下系统

8. 从client导出server(192.168.35.69)上的myproject

git-clone git://192.168.35.69/myproject

=============================================
branch 操作:
在本地:
git branch  test
git checkout test   // git branch  branch1 branch2
git push original test

git web 服务器的搭建【转】的更多相关文章

  1. CentOS下Web服务器环境搭建LNMP一键安装包

    CentOS下Web服务器环境搭建LNMP一键安装包 时间:2014-09-04 00:50来源:osyunwei.com 作者:osyunwei.com 举报 点击:3797次 最新版本:lnmp- ...

  2. 服务器上的 Git - 在服务器上搭建 Git

    http://git-scm.com/book/zh/v2/%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E7%9A%84-Git-%E5%9C%A8%E6%9C%8D%E ...

  3. 基于windows IIS的C语言CGI WEB服务器环境搭建

    网页编程对我来说特别亲切,因为我就是从html.ASP.PHP一步步接触编程的.自己的编程爱好也是从那里一点一点被满足.不过离开大学之后很久没有碰过WEB了,最近看到嵌入式中的涉及到的web服务器,了 ...

  4. web服务器环境搭建(及请求代理)

    集成开发环境:(前端开发还是使用下面单独的web服务器比较好,前后端分离会用到代理的功能) 1.安装xampp时,软件会自动安装 微软的  Microsoft Visual C++ 2008 Redi ...

  5. Linux下Web服务器环境搭建LNMP一键安装包[20130911更新]

    2012年08月14日 ⁄ LNMP ⁄ 评论数 73 ⁄ 被围观 25,200次+ 最新版本:lnmp-2.4 安装说明:请保证服务器能够正常上网.服务器系统时间准确.yum命令可以正常使用! 1. ...

  6. Win7+花生壳6.0+tomcat打做自己的web服务器(搭建自己的网站)(参考)

    链接地址:http://blog.csdn.net/zhu_9527/article/details/23344623?utm_source=tuicool&utm_medium=referr ...

  7. Web服务器amp搭建

  8. php dday1... web服务器的搭建 数据库的安装....

  9. Git本地服务器搭建及使用详解

    Git本地服务器搭建及使用 Git是一款免费.开源的分布式版本控制系统.众所周知的Github便是基于Git的开源代码库以及版本控制系统,由于其远程托管服务仅对开源免费,所以搭建本地Git服务器也是个 ...

随机推荐

  1. 6.1 python+appium元素定位方式(登录app)

    1.0.0     :常见的十种元素定位方式 .driver.find_element_by_id() #id定位 .driver.find_element_by_name() #name定位(已经凉 ...

  2. (原)自定义资源预览工具:DZAssetPreviewPlugin(1)

    @author: 白袍小道 转载请说明,谢谢     题记 后续工具制作单独作为一本(小道用的是OneNote,这样发布简单点.*--*) 总计放到写完后.     目的 1.快速预览资源(因为大部分 ...

  3. Visual Studio 2005安装包

    点击下载

  4. Week7 Teamework from Z.XML-任务分配

    任务分配 Z.XML任务初步分配新鲜出炉,请关注! 初步估计,我们的项目需要191小时.但是根据敏捷开发的方法,我们将在开发过程中根据情况迅速调整任务分配,以适应当时问题.

  5. 关于配置tomcat多版本同eclipse的配置问题

    最近很多同学都在反应tomcat和eclipse关联的问题,其他问题网上搜索下大多都有结果,有比较疑难杂症的,下面贴出: 有的同学之前配置过tomcat6的版本或者在此之前做过配置,现在配置tomca ...

  6. Zebra - zebra command to get printer error and warning status

    1 Flag2 Nibble 16-93 Nibble 8-44 Nibble 35 Nibble 26 Nibble 1

  7. 前端工程师必须要知道的SEO技巧(1):rel=nofollow的使用

    前提:最近我在找工作,想面试一些关于前端的工作,被问到了一些关于SEO优化的问题.我深深的感觉我所回答的太过于表面,没有深入.所以,又把SEO的内容看了一遍.自己总结如下:有的是看的其他博友的贴子,发 ...

  8. [ZJOI2008]骑士 DP dfs

    ---题解--- 题解: 观察题面可以很快发现这是一棵基环内向树(然而并没有什么用...) 再稍微思考一下,假设将这个环中的任意一点设为root,然后去掉root到下面的特殊边(即构成环的那条边),那 ...

  9. BZOJ_day9

    哇,一道巨大的水题害得我wa了无数次... 总结一下教训 大家一定记住(给我自己看的)  位运算 一定要加()!!! 重要的事情说三遍  位运算 一定要加()!!! 位运算 一定要加()!!! 位运算 ...

  10. BZOJ 3270 博物馆 && CodeForces 113D. Museum 期望概率dp 高斯消元

    大前提,把两个点的组合看成一种状态 x 两种思路 O(n^7) f[x]表示在某一个点的前提下,这个状态经过那个点的概率,用相邻的点转移状态,高斯一波就好了 O(n^6) 想象成臭气弹,这个和那个的区 ...