centos搭建git服务器(上)

AndyYang| 阅读:2294 发表时间:2016-03-28 20:15:13 linux版本管理
摘要:Git是一个开源的分布式版本控制系统,用以有效、高速的处理从很小到非常大的项目版本管理。Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。

[root@163-44-167-134 ~]# yum -y install git
#查看git版本号
[root@163-44-167-134 ~]# git --vistion
#gitosis为Git用户权限管理系统,通过管理服务端的/home/git/.ssh/authorized_key文件来执行对用户权限的管理,是一个python模块包
[root@163-44-167-134 ~]# yum -y install python python-setuptools
[root@163-44-167-134 ~]# git clone git://github.com/res0nat0r/gitosis.git
[root@163-44-167-134 ~]# cd gitosis/
[root@163-44-167-134 ~]# python setup.py install
#显示Finished processing dependencies for gitosis==0.2即表示成功
#添加git用户
[root@163-44-167-134 ~]# useradd git  
[root@163-44-167-134 ~]# su git
[git@163-44-167-134 root]$ cd ~
#git管理用户生产密钥并上传到服务器端
#有些人把git管理用户和git服务端放在两台服务器,完全没必要
[git@163-44-167-134 ~]$ ssh-keygen -t rsa
[git@163-44-167-134 ~]$ gitosis-init <~/.ssh/id_rsa.pub
#报错
Traceback (most recent call last):
  File "/usr/bin/gitosis-init", line 9, in <module>
    load_entry_point('gitosis==0.2', 'console_scripts', 'gitosis-init')()
  File "/usr/lib/python2.7/site-packages/gitosis-0.2-py2.7.egg/gitosis/app.py", line 24, in run
    return app.main()
  File "/usr/lib/python2.7/site-packages/gitosis-0.2-py2.7.egg/gitosis/app.py", line 38, in main
    self.handle_args(parser, cfg, options, args)
  File "/usr/lib/python2.7/site-packages/gitosis-0.2-py2.7.egg/gitosis/init.py", line 123, in handle_args
    user = ssh_extract_user(pubkey)
  File "/usr/lib/python2.7/site-packages/gitosis-0.2-py2.7.egg/gitosis/init.py", line 39, in ssh_extract_user
    raise InsecureSSHKeyUsername(repr(user))
gitosis.init.InsecureSSHKeyUsername: Username contains not allowed characters: 'git@163-44-167-134'
[git@163-44-167-134 ~]$ vim ~/.ssh/id_rsa.pub
#将证书末尾的 git@163-44-167-134 改成  git@localhost
#这一步不报错的可以无视
[git@163-44-167-134 ~]$ gitosis-init <~/.ssh/id_rsa.pub
Initialized empty Git repository in /home/git/repositories/gitosis-admin.git/
Reinitialized existing Git repository in /home/git/repositories/gitosis-admin.git/
[git@163-44-167-134 ~]$ ls
gitosis  repositories
[git@163-44-167-134 ~]$ mkdir github
[git@163-44-167-134 ~]$ cd github/
[git@163-44-167-134 github]$ git clone git@163.44.167.134:gitosis-admin.git
Cloning into 'gitosis-admin'...
The authenticity of host '163.44.167.134 (163.44.167.134)' can't be established.
ECDSA key fingerprint is a1:e3:dc:f2:aa:49:3b:5f:9f:93:0f:dd:6e:d4:ed:32.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '163.44.167.134' (ECDSA) to the list of known hosts.
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.
#这样就克隆了配置
[git@163-44-167-134 github]$ cd gitosis-admin/
[git@163-44-167-134 gitosis-admin]$ ls
gitosis.conf  keydir
#gitosis.conf为配置项目和用户文件,keydir为公钥目录
[git@163-44-167-134 gitosis-admin]$ vim gitosis.conf
[gitosis]

[group gitosis-admin]
members = git@localhost
writable = gitosis-admin
#修改下(添加一个项目)
[group github]
writable = github
members = git@localhost
[git@163-44-167-134 gitosis-admin]$ cd ../../repositories/
[git@163-44-167-134 repositories]$ mkdir github.git
[git@163-44-167-134 repositories]$ cd github.git/
#初始化一个项目
[git@163-44-167-134 github.git]$ git init --bare
Initialized empty Git repository in /home/git/repositories/github.git/
[git@163-44-167-134 root]$ cd ~
[git@163-44-167-134 ~]$ mkdir test
[git@163-44-167-134 ~]$ cd test/
[git@163-44-167-134 test]$ git clone git@163.44.167.134:github.git
Cloning into 'github'...
warning: You appear to have cloned an empty repository.
[git@163-44-167-134 github]$ touch test1.txt
#添加
[git@163-44-167-134 github]$ git add .
#提交
[git@163-44-167-134 github]$ git commit -a -m "granted jay commit rights to git-test"
#报错
fatal: Not a git repository (or any of the parent directories): .git
[git@163-44-167-134 github]$ cd gitosis-admin/
[git@163-44-167-134 gitosis-admin]$ git add .
[git@163-44-167-134 gitosis-admin]$ git commit -a -m "granted jay commit rights to git-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: empty ident name (for <git@163-44-167-134.(none)>) not allowed
#随便写
[git@163-44-167-134 gitosis-admin]$ git config --global user.name "gituser"    
[git@163-44-167-134 gitosis-admin]$ git config --global user.email "gituser@gituser.com"
#再次提交
[git@163-44-167-134 github]$ git commit -a -m "granted jay commit rights to git-test"
[master (root-commit) dc1958d] granted jay commit rights to git-test
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 test1.txt
#提交到主版本
[git@163-44-167-134 gitosis-admin]$ git push origin master

以上都是在一台服务器上操作,不过两个用户而已。此处git服务端搭建完成。

参考1:http://blog.csdn.net/tantexian/article/details/37724377 (按照这个搭了一天都没搭起来,衰~)
参考2:http://blog.csdn.net/xluren/article/details/28419467

本文为AndyYang原创,转载请注明出处!
如果您觉得好,可以打赏作者:
如果您觉得累了,是否想看点美女养养眼:猛戳>>朋友帮
如果您觉得皮了,是否想来点神吐槽:猛戳>>iPhone查询中

已有1条评论

昵称:
邮箱:

  • 最新评论

程欢2016-04-08 10:46:55
不错,受益了~
iPhone查询中 - bbs.ipcxz.com 朋友帮 - www.pengyb.cn iPhone查询中 - bbs.ipcxz.com
反馈
微信订阅号