git服务器搭建过程

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

需求

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

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

安装配置git服务器

安装git和openssh:
a@server:~$sudo apt-get install git-core openssh-server openssh-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.pub git@<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.gi t# 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 clone git@<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@server usr@pc1
[group hello]
writable = teamwork
members = a@serverb
[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

Ubuntu中Git服务器搭建的更多相关文章

  1. 项目实践中--Git服务器的搭建与使用指南(转)

    一.前言 Git是一款免费.开源的分布式版本控制系统,用以有效.高速的处理从很小到非常大的项目版本管理.在平时的项目开发中,我们会使用到Git来进行版本控制. Git的功能特性: 从一般开发者的角度来 ...

  2. 项目实践中--Git服务器的搭建与使用指南

    一.前言 Git是一款免费.开源的分布式版本控制系统,用以有效.高速的处理从很小到非常大的项目版本管理.在平时的项目开发中,我们会使用到Git来进行版本控制. Git的功能特性: 从一般开发者的角度来 ...

  3. 基于阿里云服务器的git服务器搭建

    使用阿里云Ubuntu 12.0.4 64位操作系统做git服务器. 首先git服务器有两种访问方式可以选择:http方式和ssh的方式,http方式更容易使用. 1.http方式的git服务器搭建以 ...

  4. 【转】Windows平台下Git服务器搭建

    Windows平台下Git服务器搭建 Posted on 2015-05-18 21:29 阿祥当码农 阅读(7637) 评论(0) 编辑 收藏 该文章转自:http://www.codeceo.co ...

  5. Git系列(1) Windows下Git服务器搭建

    作为对前两天Git服务器搭建的一个整理,我想分别从服务端和客户端两个角度来记录下整个搭建过程,为了达到目标,我们需要哪些操作. (一)服务端软件和账号的安装配置 我们这里只需要两个软件git和ssh, ...

  6. Windows下Git服务器搭建[转]

    Windows下Git服务器搭建   作为对前两天Git服务器搭建的一个整理,我想分别从服务端和客户端两个角度来记录下整个搭建过程,为了达到目标,我们需要哪些操作. (一)服务端软件和账号的安装配置 ...

  7. Ubuntu下Git从搭建到使用详解

    Ubuntu下Git从搭建到使用详解 一.git的搭建 (1).sudo apt-get update (2).sudo apt-get -y install git 符:安装最新版本方法: add- ...

  8. Windows平台下Git服务器搭建--------gitblit

    Windows(server)平台下Git服务器搭建 第一步:下载Java,安装,配置环境变量. 第二步:下载Gitblit.下载地址:http://www.gitblit.com/ 第三步:解压缩下 ...

  9. Git-Runoob:Git 服务器搭建

    ylbtech-Git-Runoob:Git 服务器搭建 1.返回顶部 1. Git 服务器搭建 上一章节中我们远程仓库使用了 Github,Github 公开的项目是免费的,但是如果你不想让其他人看 ...

随机推荐

  1. 【python】dict的拷贝问题

    部分来源:http://blog.sina.com.cn/s/blog_5c6760940100bmg5.html ①直接赋值 ---- 结果是不同名的引用 对新字典的修改完全作用在了原来的字典上,只 ...

  2. Android点击图标重新启动问题

    原文:http://blog.csdn.net/jianiuqi/article/details/54091181 项目中的小问题:发现应用打包安装后按home键切换到后台后,点击应用图标又重新打开了 ...

  3. bzoj 3295 CDQ求动态逆序对

    #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk mak ...

  4. 六十二 Web开发 使用模板

    Web框架把我们从WSGI中拯救出来了.现在,我们只需要不断地编写函数,带上URL,就可以继续Web App的开发了. 但是,Web App不仅仅是处理逻辑,展示给用户的页面也非常重要.在函数中返回一 ...

  5. centos定时备份数据库超简单示例

    #mkdir -p /home/db_backup#cd /home/db_backup #vim mysql_backup.shDATE=$(date +%Y%m%d_%H%M%S) /alidat ...

  6. vmware漏洞之一——转:利用一个堆溢出漏洞实现VMware虚拟机逃逸

    转:https://zhuanlan.zhihu.com/p/27733895?utm_source=tuicool&utm_medium=referral 小结: vmware通过Backd ...

  7. #、##和__VA_ARGS__

    转自:http://www.cnblogs.com/zhujudah/admin/EditPosts.aspx?opt=1 1.#假如希望在字符串中包含宏参数,ANSI C允许这样作,在类函数宏的替换 ...

  8. 洛谷P1113 杂务

    题目描述 John的农场在给奶牛挤奶前有很多杂务要完成,每一项杂务都需要一定的时间来完成它.比如:他们要将奶牛集合起来,将他们赶进牛棚,为奶牛清洗乳房以及一些其它工作.尽早将所有杂务完成是必要的,因为 ...

  9. wannafly挑战赛14

    第一次打wannafly..觉得自己好菜啊... 题目描述 在三维空间中,平面 x = 0, y = 0, z = 0,以及平面 x + y + z = K 围成了一个三棱锥. 整天与整数打交道的小明 ...

  10. 浅谈分布式CAP定理

    互联网发展到现在,由于数据量大.操作并发高等问题,大部分网站项目都采用分布式的架构.而分布式系统最大的特点数据分散,在不同网络节点在某些时刻(数据未同步完,数据丢失),数据会不一致. 在2000年,E ...