阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 6.5 + Git 1.8.3.1 + Gitosis 构建Git服务器

219次阅读
没有评论

共计 14226 个字符,预计需要花费 36 分钟才能阅读完成。

环境:

Git Sserver

IP:192.168.40.128

Git Client

IP:192.168.40.134

—————————————–

推荐阅读

Fedora 通过 Http Proxy 下载 Git http://www.linuxidc.com/Linux/2009-12/23170.htm

在 Ubuntu Server 上安装 Git http://www.linuxidc.com/Linux/2009-06/20421.htm

服务器端 Git 仓库的创建(Ubuntu)http://www.linuxidc.com/Linux/2011-02/32542.htm

Linux 下 Git 简单使用教程(以 Android 为例)http://www.linuxidc.com/Linux/2010-11/29883.htm

Git 权威指南 PDF 高清中文版 http://www.linuxidc.com/Linux/2013-10/91053.htm

_——在 Git Sserver 配置 Git 环境

1)安装软件所需依赖包

[root@Git ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel Python python-setuptools -y

2)安装 git

[root@Git ~]# mkdir /tmp/soft/

[root@Git ~]# cd /tmp/soft/

[root@Git soft]# tar zfvx git-1.8.3.1-linux-1374045102000.tar.gz

[root@Git git-1.8.3.1]# make prefix=/usr/local/git all

[root@Git git-1.8.3.1]# make prefix=/usr/local/git install

[root@Git git-1.8.3.1]# ln -s /usr/local/git/bin/* /usr/bin/

[root@Git git-1.8.3.1]# git –version

git version 1.8.3.1    #表示安装成功

3)安装 gitosis

[root@Git git-1.8.3.1]# cd /usr/local/

[root@Git local]# it clone git://github.com/res0nat0r/gitosis.git

-bash: it: command not found

[root@Git local]# git clone git://github.com/res0nat0r/gitosis.git

正克隆到 ‘gitosis’…

remote: Reusing existing pack: 727, done.

remote: Total 727 (delta 0), reused 0 (delta 0)

接收对象中: 100% (727/727), 179.60 KiB | 104.00 KiB/s, done.

处理 delta 中: 100% (407/407), done.

[root@Git local]# cd gitosis

[root@Git gitosis]# python setup.py install

running install

running bdist_egg

running egg_info

creating gitosis.egg-info

writing requirements to gitosis.egg-info/requires.txt

writing gitosis.egg-info/PKG-INFO

writing top-level names to gitosis.egg-info/top_level.txt

writing dependency_links to gitosis.egg-info/dependency_links.txt

writing entry points to gitosis.egg-info/entry_points.txt

writing manifest file ‘gitosis.egg-info/SOURCES.txt’

reading manifest file ‘gitosis.egg-info/SOURCES.txt’

reading manifest template ‘MANIFEST.in’

writing manifest file ‘gitosis.egg-info/SOURCES.txt’

installing library code to build/bdist.linux-x86_64/egg

running install_lib

running build_py

creating build

creating build/lib

creating build/lib/gitosis

copying gitosis/gitweb.py -> build/lib/gitosis

copying gitosis/gitdaemon.py -> build/lib/gitosis

copying gitosis/init.py -> build/lib/gitosis

copying gitosis/run_hook.py -> build/lib/gitosis

copying gitosis/access.py -> build/lib/gitosis

copying gitosis/snagit.py -> build/lib/gitosis

copying gitosis/util.py -> build/lib/gitosis

copying gitosis/ssh.py -> build/lib/gitosis

copying gitosis/repository.py -> build/lib/gitosis

copying gitosis/group.py -> build/lib/gitosis

copying gitosis/app.py -> build/lib/gitosis

copying gitosis/__init__.py -> build/lib/gitosis

copying gitosis/serve.py -> build/lib/gitosis

copying gitosis/mirror.py -> build/lib/gitosis

creating build/lib/gitosis/test

copying gitosis/test/test_repository.py -> build/lib/gitosis/test

copying gitosis/test/test_init.py -> build/lib/gitosis/test

copying gitosis/test/util.py -> build/lib/gitosis/test

copying gitosis/test/test_access.py -> build/lib/gitosis/test

copying gitosis/test/test_group.py -> build/lib/gitosis/test

copying gitosis/test/test_mirror.py -> build/lib/gitosis/test

copying gitosis/test/test_run_hook.py -> build/lib/gitosis/test

