Ubuntu14.04环境中搭建属于自己的Git服务器

最近要开始源码环境搭建了。没有现成的环境只好自己搭建了。基于Ubuntu14.04搭建。理论上通用其他版本的Ubuntu。后续在整理一遍关于Git服务器下搭建Android源码版本管理。
在这里Git版本管理的好处就不过多介绍了。可以自行百度。这里就更细致的讲解一下搭建的流程。方便大家更快速的搭建属于自己的Git版本管理服务器。配置完成后Ubuntu登陆界面会多一个git用户登录。觉得碍眼的话可以参考我的前一篇文章Ubuntu14.10登录界面隐藏其他用户登录窗口。话不多说,开始我们的搭建之旅。
一、创建Git用户。
1、安装git-core、python-setuptools、openssh-server、openssh-client(python-setuptools主要用于安装gitosis。后两个软件主要是为了方便使用Putty直接登录到服务器)

sudo apt-get install git-core python-setuptools openssh-server openssh-client
  • 1

2、创建git用户并初git用户的始化密码

sudo useradd -m git
sudo passwd git
  • 1
  • 2

3、建立git用户使用的目录

sudo mkdir /home/repo
sudo chown git:git /home/repo
  • 1
  • 2

二、安装Gitosis软件。
1、安装Gitosis(为了统一管理,下边我会把几个重要的文件放在我建立的Tools目录中进行安装配置。)

mkdir Tools
cd Tools
git clone git://eagain.net/gitosis
(如果克隆失败用下面的地址)
git clone https://github.com/res0nat0r/gitosis.git

cd gitosis/
sudo python setup.py install
(切换到git用户)
su git 
(软链接目录)
ln -s /home/repo /home/git/repositories
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

2、生成管理员ssh公钥 ,并拷贝到服务器。
(在这里我是直接使用的服务器作为管理员,使用其他服务器原理一样)

 ssh-keygen -t rsa
 (直接回车即可)
 cp /home/XXX/.ssh/id_rsa.pub /tmp
 (尽量使用git用户拷贝,防止下一步初始化时读取不了公钥。)
  • 1
  • 2
  • 3
  • 4

这里写图片描述

其他用户作为管理员可以直接用优盘拷贝公钥到服务器或者直接通过命令拷贝

scp .ssh/id_rsa.pub git@<ServerIP>:/tmp
(此方法直接是使用的git用户拷贝。ServerIP为你的Git服务器ip。)
(如:scp .ssh/id_rsa.pub git@192.168.1.102:/tmp
  • 1
  • 2
  • 3

3、初始化Gitosis,让你的管理员公钥生效(在Git服务器上进行)。

 sudo -H -u git gitosis-init < /tmp/id_rsa.pub
  • 1

这里写图片描述

三、配置Gitosis、建立第一个属于自己的Git版本库。
1、使用管理员机器克隆Gitosis配置库(前边上传的谁的公钥谁就是管理员,后续也可以添加。)

git clone git@localhost:gitosis-admin.git
  • 1

这里写图片描述

2、服务器中建立“test.git”版本库
(GIt版本库统一在/home/git/repositories目录下,文件夹一定要以“.git”结尾

(切换到git用户)
su git 
(建立版本库“test.git”)
cd ~/repositories
mkdir test.git
(初始化test.git版本库)
cd test.git
git init --bare
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

3、管理员机器中配置“test.git”版本库。

cd gitosis-admin/
(gitosis.conf为配置文件、keydir为公钥文件夹)
vim gitosis.conf
  • 1
  • 2
  • 3

这里写图片描述

配置完毕提交配置信息
(公钥的命令一定要和公钥的名字一样,如下:后边的就是你的公钥名字,此时公钥的命名就为XXX.pub)
这里写图片描述

 git add gitosis.conf
 git commit -am "添加“test.git”版本库。"
  • 1
  • 2

第一次提交会让你填写你的身份


这里写图片描述

 git config --global user.email "你的邮箱@XXX.com"
 git config --global user.name "你的名字"
 (再次填写commit信息)
 git commit -am "添加“test.git”版本库。"
 git push origin master
  • 1
  • 2
  • 3
  • 4
  • 5

四、测试第一个属于自己的Git版本库。

 git clone git@localhost:test.git
 cd test
 echo "HelloWorld" > HelloWorld
 git add HelloWorld
 git commit -am "第一个提交记录"
 git push origin master
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值