版本控制系统对于团队开发的协同共组的重要性不可言喻,搭建git服务器的过程也比较容易出错,需要了解每一步工作的的作用,才能找出出错地方。以下是我构建的过程,在两台虚拟机上重复了三次,以下过程是在一台比较干净的虚拟机上的安装过程。一台虚拟机上没配置成功,不甘心,重新尝试了一下,也顺利成功了。只是在克隆clone管理仓库gitolite-admin.git时有点不一样,即3.7提到的方法。
操作系统:centos5.6
1、安装openssh依赖的软件包
#yum install openssh* -ycentos服务器一般已经安装好perl编译开发环境
2、编译安装git
下载地址https://code.google.com/p/git-core/downloads/list选择合适的版本,这了选择是1.7.10
解压:
#tar zxvf git*
编译:
# make
安装:
# make install
3、配置gitolite
3.1、建立git用户
#useradd git#visudo
添加权限控制,允许git用户sudo,添加一下内容
git ALL=(ALL) ALL
修改密码
#passwd git
3.2 设置gitolite工作目录
#cd /home/git#chown -R git:git /home/git
#chmod -R 2755 /home/git
3.3下载gitolite
#git clone git://github.com/sitaramc/gitolite.git3.4安装gitolite
#su git#cd ./gitolite
#mkdir -p ~/bin
#./install -to ~/bin
#echo "PATH=$PATH:$HOME/bin" >> ~/.bashrc
#source ~/.bashrc 使环境变量生效
3.5 生成公钥与私钥
下一步需要使用到管理员的公钥,在客户端生成公钥与私钥,把公钥上传到git服务器为了方便,我在git服务器本地生成公钥和私钥,也在git服务器本地进行测试。其实把私钥拷贝到客户端使用也可以。
#su root 切换到root用户
#ssh-keygen -t rsa -f git.pub
下面一直输入“回车”就可以,生成的公钥和私钥在~/.ssh/下面
把git.pub复制到根目录/下
#cp ~/.ssh/git.pub /git.pub
3.6 setup
#su git#cd ~/bin
#./gitolite setup -pk ~/git.pub
将会显示下面的初始化信息
Initialized empty Git repository in /home/git/repositories/gitolite-admin.git/
Initialized empty Git repository in /home/git/repositories/testing.git/
3.7 复制git管理仓库文件
#git clone git@192.168.3.199:gitolite-admin.git复制信息:
Cloning into 'gitolite-admin'...
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (4/4), done.
***这一步可能提示输入密码,可能由于公钥引起的
http://www.mmncs.com/2011/06/fatal-gitolite-admin-git-does-not-appear-to-be-a-git-repository/
fatal: gitolite-admin.git does not appear to be a git repository
by MMNCS on June 9th, 2011, updated August 16, 2011
If you get the follwoing error: “fatal: gitolite-admin.git does not appear to be a git repository” It might be because a public key has been added to the authorized_keys file for the gitolite git user account. I discovered this after much hazzle and you can only have keys generated by Gitolite in the authorized_key file.Simply remove the key from the authorized_keys file and the problem should cease to exist.
或者先进行3.9的步骤,再通过host进行复制管理仓库。之前一台虚拟机上配置失败,不能复制gitolite-admin.git。重新安装无法像上面使用git@192.168.3.90这种形式复制gitolite-admin.git。使用3.9设置的host可以复制。
#git clone git@test:gitolite-admin.git3.8 去掉git用户密码。否则提示输入密码
#passwd -d git3.9 修改~/.ssh/config文件,允许用户无需帐号和密码登录
#su root#vim ~/.ssh/config
加入以下内容
host test
user git
hostname 192.168.3.199
port 22
identityfile ~/.ssh/git
3.10 测试
# ssh git@192.168.3.199或者
#ssh test
hello git, this is git@sylar199 running gitolite3 v3.5.1-8-gd8fa068 on git 1.7.10
出现下面的信息
R W gitolite-admin
R W testing
Connection to 192.168.3.199 closed.
配置过程中使用的git用户,注意用户的切换。
注意git的ssh连接,与shell的ssh连接,他们均使用到公钥,注意他们的区别(使用的shell不同,/bin/bash与gitolite-shell)。
有什么问题,给我指出,谢谢!
4 参考资料:
【1】http://williamherry.com/blog/2012/10/03/install-gitolite/【2】http://www.csser.com/board/4f3f516e38a5ebc978000507
【3】http://www.poorren.com/centos-git-gitolite-windows/
【4】http://www.mmncs.com/2011/06/fatal-gitolite-admin-git-does-not-appear-to-be-a-git-repository/
【6】Gitolite构建Git服务器