copying gitosis/test/test_serve.py -> build/lib/gitosis/test

copying gitosis/test/test_ssh.py -> build/lib/gitosis/test

copying gitosis/test/__init__.py -> build/lib/gitosis/test

copying gitosis/test/test_gitweb.py -> build/lib/gitosis/test

copying gitosis/test/test_gitdaemon.py -> build/lib/gitosis/test

creating build/lib/gitosis/templates

copying gitosis/templates/__init__.py -> build/lib/gitosis/templates

creating build/lib/gitosis/templates/admin

creating build/lib/gitosis/templates/admin/hooks

copying gitosis/templates/admin/hooks/post-update -> build/lib/gitosis/templates/admin/hooks

creating build/lib/gitosis/templates/default

creating build/lib/gitosis/templates/default/hooks

copying gitosis/templates/default/hooks/post-receive -> build/lib/gitosis/templates/default/hooks

creating build/bdist.linux-x86_64

creating build/bdist.linux-x86_64/egg

creating build/bdist.linux-x86_64/egg/gitosis

copying build/lib/gitosis/gitweb.py -> build/bdist.linux-x86_64/egg/gitosis

copying build/lib/gitosis/gitdaemon.py -> build/bdist.linux-x86_64/egg/gitosis

copying build/lib/gitosis/init.py -> build/bdist.linux-x86_64/egg/gitosis

copying build/lib/gitosis/run_hook.py -> build/bdist.linux-x86_64/egg/gitosis

copying build/lib/gitosis/access.py -> build/bdist.linux-x86_64/egg/gitosis

copying build/lib/gitosis/snagit.py -> build/bdist.linux-x86_64/egg/gitosis

copying build/lib/gitosis/util.py -> build/bdist.linux-x86_64/egg/gitosis

creating build/bdist.linux-x86_64/egg/gitosis/test

copying build/lib/gitosis/test/test_repository.py -> build/bdist.linux-x86_64/egg/gitosis/test

copying build/lib/gitosis/test/test_init.py -> build/bdist.linux-x86_64/egg/gitosis/test

copying build/lib/gitosis/test/util.py -> build/bdist.linux-x86_64/egg/gitosis/test

copying build/lib/gitosis/test/test_access.py -> build/bdist.linux-x86_64/egg/gitosis/test

copying build/lib/gitosis/test/test_group.py -> build/bdist.linux-x86_64/egg/gitosis/test

copying build/lib/gitosis/test/test_mirror.py -> build/bdist.linux-x86_64/egg/gitosis/test

copying build/lib/gitosis/test/test_run_hook.py -> build/bdist.linux-x86_64/egg/gitosis/test

copying build/lib/gitosis/test/test_serve.py -> build/bdist.linux-x86_64/egg/gitosis/test

copying build/lib/gitosis/test/test_ssh.py -> build/bdist.linux-x86_64/egg/gitosis/test

copying build/lib/gitosis/test/__init__.py -> build/bdist.linux-x86_64/egg/gitosis/test

copying build/lib/gitosis/test/test_gitweb.py -> build/bdist.linux-x86_64/egg/gitosis/test

copying build/lib/gitosis/test/test_gitdaemon.py -> build/bdist.linux-x86_64/egg/gitosis/test

copying build/lib/gitosis/ssh.py -> build/bdist.linux-x86_64/egg/gitosis

creating build/bdist.linux-x86_64/egg/gitosis/templates

creating build/bdist.linux-x86_64/egg/gitosis/templates/admin

creating build/bdist.linux-x86_64/egg/gitosis/templates/admin/hooks

copying build/lib/gitosis/templates/admin/hooks/post-update -> build/bdist.linux-x86_64/egg/gitosis/templates/admin/hooks

creating build/bdist.linux-x86_64/egg/gitosis/templates/default

creating build/bdist.linux-x86_64/egg/gitosis/templates/default/hooks

copying build/lib/gitosis/templates/default/hooks/post-receive -> build/bdist.linux-x86_64/egg/gitosis/templates/default/hooks

copying build/lib/gitosis/templates/__init__.py -> build/bdist.linux-x86_64/egg/gitosis/templates

copying build/lib/gitosis/repository.py -> build/bdist.linux-x86_64/egg/gitosis

copying build/lib/gitosis/group.py -> build/bdist.linux-x86_64/egg/gitosis

