前阵子公司须要,让我搭个Git服务器,把以前用的SVN上代码迁移到git上去,因此就在阿里云主机上搭了一个,记录了下安装过程,留存文档以备查阅。本篇本章只涉及搭建部分的操做,更多git的使用能够参考文档。python
hadoop-slave 192.168.186.129
系统版本信息git
[root@hadoop-slave ~]# cat /etc/redhat-release CentOS release 6.4 (Final)
[root@hadoop-slave ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel -y
git-1.7.1
,要移除一下。Git安装[root@hadoop-slave ~]# git --version git version 1.7.1 [root@hadoop-slave ~]# yum remove git -y
下载源码包 github
[root@hadoop-slave ~]# wget https://www.kernel.org/pub/software/scm/git/git-2.5.0.tar.gz [root@hadoop-slave ~]# tar -zxf git-2.5.0.tar.gz [root@hadoop-slave ~]# cd git-2.5.0 [root@hadoop-slave git-2.5.0]# ./configure --prefix=/usr/local/git [root@hadoop-slave git-2.5.0]# make && make install [root@hadoop-slave git-2.5.0]# ln -s /usr/local/git/bin/* /usr/bin/ [root@hadoop-slave git-2.5.0]# git --version #显示版本号,安装成功 git version 2.5.0 [root@hadoop-slave git-2.5.0]#
Gitosis配置 vim
权限管理工具gitosis的安装,须要用到python-setuptools
windows
[root@hadoop-slave ~]# yum install python python-setuptools [root@hadoop-slave ~]# git clone git://github.com/res0nat0r/gitosis.git [root@hadoop-slave ~]# cd gitosis/ [root@hadoop-slave gitosis]# python setup.py install …… Using /usr/lib/python2.6/site-packages Finished processing dependencies for gitosis==0.2 #安装成功
管理git服务器须要一些管理者,能够经过上传开发者机器的公钥到服务器,添加成为git服务器的管理者。
如下是把windows机器做为git的管理者,在git bash
生成公钥并上传至服务器的过程。bash
$ssh-keygen -t rsa #一路回车,不须要设置密码 $scp ~/.ssh/id_rsa.pub root@192.168.186.129:~
登陆服务器 服务器
[root@hadoop-slave ~]# ls id_rsa.pub
id_rsa.pub
服务器上生成git用户,使用git用户并初始化gitosis
建立git版本管理用户 gitssh
[root@hadoop-slave ~]# useradd -c "git version manager" -m -d /home/git -s /bin/bash git [root@hadoop-slave ~]# passwd git
初始化gitosiscurl
[root@hadoop-slave ~]# mv id_rsa.pub /home/git/ [root@hadoop-slave ~]# su git [git@hadoop-slave root]$ cd [git@hadoop-slave ~]$ gitosis-init < ./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@hadoop-slave ~]$ chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update #添加权限
ok了,服务器端配置就ok了,下一步在开发者机器上配置 工具
服务端配置完毕,如今转到管理客户端,进入管理机器(上传公钥的机器),打开git bash
$mkdir ~/gitrepo $cd gitrepo $git clone git@123.56.138.94:gitosis-admin.git #克隆项目管理仓库
问题1:
PS:若是clone报错了,密钥的问题和git用户密码的问题,(使用绝对路径/home/git/repositories/gitosis-admin.git能够下载,可是不推荐)
查看gitosis.conf中密钥的members
的名称为是不是管理机器的主机名.pub
。
管理文件clone下来后,能够对项目进行管理。若要先建立一个新项目,要在gitosis-admin.git的配置文件中添加项目,并提交到git服务器告诉服务器我有个新项目。
$cd ~/gitrepo/gitosis-admin $vim gitosis.conf [group test] # 具备写权限的组名称 writable = test # 该组可写的项目名称 members = liuyan@liuyan-pc #有写权限的组成员
提交到服务器
$git add . $git commit -a -m "add test repo" $git push
管理文件提交后,本地建立的新项目test就能够提交到远程仓库了。
$cd ~/repo
$mkdir test
$cd test #对于新的项目,须要先在本地初始化为 Git 项目,添加要管理的文件并做首次提交
$git init
$touch readme
提交到远程服务器
$git add . $git commit -a -m "init test" $git remote add origin git@192.168.186.129:test.git $git push origin master
git push origin master的意思就是上传本地当前分支代码到master分支。git push是上传本地全部分支代码到远程对应的分支上
服务端查看
[git@hadoop-slave repositories]$ ls
gitosis-admin.git test.git
test仓库已经存在,能够进行操做了。
项目的开发人员通常不止一个,就要添加项目协同开发者。这里须要协同开发者的公钥,上传至git服务器。
$cd ~/gitrepo/gitosis-admin/keydir $ mv ~/id_rsa.pub liuyan@zizhuoy.pub #修改公钥为`主机名.pub` $vim gitosis.conf #添加成员 [group test] writable = test members = liuyan@liuyan-pc liuyan@zizhuoy
而后将添加数据后的目录更新到git服务器
$git add keydir/liuyan@zizhuoy.pub $git commit -am " granted liuyan@zizhuoy commit rights to test " $git push
注解:gitosis其实是从服务器端的/home/git/repositories/gitosis-admin/.gitosis.conf文件读取信息的,经过以上操做,会将新的权限信息写入到该文件中,若是搞错了配置,致使失去了推送权限,能够经过修改该文件来从新设定,若是你手工编辑该文件的话,它会一直保持到下次向 gitosis-admin 推送新版本的配置内容为止。
推送完成后,新加的协同开发者就能够进行项目的开发了。
转自
Centos 6.4搭建git服务器 | Yan's bloghttp://yanliu.org/2015/08/20/Centos-6-4%E6%90%AD%E5%BB%BAgit%E6%9C%8D%E5%8A%A1%E5%99%A8/