搭建Gitolite

系統:CentOS7git

1.安裝依賴包

[root@localhost ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel -y

2.安裝git

[root@localhost ~]# yum install git

3.建立git用戶

[root@localhost ~]# useradd -s /bin/bash git -m
// -s 指定用戶shell
// -m 建立用戶主目錄

4.安裝gitolite

克隆gitolite倉庫github

[git@localhost ~]$ git clone https://github.com/sitaramc/gitolite

建立目錄並安裝shell

[git@localhost ~]$ mkdir $HOME/bin
[git@localhost ~]$ gitolite/install -to $HOME/bin
[git@localhost ~]$ ll bin/
total 24
drwxrwxr-x. 2 git git 4096 Jan 23 01:52 commands
-rwxrwxr-x. 1 git git 3083 Jan 23 01:52 gitolite
-rwxrwxr-x. 1 git git 9023 Jan 23 01:52 gitolite-shell
drwxrwxr-x. 3 git git   22 Jan 23 01:52 lib
drwxrwxr-x. 2 git git   92 Jan 23 01:52 syntactic-sugar
drwxrwxr-x. 3 git git  166 Jan 23 01:52 triggers
-rw-rw-r--. 1 git git   19 Jan 23 02:01 VERSION
drwxrwxr-x. 2 git git  174 Jan 23 01:52 VREF

安裝gitolite,出現以下錯誤bash

Can't locate Data/Dumper.pm in @INC (@INC contains: /home/git/gitolite/src/lib /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /home/git/gitolite/src/lib/Gitolite/Common.pm line 65.
BEGIN failed--compilation aborted at /home/git/gitolite/src/lib/Gitolite/Common.pm line 65.
Compilation failed in require at gitolite/install line 15.
BEGIN failed--compilation aborted at gitolite/install line 15.

安裝以下依賴app

yum install -y perl-Data-Dumper

5.配置gitolite管理員

  • 5.1. git用戶生成公鑰
[git@localhost ~]$ cd ~
[git@localhost ~]$ ssh-keygen -t rsa //一路回車
[git@localhost ~]$ mv .ssh/id_rsa.pub admin.pub
  • 5.2 安裝管理員公鑰
[git@localhost ~]$ $HOME/bin/gitolite setup -pk admin.pub
  • 5.3 clone 管理員倉庫
[git@localhost ~]$ git clone git@127.0.0.1:gitolite-admin

6.添加用戶

添加用戶很簡單。爲了添加一個名爲highgo的用戶,獲取該用戶的公鑰,命名爲highgo.pub,而後放到管理員倉庫gitolite-admin的keydir目錄下。添加,提交,而後推送更改。這樣用戶就被添加了。ssh

highgo:curl

[highgo@localhost ~]$ ssh-keygen -t rsa
[highgo@localhost ~]$ mv .ssh/id_rsa.pub highgo.pub

將highgo.pub文件放入/home/git/gitolite-admin/keydir
git:測試

[git@localhost keydir]$ pwd
/home/git/gitolite-admin/keydir
[git@localhost keydir]$ ll
total 8
-rw-rw-r--. 1 git git 407 Jan 23 02:26 admin.pub
-rw-r--r--. 1 git git 410 Jan 23 02:28 highgo.pub
[git@localhost keydir]$ cd ..
[git@localhost gitolite-admin]$ git add keydir/highgo.pub
[git@localhost gitolite-admin]$ git config --global user.email "git@test.com"
[git@localhost gitolite-admin]$ git config --global user.name "git"
[git@localhost gitolite-admin]$ git commit -am "add user highgo"
[git@localhost gitolite-admin]$ git push origin master

7. 測試

[highgo@localhost ~]$ git clone git@127.0.0.1:testing
Cloning into 'testing'...
warning: You appear to have cloned an empty repository.
[highgo@localhost ~]$ cd testing/
[highgo@localhost testing]$ ll
total 0
[highgo@localhost testing]$ touch text.txt
[highgo@localhost testing]$ ll
total 0
-rw-rw-r--. 1 highgo highgo 0 Jan 23 03:27 text.txt
[highgo@localhost testing]$ git add text.txt 
[highgo@localhost testing]$ git config --global user.email "highgo@test.com"
[highgo@localhost testing]$ git config --global user.name "highgo"
[highgo@localhost testing]$ git commit -m "add txt"
[master (root-commit) cc916f3] add txt
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 text.txt
[highgo@localhost testing]$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 201 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@127.0.0.1:testing
 * [new branch]      master -> master
[highgo@localhost testing]$ ll
total 0
-rw-rw-r--. 1 highgo highgo 0 Jan 23 03:27 text.txt
[highgo@localhost testing]$ cd ..
[highgo@localhost ~]$ rm -rf testing/
[highgo@localhost ~]$ git clone git@127.0.0.1:testing
Cloning into 'testing'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
[highgo@localhost ~]$ cd testing/
[highgo@localhost testing]$ ll
total 0
-rw-rw-r--. 1 highgo highgo 0 Jan 23 03:30 text.txt
[highgo@localhost testing]$
相關文章
相關標籤/搜索