Gitolite 部署GiT 仓库

简介

    gitolite 提供了便于部署git远程仓库的工具,它本身并不提供服务,服务仍旧依托 ssh 对外提供。

    gitolite 增强了授权体系,和仓库管理功能。

    在本地clone一个gitolite-admin的仓库,直接在本地修改,再推送到远程服务器上即可生效。

    gitolite适合小团队管理.

gitolite部署

准备工作

创建用户

useradd git-admin
[root@node4 ~]# id git-admin 
uid=1000(git-admin) gid=1000(git-admin) groups=1000(git-admin)
[root@node4 ~]# passwd git-admin 

生成秘钥

su git-admin 
cd
ssh-keygen -t rsa

修改秘钥名称

mv .ssh/id_rsa.pub .ssh/admin.pub
chmod  700 .ssh/admin.pub

部署

克隆 gitolite 版本库

git clone https://github.com/sitaramc/gitolite

安装 gitolite

[git-admin@node4 ~]$ mkdir gitolite-admin
[git-admin@node4 ~]$ gitolite/install -to gitolite-admin
[git-admin@node4 ~]$ cd gitolite-admin
[git-admin@node4 gitolite-admin]$ ls
commands  gitolite  gitolite-shell  lib  syntactic-sugar  triggers  VERSION  VREF

初始化仓库

    使用 admin.pub 管理员秘钥初始化仓库.本机就有了大管理员权限.

    同时会在家目录下创建 repositories 文件夹,这个文件夹就是存储所有的 git 仓库的

   默认有两个 :可.gitolite-admin.git 和test.git, 一个是管理仓库的,一个是测试用 .

[git-admin@node4 gitolite-admin]$ ./gitolite setup -pk ~/.ssh/admin.pub
Initialized empty Git repository in /home/git-admin/repositories/gitolite-admin.git/
Initialized empty Git repository in /home/git-admin/repositories/testing.git/
WARNING: /home/git-admin/.ssh/authorized_keys missing; creating a new one
    (this is normal on a brand new install)

查看仓库

[git-admin@node4 ~]$ cd repositories/
[git-admin@node4 repositories]$ ls
gitolite-admin.git testing.git

生成管理员仓库

    就是把管理员仓库的代码同步到一个位置,以后权限控制,创建仓库,添加用户都在这个地方操作就可以了.

[git-admin@node4 ~]$ mkdir data
[git-admin@node4 ~]$ cd data/
[git-admin@node4 data]$ git clone git-admin@127.0.0.1:gitolite-admin
Cloning into 'gitolite-admin'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (6/6), done.
[git-admin@node4 data]$ tree 
.
└── gitolite-admin         
    ├── conf                        配置公户权限/仓库的配置
    │   └── gitolite.conf
    └── keydir                     下面是放对应用户ssh公钥,admin.pub这个公钥可以删除了(创建格式为 用户名可自定义.pub 用户名权限控制有用到,里面复制该用户的 ssh.pub <id_rsa.pub>)       
        └── admin.pub

gitolite配置文件说明

在 keydir 下把开发人员的 sshkey 都添加进去一个人一个文件.

配置仓库

cat conf/gitolite.conf 
# groups              # 用户组
@admin = admin        # 多个用户用空格隔开,此用户名就是keydir 用户名.pub文件的名字
@user = root

# access
repo gitolite-admin      # 仓库名 可以自定义多个仓库
    RW+     =   admin    # RW+ 权限为: 读 写 删除

# 自定义的仓库,如果没有仓库则会自动创建仓库
# 如果要新增加仓库按照这个格式在添加就可以了
repo project
    RW+     =   @admin    # 也可以写 @all 所有人
    Rw      =   @user    # Rw  权限为: 度 写 

提交代码

    提交代码之后 gitolite 会自动创建仓库.

[git-admin@node4 gitolite-admin]$   git config --global user.email "you@example.com"
[git-admin@node4 gitolite-admin]$   git config --global user.name "Your Name"
[git-admin@node4 gitolite-admin]$ git commit -m 'new user test'
[master aeef50c] new user test
 2 files changed, 12 insertions(+), 2 deletions(-)
 create mode 100644 keydir/test.pub
[git-admin@node4 gitolite-admin]$ git push origin master 
Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 1.12 KiB | 1.12 MiB/s, done.
Total 6 (delta 0), reused 0 (delta 0)
remote: WARNING: syntax error, ignoring: 'Rw = @user'
remote: Initialized empty Git repository in /home/git-admin/repositories/project.git/          # 自动创建仓库
To 127.0.0.1:gitolite-admin
   2e5aae9..aeef50c  master -> master

客户端测试

[root@node3 ~]# git clone git-admin@172.16.0.64:devops.git
Cloning into 'devops'...
warning: You appear to have cloned an empty repository.
[root@node3 ~]# cd devops/
[root@node3 devops]# ls
[root@node3 devops]# touch tt{1..100}.txt
[root@node3 devops]# git add .
[root@node3 devops]# git commit -m 'add 100 txt'
[root@node3 devops]# git push origin master 
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 448 bytes | 448.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To 172.16.0.64:devops.git
 * [new branch]      master -> master

  

 

posted @ 2020-07-25 23:14  闫世成  阅读(418)  评论(0编辑  收藏  举报