copying build/lib/gitosis/app.py -> build/bdist.linux-x86_64/egg/gitosis

copying build/lib/gitosis/__init__.py -> build/bdist.linux-x86_64/egg/gitosis

copying build/lib/gitosis/serve.py -> build/bdist.linux-x86_64/egg/gitosis

copying build/lib/gitosis/mirror.py -> build/bdist.linux-x86_64/egg/gitosis

byte-compiling build/bdist.linux-x86_64/egg/gitosis/gitweb.py to gitweb.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/gitdaemon.py to gitdaemon.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/init.py to init.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/run_hook.py to run_hook.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/access.py to access.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/snagit.py to snagit.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/util.py to util.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/test/test_repository.py to test_repository.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/test/test_init.py to test_init.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/test/util.py to util.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/test/test_access.py to test_access.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/test/test_group.py to test_group.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/test/test_mirror.py to test_mirror.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/test/test_run_hook.py to test_run_hook.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/test/test_serve.py to test_serve.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/test/test_ssh.py to test_ssh.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/test/__init__.py to __init__.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/test/test_gitweb.py to test_gitweb.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/test/test_gitdaemon.py to test_gitdaemon.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/ssh.py to ssh.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/templates/__init__.py to __init__.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/repository.py to repository.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/group.py to group.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/app.py to app.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/__init__.py to __init__.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/serve.py to serve.pyc

byte-compiling build/bdist.linux-x86_64/egg/gitosis/mirror.py to mirror.pyc

creating build/bdist.linux-x86_64/egg/EGG-INFO

copying gitosis.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO

copying gitosis.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO

copying gitosis.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO

copying gitosis.egg-info/entry_points.txt -> build/bdist.linux-x86_64/egg/EGG-INFO

copying gitosis.egg-info/not-zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO

copying gitosis.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO

copying gitosis.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO

creating dist

creating ‘dist/gitosis-0.2-py2.6.egg’ and adding ‘build/bdist.linux-x86_64/egg’ to it

removing ‘build/bdist.linux-x86_64/egg’ (and everything under it)

Processing gitosis-0.2-py2.6.egg

creating /usr/lib/python2.6/site-packages/gitosis-0.2-py2.6.egg

Extracting gitosis-0.2-py2.6.egg to /usr/lib/python2.6/site-packages

Adding gitosis 0.2 to easy-install.pth file

Installing gitosis-init script to /usr/bin

Installing gitosis-run-hook script to /usr/bin

Installing gitosis-serve script to /usr/bin

Installed /usr/lib/python2.6/site-packages/gitosis-0.2-py2.6.egg

Processing dependencies for gitosis==0.2

Searching for distribute==0.6.10

Best match: distribute 0.6.10

Adding distribute 0.6.10 to easy-install.pth file

Installing easy_install script to /usr/bin

Installing easy_install-2.6 script to /usr/bin

Using /usr/lib/python2.6/site-packages

Finished processing dependencies for gitosis==0.2        #说明安装成功

——配置秘钥并上传至 Git Server

1)在 Git Client 上创建秘钥

[root@Git-Client ~]# ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Created directory ‘/root/.ssh’.

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

d9:8e:54:e2:45:0b:40:db:4c:d2:07:c1:35:4f:ee:12 root@Git-Client

The key’s randomart image is:

+–[RSA 2048]—-+

|    .++=++ .    |

|      *oo.*    |

|      . +.E o    |

|      . * o    |

|        S o .    |

|      . o .    |

|        . .      |

|                |

|                |

+—————–+

2)上传至 Git Server

[root@Git-Client ~]# scp ~/.ssh/id_rsa.pub root@192.168.40.128:/tmp/

The authenticity of host ‘192.168.40.128 (192.168.40.128)’ can’t be established.

RSA key fingerprint is fe:5b:df:4d:ee:d2:e9:ed:2c:e1:df:eb:ed:da:84:7e.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added ‘192.168.40.128’ (RSA) to the list of known hosts.

root@192.168.40.128’s password:

id_rsa.pub                                    100%  397    0.4KB/s  00:00

3)在 Git Server 上生成 git 用户

[root@Git ~]# adduser  git

4)导入 Git Client 的秘钥

[root@Git ~]# su – git

[git@Git ~]$ gitosis-init < /tmp/id_rsa.pub

初始化空的 Git 版本库于 /home/git/repositories/gitosis-admin.git/

