首页 > 代码库 > CentOS搭建GIT服务器

CentOS搭建GIT服务器

1、安装GIT核心

wget https://www.kernel.org/pub/software/scm/git/git-2.0.0.tar.gz
tar -zvxf git-2.0.0.tar.gz 解压

进入git解压目录,然后配置、安装:

autoconf
./configure --with-curl=/usr/local
make
sudo make install

报错

/usr/bin/perl Makefile.PL PREFIX=/usr/local INSTALL_BASE=‘‘ --localedir=/usr/local/share/locale
Cant locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /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 Makefile.PL line 3.
BEGIN failed--compilation aborted at Makefile.PL line 3.
make[1]: *** [perl.mak] 错误 2
make: *** [perl/perl.mak] 错误 2

看起来应该是perl的问题,perl-version发现perl已经安装了,google一把,是perl的一个包的问题,参见右边解决了:http://my.oschina.net/indestiny/blog/223082

 yum install perl-ExtUtils-MakeMaker package

然后继续  make && make install

安装后显示信息:

make[1]: Leaving directory `/usr/local/git-2.0.0/git-guibindir=$(cd /usr/local/bin && pwd) &&         execdir=$(cd /usr/local/libexec/git-core && pwd) &&         { test "$bindir/" = "$execdir/" ||           for p in git git-shell git-upload-pack git-cvsserver; do                 rm -f "$execdir/$p" &&                 test -z "" &&                 ln "$bindir/$p" "$execdir/$p" 2>/dev/null ||                 cp "$bindir/$p" "$execdir/$p" || exit;           done;         } &&         for p in git-receive-pack git-upload-archive; do                 rm -f "$bindir/$p" &&                 test -z "" &&                 ln "$bindir/git" "$bindir/$p" 2>/dev/null ||                 ln -s "git" "$bindir/$p" 2>/dev/null ||                 cp "$bindir/git" "$bindir/$p" || exit;         done &&         for p in  git-add git-annotate git-apply git-archive git-bisect--helper git-blame git-branch git-bundle git-cat-file git-check-attr git-check-ignore git-check-mailmap git-check-ref-format git-checkout-index git-checkout git-clean git-clone git-column git-commit-tree git-commit git-config git-count-objects git-credential git-describe git-diff-files git-diff-index git-diff-tree git-diff git-fast-export git-fetch-pack git-fetch git-fmt-merge-msg git-for-each-ref git-fsck git-gc git-get-tar-commit-id git-grep git-hash-object git-help git-index-pack git-init-db git-log git-ls-files git-ls-remote git-ls-tree git-mailinfo git-mailsplit git-merge git-merge-base git-merge-file git-merge-index git-merge-ours git-merge-recursive git-merge-tree git-mktag git-mktree git-mv git-name-rev git-notes git-pack-objects git-pack-redundant git-pack-refs git-patch-id git-prune-packed git-prune git-push git-read-tree git-receive-pack git-reflog git-remote git-remote-ext git-remote-fd git-repack git-replace git-rerere git-reset git-rev-list git-rev-parse git-revert git-rm git-send-pack git-shortlog git-show-branch git-show-ref git-stripspace git-symbolic-ref git-tag git-unpack-file git-unpack-objects git-update-index git-update-ref git-update-server-info git-upload-archive git-var git-verify-pack git-verify-tag git-write-tree git-cherry git-cherry-pick git-format-patch git-fsck-objects git-init git-merge-subtree git-show git-stage git-status git-whatchanged; do                 rm -f "$execdir/$p" &&                 test -z "" &&                 ln "$execdir/git" "$execdir/$p" 2>/dev/null ||                 ln -s "git" "$execdir/$p" 2>/dev/null ||                 cp "$execdir/git" "$execdir/$p" || exit;         done &&         remote_curl_aliases="git-remote-https git-remote-ftp git-remote-ftps" &&         for p in $remote_curl_aliases; do                 rm -f "$execdir/$p" &&                 test -z "" &&                 ln "$execdir/git-remote-http" "$execdir/$p" 2>/dev/null ||                 ln -s "git-remote-http" "$execdir/$p" 2>/dev/null ||                 cp "$execdir/git-remote-http" "$execdir/$p" || exit;         done &&         ./check_bindir "z$bindir" "z$execdir" "$bindir/git-add"

然后查看一下:

[root@bxcs_repository local]# git
usage: git [--version] [--help] [-C <path>] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

最常用的 git 命令有:
   add        添加文件内容至索引
   bisect     通过二分查找定位引入 bug 的变更
   branch     列出、创建或删除分支
   checkout   检出一个分支或路径到工作区
   clone      克隆一个版本库到一个新目录
   commit     记录变更到版本库
   diff       显示提交之间、提交和工作区之间等的差异
   fetch      从另外一个版本库下载对象和引用
   grep       输出和模式匹配的行
   init       创建一个空的 Git 版本库或重新初始化一个已存在的版本库
   log        显示提交日志
   merge      合并两个或更多开发历史
   mv         移动或重命名一个文件、目录或符号链接
   pull       获取并整合另外的版本库或一个本地分支
   push       更新远程引用和相关的对象
   rebase     本地提交转移至更新后的上游分支中
   reset      重置当前HEAD到指定状态
   rm         从工作区和索引中删除文件
   show       显示各种类型的对象
   status     显示工作区状态
   tag        创建、列出、删除或校验一个GPG签名的 tag 对象

命令 git help -agit help -g 显示可用的子命令和一些指南。参见
git help <命令>git help <指南> 来查看给定的子命令帮助或指南。

[root@bxcs_repository local]# git --version
git version 2.0.0

安装成功了。

2、安装openssl等

yum install  -y gettext-devel expat-devel curl-devel zlib-devel openssl-devel

3、安装python setuptools包

yum install python python-setuptools

4、用我们刚刚安装的git下载gitosis并安装:

下载
git clone git://github.com/res0nat0r/gitosis.git
进入
cd gitosis/
用刚安装的python 安装gitosis
python setup.py install

5、本地生成key,公钥上传到server上:

ssh-keygen -t rsa

6、新建git管理员用户,初始化:

 adduser git # 新增一个git用户
su - git # 切换git用户
[git@bxcs_repository gitosis]$ gitosis-init <tempPubKeys/id_rsa.pub
初始化空的 Git 版本库于 /home/git/repositories/gitosis-admin.git/
重新初始化现存的 Git 版本库于 /home/git/repositories/gitosis-admin.git/

上面的初始化,已经将本地公钥初始化到gitosis中,本地机器成为管理员权限机器。

必须以git用户初始化,否则后来clone gitosis-admin.git时会有问题,必须输密码!(主要是仓库地址要放在/home/git/repositories/gitosis-admin.git/,而不是/home/repositories/gitosis-admin.git/)

7、本地下载管理端

在本地下载server上的管理端:

 git clone git@192.168.3.30:gitosis-admin.git

然后看看配置文件:

Administrator@HG-20140421APSR /usr/local/gitosis-admin
$ cat gitosis.conf
[gitosis]

[group gitosis-admin]  #组名
writable = gitosis-admin  #项目名
members = Administrator@HG-20140421APSR #团队成员名(必须和密钥名一致),多个用空格隔开

密钥:

$ ls keydir/
Administrator@HG-20140421APSR.pub

 

 

9、新建项目:

先加权限:

先在gitosis.conf中添加如下分组、成员信息:

[group bxcs]
writable = bxcs
members = xxx@xxx Administrator@HG-20140421APSR

然后在keydir中添加公钥

提交到admin项目:

git add .
git commit -m "修改权限,创建XXXX项目"
git push

 

初始化项目:

进入我们的项目工作空间

#初始化
git init
git add .
git commit -m "初始化项目"

#然后提交!
git remote add origin git@192.168.X.XX:bxcs.git
git push origin master

或者用下面一行提交:

git push git@192.168.x.xx:bxcs.git master

OK

 

 

搭建过程参考了:

http://zwm-xl.blog.sohu.com/170050241.html

http://blog.sina.com.cn/s/blog_904dee7f0101gait.html

http://blog.csdn.net/ice520301/article/details/6142503