sfwe2 发表于 2015-4-20 12:44:37

CentOS 6.4x64安装git和gitolite服务器

一.部署环境
    系统:CentOS 6.4x64 最小化安装
    IP:192.168.3.27

二.安装基础依赖包   

1
#yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel -y





三.下载git-2.2.0.tar.gz

1
#wget https://www.kernel.org/pub/software/scm/git/git-2.2.0.tar.gz





四.解压文件到当前目录下,并安装

1
2
3
4
5
6
7
8
9
10
11
#tar xf git-2.2.0.tar.gz
#cdgit-2.2.0/
#make prefix=/usr/local/git all
#make prefix=/usr/local/git install

增加软连接
#ln -s /usr/local/git/bin/* /usr/bin/

验证结果,显示出版本号,表示安装成功
#git --version
git version 2.2.0





五.创建git用户

1
# useradd git





六.在git用户家目录下安装gitolite

1
2
3
# su git
$ cd
$ mkdir bin





七.克隆gitolite源码

1
2
3
4
5
6
7
$ git clone https://github.com/sitaramc/gitolite.git
Cloning into 'gitolite'...remote: Counting objects: 8884, done.
remote: Total 8884 (delta 0), reused 0 (delta 0), pack-reused 8884Receiving
objects: 100% (8884/8884), 3.66 MiB | 179.00 KiB/s, done.
Resolving deltas: 100% (5055/5055), done.Checking connectivity... done.
$ ls
bingitolite





八.安装gitolite

1
2
3
$ ./gitolite/install --to /home/git/bin/
$ ls bin/
commandsgitolitegitolite-shelllibsyntactic-sugartriggersVERSIONVREF





九.配置gitolite管理员
    生成管理员账户的公钥(此处指定本地root用户为管理员,键入回车使用默认值)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# ssh-keygen
# cp .ssh/id_rsa.pub /tmp/admin.pub

切换回git用户,为gitolite配置管理员
$ bin/gitolite setup -pk /tmp/admin.pub
Initialized empty Git repository in /home/git/repositories/gitolite-admin.git
/Initialized empty Git repository in /home/git/repositories/testing.git/
WARNING: /home/git/.ssh missing; creating a new one   
(this is normal on a brand new install)
WARNING: /home/git/.ssh/authorized_keys missing; creating a new one   
(this is normal on a brand new install)

$ ls
bingitoliteprojects.listrepositories





十.管理员日常管理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# git clone git@192.168.3.27:gitolite-admin
Cloning into 'gitolite-admin'...The authenticity of host
'192.168.3.27 (192.168.3.27)' can't be established.
RSA key fingerprint is c4:34:02:55:ad:42:8a:65:ba:94:00:20:48:d7:3c:33.
Are you sure you want to continue connecting (yes/no)? yes
#这里是第一次连接,需要输入yes进行确认
Warning: Permanently added '192.168.3.27' (RSA) to the list of known hosts.
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (4/4), done.
Receiving objects: 100% (6/6), 734 bytes | 0 bytes/s, done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Checking connectivity... done.

# ls
confkeydir
# pwd
/root/gitolite-admin





验证:
创建库、添加用户
例如某test用户访问git服务器上的mytest库

test用户向git服务器管理(此处是之前的服务器本地的root用户)提交自己的ssh无密码公钥

管理员将test的公钥复制到 gitolite-admin/keydir/ 下

注:该key需要在test用户机器上使用ssh-keygen生成,再传送到192.168.3.27/tmp目录下

1
# cp /tmp/test.pub /root/gitolite-admin/keydir/




管理员创建myFirstRepo库,并给test分配权限

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# cd gitolite-admin/conf/
# vim gitolite.conf
#以下是gitolite.conf的默认内容
repo gitolite-admin   
    RW+   =   admin
repo testing   
    RW+   =   @all
   
下边定义mytest库,并且指定用户权限:
#在gitolite.conf中添加以下内容
@mygroup    = test
repo mytest   
    RW+   = @mygroup
注:此处@mygroup是一个组,给mygroup组赋予对mytest这个库的读、写、推送的权限
(详细规则可参考gitolite的readme.txt)管理员将对gitolite-admin的修改(建库、加用户)
提交到git服务器

# pwd
/root/gitolite-admin
# git status    #查看git库状态
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)   

    modified:   conf/gitolite.conf      #表示该文件被修改
Untracked files:(use "git add <file>..." to include in what will be committed)
    keydir/test.pub      #增加的文件
no changes added to commit (use "git add" and/or "git commit -a")

#将有改动的文件添加到git库
# git add keydir/test.pub conf/gitolite.conf
# git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:(use "git reset HEAD <file>..." to unstage)
    modified:   conf/gitolite.conf   
    new file:   keydir/test.pub
    #这里表示已添加#在第一次执行git commit命令时会有以下提示,需要使用者表明身份

# git commit -m "add repo mytest; add user test"
*** Please tell me who you are.Run
    git config --global user.email "you@example.com"
    git config --global user.name "Your Name"to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'root@nginx.(none)')

#在这里我们执行以下2条命令
# git config --global user.email "lyao@aaa.com"
# git config --global user.name "lyao"

#再重新执行git commit命令
# git commit -m "add repo mytest; add user test"
add repo mytest;
add user test 2 files changed, 5 insertions(+)
create mode 100644 keydir/test.pub

#执行完以上命令后,修改的文件只是提交在本地了,并没有提交到git server中,还需要执行git push命令
# git push origin master    #推送到远端的master分支
Counting objects: 6, done.Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 817 bytes | 0 bytes/s, done.
Total 6 (delta 0), reused 0 (delta 0)
remote: Initialized empty Git repository in /home/git/repositories/mytest.git
/To git@192.168.3.27:gitolite-admin   
3554f3d..7b877e7master -> master





客户端验证:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# git clone git@192.168.3.27:/mytest.git
Initialized empty Git repository in /root/mytest/.git/
warning: You appear to have cloned an empty repository.
# ll
total 3240
drwxr-xr-x 3 root root    4096 Apr 17 14:45 mytest
# cd mytest/
# git status
# On branch master#
# Initial commit
#nothing to commit (create/copy files and use "git add" to track)

#创建1个文件1.txt并添加到git
# touch 1.txt
# git add 1.txt
# git commit "add file 1.txt"

#第一次使用需要表明身份
# git commit -m "add file 1.txt"
add file 1.txt
Committer: root <root@ipython.(none)>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:   
    git config --global user.name "Your Name"   
    git config --global user.email you@example.com
If the identity used for this commit is wrong, you can fix it with:
   git commit --amend --author='Your Name <you@example.com>'
    0 files changed, 0 insertions(+), 0 deletions(-)
    create mode 100644 1.txt

# git config --global user.email test@aaa.com
# git config --global user.name test

# git commit -m "add file 1.txt"
# On branch masternothing to commit (working directory clean)

# git status
# On branch masternothing to commit (working directory clean)

# ll
total 0-rw-r--r-- 1 root root 0 Apr 17 14:47 1.txt

# git push origin master
Counting objects: 3, done.Writing objects: 100% (3/3), 206 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)To git@192.168.3.27:/mytest.git
*       master -> master



页: [1]
查看完整版本: CentOS 6.4x64安装git和gitolite服务器