重新初始化现存的 Git 版本库于 /home/git/repositories/gitosis-admin.git/

5)删除秘钥

[git@Git ~]$ su –

密码:

[root@Git ~]# rm /tmp/id_rsa.pub

rm:是否删除普通文件 “/tmp/id_rsa.pub”?y

6)在 Git Client 上导出项目管理

[root@Git-Client ~]# mkdir -p /repo

[root@Git-Client ~]# cd /repo

[root@Git-Client repo]# git clone git@192.168.40.128:gitosis-admin.git

Initialized empty Git repository in /repo/gitosis-admin/.git/

remote: Counting objects: 5, done.

remote: Compressing objects: 100% (4/4), done.

remote: Total 5 (delta 0), reused 5 (delta 0)

Receiving objects: 100% (5/5), done.

7)增加以及设置管理项目

[root@Git-Client repo]# cd /repo/gitosis-admin

[root@Git-Client gitosis-admin]# more keydir/root\@Git-Client.pub

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0HRA7sVa910FO/juESVyKY7ZL2J9TQKFpffHeQAVFmhMl

cAv/4cf1NIY7GK4xYjjAPvh9xMTGHFX06n/XNOGvoRev/w/2qmHldwxXepgKXVsBbI5oNxD1UUt7GIst1

/AKERThbeWYWrl1HAZ64WxS88e5/nVU/ix2IE3MKhGg2A9JhvAzdXxqMLR2T2TdLqi11CQ5cQxKt17K0+

sTiTQzIY1kGwV6UKf9Rq0EZA94/iLxRkb8NSyw0ouZxoMqsyezXArtM5mM7p/RU/js7mgR62PiYiY9iQP

1p89UtIRmibfRB5dTEEJSCAYJ91+F7ZLFH9XcjSz4Md4pgNF9FZKWw== root@Git-Client

[root@Git-Client gitosis-admin]# vi gitosis.conf

[gitosis]

[group gitosis-admin]

writable = gitosis-admin

members = root@Git-Client

[group test-git]

writable = test-git

members = root@Git-Client

8)提交修改

# 一定要在 gitosis.conf 文件的目录下执行

[root@Git-Client gitosis-admin]# git add .

# 第一次修改添加一个用户和邮箱地址

[root@Git-Client gitosis-admin]# git config –global user.name test

[root@Git-Client gitosis-admin]# git config –global user.email test@163.com

[root@Git-Client gitosis-admin]# git commit -a -m “add test-git repo”

# On branch master

# Your branch is ahead of ‘origin/master’ by 1 commit.

#

nothing to commit (working directory clean)

[root@Git-Client gitosis-admin]# git push

Counting objects: 5, done.

Compressing objects: 100% (3/3), done.

Writing objects: 100% (3/3), 366 bytes, done.

Total 3 (delta 0), reused 0 (delta 0)

To git@192.168.40.128:gitosis-admin.git

  c2ecaf1..5e249ac  master -> master

9)初始化,增加以及使用 tes-git 项目

[root@Git-Client gitosis-admin]# cd /repo

[root@Git-Client repo]# mkdir test-git

[root@Git-Client repo]# cd test-git

[root@Git-Client test-git]# git init

Initialized empty Git repository in /repo/test-git/.git/

[root@Git-Client test-git]# touch test1 test2 test3

[root@Git-Client test-git]# touch readme

[root@Git-Client test-git]# git add .

[root@Git-Client test-git]# git commit -a -m “init test-git”

[master (root-commit) ef505cd] init test-git

 0 files changed, 0 insertions(+), 0 deletions(-)

 create mode 100644 readme

 create mode 100644 test1

 create mode 100644 test2

 create mode 100644 test3

[root@Git-Client test-git]# git remote add origin git@zgit:test-git.git

[root@Git-client user-git]# git push origin master

初始化空的 Git 版本库于 /home/git/repositories/test-git.git/

Counting objects: 3, done.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (3/3), 208 bytes, done.

Total 3 (delta 0), reused 0 (delta 0)

To git@192.168.40.128:test-git.git

 * [new branch]      master -> master

10)检测 Git Server 上面是否同步

[root@Git ~]# cd /home/git/repositories/

[root@Git repositories]# ls

gitosis-admin.git  test-git.git        #有同步 test-git 这个目录,说明成功。

Git 的详细介绍 :请点这里
Git 的下载地址 :请点这里

更多 CentOS 相关信息见 CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计14226字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中