前阵子公司需要,让我搭个Git服务器,把之前用的SVN上代码迁移到git上去,所以就在阿里云主机上搭了一个,记录了下安装过程,留存文档以备查阅。本篇本章只涉及搭建部分的操作,更多git的使用可以参考文档

系统环境

主机环境

hadoop-slave    192.168.186.129

系统版本信息

[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

Centos系统会默认安装一个git-1.7.1,要移除一下。Git安装

[root@hadoop-slave ~]# git --version
git version 1.7.
[root@hadoop-slave ~]# yum remove git -y

下载源码包

[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..tar.gz
[root@hadoop-slave ~]# cd git-2.5.
[root@hadoop-slave git-2.5.]# ./configure --prefix=/usr/local/git
[root@hadoop-slave git-2.5.]# make && make install
[root@hadoop-slave git-2.5.]# 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配置

Gitosis安装

权限管理工具gitosis的安装,需要用到python-setuptools

[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./site-packages
Finished processing dependencies for gitosis==0.2 #安装成功

公钥管理

管理git服务器需要一些管理者,可以通过上传开发者机器的公钥到服务器,添加成为git服务器的管理者。
以下是把windows机器作为git的管理者,在git 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

Gitosis初始化

服务器上生成git用户,使用git用户并初始化gitosis
创建git版本管理用户 git

[root@hadoop-slave ~]# useradd -c "git version manager" -m -d /home/git -s /bin/bash git
[root@hadoop-slave ~]# passwd git

初始化gitosis

[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 /home/git/repositories/gitosis-admin.git/hooks/post-update #添加权限

ok了,服务器端配置就ok了,下一步在开发者机器上配置

Git项目管理

Clone项目管理仓库

服务端配置完毕,现在转到管理客户端,进入管理机器(上传公钥的机器),打开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 blog
http://yanliu.org/2015/08/20/Centos-6-4%E6%90%AD%E5%BB%BAgit%E6%9C%8D%E5%8A%A1%E5%99%A8/

Centos 6.4搭建git服务器【转】的更多相关文章

  1. CentOS 6.4 搭建git 服务器

    CentOS 6.4 搭建git 服务器 (2013-11-22 19:04:09)转载▼ 标签: it 分类: Linux 此文件是依据markdown所编写,更好效果参见本人github的文档ht ...

  2. 在CentOS 7中搭建Git服务器

    环境说明 - CentOS 7.x 最小安装 - 配置网络连接 1. 安装Git及创建用户 # 安装Git $ yum install git # 创建一个git用户组和用户,用来运行git服务 $ ...

  3. 自定义Git之使用centos搭建git 服务器

    Github 公开的项目是免费的,但是如果你不想让其他人看到你的项目就需要收费. 这时我们就需要自己搭建一台Git服务器作为私有仓库使用. 接下来我们将以 Centos 为例搭建 Git 服务器. 1 ...

  4. centos 搭建git服务器

    centos 6搭建git服务器 安装 rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-6.noarch.rpm yum ins ...

  5. 在CentOS搭建Git服务器 转

    在CentOS搭建Git服务器 来自 :http://www.jianshu.com/p/69ea5ded3ede 前言 我们可以GitHub发布一些开源代码的公共仓库,但对于私密仓库就需要收费了.公 ...

  6. CentOs上搭建git服务器

    CentOs上搭建git服务器 首先安装setuptools wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0 ...

  7. CentOS搭建Git服务器及权限管理

    声明:本教程,仅作为配置的记录,细节不展开,需要您有一点linux的命令基础,仅作为配置参考. 1. 系统环境 系统: Linux:CentOS 7.2 64位 由于CentOS已经内置了OpenSS ...

  8. 搭建 Git 服务器(基于 CentOS 7)

    服务器上的-Git-架设服务器-官网参考 对于规模比较小的团队,可以直接搭建 Git 服务器,逐个收集研发同学的证书配置进来即可.如果团队规模比较大,可以直接采用 GitLab.Drone 等现成的带 ...

  9. 在centos搭建git服务器时,不小心把/home/git目录删除了,我是怎么恢复的

    在centos搭建git服务器时,不小心把/home/git目录删除了,我是怎么恢复的 在删除掉/home/git目录后,每次 git push提交时,都让填写密码,烦 第一步:在本地找到id_rsa ...

随机推荐

  1. bzoj2429- 聪明的猴子

    题意其实就是说有很多个点,求一组边把它们都连接起来,并且最大的那条边最小.很明显这就是一个最小生成树,是一颗保证最长边最短的树. 代码 刚刚学了个Borůvka算法,于是写了两个. Borůvka # ...

  2. bzoj1093[ZJOI2007]最大半连通子图(tarjan+拓扑排序+dp)

    Description 一个有向图G=(V,E)称为半连通的(Semi-Connected),如果满足:?u,v∈V,满足u→v或v→u,即对于图中任意两点u,v,存在一条u到v的有向路径或者从v到u ...

  3. BZOJ4881 线段游戏(二分图+树状数组/动态规划+线段树)

    相当于将线段划分成两个集合使集合内线段不相交,并且可以发现线段相交等价于逆序对.也即要将原序列划分成两个单增序列.由dilworth定理,如果存在长度>=3的单减子序列,无解,可以先判掉. 这个 ...

  4. lxm --- ans lb config

    lxm --- ans lb config #ANS2.2 Build 160.006 # Last modified by `save config`, Fri Oct 12 17:15:42 20 ...

  5. 【BZOJ4405】【WC2016】挑战NPC(带花树)

    [BZOJ4405][WC2016]挑战NPC(带花树) 题面 BZOJ 洛谷 Uoj Description 小N最近在研究NP完全问题,小O看小N研究得热火朝天,便给他出了一道这样的题目: 有n个 ...

  6. 大坑!有网,电脑qq登不上去!!

    手机qq --> 设置 --> 账号设备安全 -->  允许手机电脑同步在线 或是其他设置干扰导致

  7. position:fixed 相对父元素定位

    position:fixed是对于浏览器窗口定位的,要实现相当于父元素定位,可以这样: 不设置fixed元素的top,bottom,left,right,只设置margin来实现. 这种方法本质上fi ...

  8. 【bzoj2759】一个动态树好题

    Portal -->bzoj2759 Solution 哇我感觉这题真的qwq是很好的一题呀qwq 很神qwq反正我真的是自己想怎么想都想不到就是了qwq 首先先考虑一下简化版的问题应该怎么解决 ...

  9. TCP粘包处理

    TCP(transport control protocol,传输控制协议)是面向连接的,面向流的,提供高可靠性服务.收发两端(客户端和服务器端)都要有一一成对的socket, 因此,发送端为了将多个 ...

  10. 手脱EXE32Pack v1.39

    1.PEID查壳 EXE32Pack v1.39 2.载入OD,先F8跟一下 0040A00C > 3BC0 cmp eax,eax ; //程序入口点 0040A00E je short st ...