Gitolite搭建Git服務器

版本控制系統對於團隊開發的協同共組的重要性不可言喻,搭建git服務器的過程也比較容易出錯,需要了解每一步工作的的作用,才能找出出錯地方。以下是我構建的過程,在兩臺虛擬機上重複了三次,以下過程是在一臺比較乾淨的虛擬機上的安裝過程。一臺虛擬機上沒配置成功,不甘心,重新嘗試了一下,也順利成功了。只是在克隆clone管理倉庫gitolite-admin.git時有點不一樣,即3.7提到的方法。

操作系統:centos5.6

1、安裝openssh依賴的軟件包

#yum install openssh* -y
centos服務器一般已經安裝好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.git

3.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 [email protected]: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。重新安裝無法像上面使用[email protected]這種形式複製gitolite-admin.git。使用3.9設置的host可以複製。

#git clone git@test:gitolite-admin.git

3.8 去掉git用戶密碼。否則提示輸入密碼

#passwd -d git

3.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 [email protected]
或者
#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/

【5】http://www.mmncs.com/2011/07/how-to-install-and-setup-a-git-repository-server-using-gitolite-on-linux-ubuntu-11-04-server-and-client/

【6】Gitolite構建Git服務器




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章