网2112 发表于 2016-10-8 08:19:55

CentOS 6.7 Git 服务搭建及TortoiseGit配置连接

咳咳~好几天没写博文啦,这几天都在研究Git,没办法公司要要抛弃SVN转站Git,废话就不多说,下面我们进行操作演示:

环境:之前搭建的Redis-Master服务器一枚,配置一般般~
工具:TortoiseGit,传说中的小乌龟~

1、安装开发工具与依赖包

1
2
3
# yum groupinstall "Development tools"            \\安装下开发工具,也不是一定要装,只不过自己习惯装起来
===============\\安装依赖包=====================
# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel




2、安装Git

1
# yum install git




3、创建Git用户

1
2
3
4
5
6
7
8
9
10
11
# useradd git
\\切换到git,并且确保所在位置与用户名
# su - git
$ pwd
/home/git
$ whoami
git

\\查看.ssh是否存在,如果不存在请自行创建
$ ls -a
....bash_history.bash_logout.bash_profile.bashrcgitolite.tar.gz.ssh.viminfo




4、获取Git版本安装


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ git clone
$ ls
gitolite.tar.gz                \\由于下载速度实在慢,本人使用了线上服务器download并打包传到自己的实验小鸡上面
$ tar xf gitolite.tar.gz   \\解压缩
$ ls
gitolitegitolite.tar.gz

=========创建用户家目录及安装gitolite
$ mkdir $HOME/bin
$ $HOME/gitolite/install -to $HOME/bin
$ ls . bin/
.:
bingitolitegitolite.tar.gz

bin/:
commandsgitolitegitolite-shelllibsyntactic-sugartriggersVERSIONVREF




5、配置Gitolite管理员


1
2
3
4
5
$ ssh-keygen -t rsa\\这条为ssh密钥生成命令,我这边已经有了就直接使用了

$ /home/git/bin/gitolite setup -pk .ssh/id_rsa.pub    \\使用管理员公钥安装Gitolite
Initialized empty Git repository in /home/git/repositories/gitolite-admin.git/
Initialized empty Git repository in /home/git/repositories/testing.git/




6、生成管理员仓库gitolite-admin


1
2
3
4
5
6
7
8
9
10
11
12
$ git clone git@127.0.0.1:gitolite-admin
Initialized empty Git repository in /home/git/gitolite-admin/.git/
The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
RSA key fingerprint is 64:df:86:6c:e3:96:c3:52:80:a7:d8:af:27:4a:4c:80.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '127.0.0.1' (RSA) to the list of known hosts.
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (6/6), done.
$ ls
bingitolitegitolite-admingitolite.tar.gzprojects.listrepositories




7、了解gitolite-admin仓库配置及TortoiseGit安装及秘钥生成

1
2
3
4
5
6
7
8
9
10
$ cd gitolite-admin/
$ ls conf/ keydir/ .git/
conf/:
gitolite.conf

.git/:
branchesconfigdescriptionHEADhooksindexinfologsobjectspacked-refsrefs

keydir/:
id_rsa.pub





7.1 .git文件目录为git程序自动生成
7.2 conf名字上就知道是配置文件
7.3 keydir名字上也可以看出是存放key的文件目录
7.4 TortoiseGit安装及秘钥生成


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
7.2====================修改前============================
$ cat conf/gitolite.conf
repo gitolite-admin            \\这里就是定义我们之前第6点讲到的生成管理员仓库
    RW+   =   id_rsa      \\该id_rsa是我们之前安装用到的id_rsa.pub也是我们用来管控的账号,给名字可以重取,比如按照编号之类的

repo testing                   \\testing为project,系统自动会建立的一个测试的仓库
    RW+   =   @all         \\该@all用过svn的知道,这是一个输出组
=====================修改后==============================
$ vim conf/gitolite.conf

#############=====Groups======##################
   @dev_rw = sunshine         \\我新增的用户sunshine


repo gitolite-admin
    RW+   =   id_rsa

repo testing
    RW+   =   @all

repo dev
    RW+   =   @dev_rw      \\新增的输出组





1
2
3
4
5
6
7.3====================修改前============================
$ ls keydir/
id_rsa.pub                \\改名字我们可以自定义,在conf配置的用户就是去掉pub后的名称
=====================修改后==============================
$ ls keydir/
id_rsa.pubsunshine.pub   \\该秘钥使用TortoiseGit中的PuTTYgen生成,下面会介绍





7.4 TortoiseGit的安装及秘钥生成
进入https://tortoisegit.org/download/官网下载对应版本
安装,就是下一步下一步。

7.4.1 使用PuTTYgen生成秘钥,点击Genetate

7.4.2 鼠标记得要在Please 下面的框框移来移去,不然你就等很久才能生成完毕,这类似我们生成Linux ssh生成敲打键盘一样



7.4.3
1、在key comment后面输入 sunshine

2、把public框框下面的公钥复制到我们之前在keydir目录下的sunshine.pub里面

1
2
$ cat keydir/sunshine.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAgKGrcRSPcJE0o37svz0DqncT0cTyI9oGv8mmI9z00wSMumAq82gFdHC0xpVeFcdZQfNM7bsZlxGskEF7/W7p6P4Dc0RCiArcYaSWd0sj1+16ZQADARjFVzf5OBzQNy6OSbAKub/LS1fnl4W7Ad1Mq7wCAVpXzPWVINB3gbzecFekUJ42quqXju+/MtVIfipmEvsJnsOtCfUg5sHUFL7d0dBNgYhXoFPtpuFKS7ay/1dE9JPu83jUB+WkjW/VRIIMrXpAhHVfZ0W25B4cVS04TeNZuLlxAa4HdsI/CbEckzxYvdFDgTPhTqiVTMOFJwhzzUFCxGNlge4vfh1sZP14Ew== sunshine





3、点击Save private key 保存到我们指定的目录



7.5 在服务端执行如下命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$ git add conf/gitolite.conf            \\将gitolite.conf添加到暂存区
$ git add keydir                           \\将keydir添加到暂存区
$ git commit -m " New add sunshine.pub key and conf/gitolite.conf "    \\提交并说明内容
New add sunshine.pub key and conf/gitolite.conf
Committer: git <git@redis_master.(none)>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"                               \\初次提价交要求填写相应用户名
    git config --global user.email you@example.com                           \\初次提交会要求填写Email地址

If the identity used for this commit is wrong, you can fix it with:

    git commit --amend --author='Your Name <you@example.com>'

2 files changed, 8 insertions(+), 0 deletions(-)
create mode 100644 keydir/sunshine.pub
$ git config --global user.email "sunshineboysfz@iyunv.com"      \\全局填写用户名
$ git config --global user.name "sunshineboysfz"                  \\全局填写Email地址
$ git push                                                         \\同步到gitolite中的master去
Counting objects: 10, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 872 bytes, done.
Total 6 (delta 0), reused 0 (delta 0)
remote: Initialized empty Git repository in /home/git/repositories/dev.git/
To git@127.0.0.1:gitolite-admin
   2de3dc5..9d8a7e7master -> master





7.6 TortoiseGit连接配置
1、在windows目录(自己指定的地方)新建一个目录
2、邮件该文件,点击Git克隆
3、填写相应的信息,并且在加载PuTTY秘钥加载7.4.3的第三点,就是自己保持的私钥文件。最后点击确定



至此,CentOS+TortoiseGit+gitolite就搭建好啦,其实服务搭建看看就会,主要是使用。
页: [1]
查看完整版本: CentOS 6.7 Git 服务搭建及TortoiseGit配置连接