CentOs上搭建git服务器

CentOs上搭建git服务器

首先安装setuptools

  1. wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
  2. tar zxvf setuptools-0.6c11.tar.gz
  3. cd setuptools-0.6c11
  4. python setup.py build
  5. python setup.py install

在服务器(CentOs)上首先安装git软件

  • yum insatll git

安装gitosis

  1. git clone git://github.com/res0nat0r/gitosis.git
  2. cd gitosis
  3. python setup.py install

添加用户git

sudo useradd -r -s /bin/sh -c 'git version control' -d /home/git git

设置权限

mkdir -p /home/git

chown git:git /home/git

ssh登陆验证

  • cat kailuzhe_rsa.pub >> authorized_keys authorized_keys存在,追加
  • mv kailuzhe_rsa.pub authorized_key authorized_keys不存在,改名

生成公钥

  • ssh-keygen -t rsa

上传公钥

  • scp ~/.ssh/id_rsa.pub USER@YOUR_SERVER:/tmp

在服务端生成管理库

  • sudo -H -u git gitosis-init < /tmp/id_rsa.pub

看到如下提示说明安装成功

Initialized empty Git repository in /var/spool/gitosis/repositories/gitosis-admin.git/ Reinitialized existing Git repository in /var/spool/gitosis/repositories/gitosis-admin.git/

修改上传权限

  • chmod 755 /var/spool/gitosis/repositories/gitosis-admin.git/hooks/post-update

同步配置文件

  • git clone git+ssh://git@118.123.16.30:22000/gitosis-admin.git

创建新的repositories

打开gitosis.conf文件,你将看到

[group gitosis-admin]

writable = gitosis-admin

members = nasa127@localhost

这个是管理组的权限,members中的用户名就是刚才上传的公钥里面的用户名。 在这个文件后面加入:

[group myteam]

members = nasa127@localhost

writable = diablo3_spider

这里你定义了一个叫myteam的组,授予nasa127@localhost这个用户写“diablo3_spider”这个repo的权限

git commit -a -m "Allow nasa write access to diablo3_spider"

git push

上面的操作就更新了服务端的权限。 下面就开始创建diablo3_spider的repo

mkdir diablo3_spider

cd diablo3_spider

git init

随便加一些文件提交代码:

git remote add origin git@YOUR_SERVER_HOSTNAME:diablo3_spider.git

git add .

git commit -a -m "initial import"

 

git push origin master:refs/heads/master

接下来,可以增加成员的公钥到系统中了

cd gitosis-admin

cp ~/Administrator@SUNPX-PC.pub keydir/

cp ~/tongzhongqian@localhost.pub keydir/

git add keydir/Administrator@SUNPX-PC.pub keydir/tongzhongqian@localhost.pub

修改gitosis.conf

[group fractalist]

members = nasa127@localhost Administrator@SUNPX-PC tongzhongqian@localhost

writable = GTFund-iPad

提交修改:

git commit -a -m "Granted sunpx and qtz commit rights to diablo3_spider"

git push

其它成员就可以获取代码了

git clone git@YOUR_SERVER:diablo3_spider.git

其他

对Git设置端口号

git+ssh://git@YOUR_SERVER:PORT/GTFund-iPad.git

 

git remote add origin git+ssh://git@YOUR_SERVER:PORT/GTFund-iPad.git

参考文档

  • http://blog.prosight.me/index.php/2009/07/271
  • http://blog.chinaunix.net/uid-26337130-id-3027600.html
  • https://github.com/res0nat0r/gitosis#using-gitweb
  • http://www.jiangmiao.org/blog/1600.html
  • http://hi.baidu.com/unspace/blog/item/81cef0d33db0f3c0a9ec9ab0.html
  • http://code.google.com/p/tortoisegit/

来自:http://www.cnblogs.com/nasa/archive/2012/05/31/2528901.html

 

自己添加的链接:

http://git-scm.com/book/zh/ch4-7.html

http://blog.csdn.net/king_sundi/article/details/7065525

 

posted on 2014-02-10 17:55  BuildyMan  阅读(255)  评论(0编辑  收藏  举报

导航