一,关于gitolite
1,官网:
https://gitolite.com/gitolite/index.html
2,代码网站:
https://github.com/sitaramc/gitolite
3,说明:
3个角色: git服务器,上面运行gitolite/ssh服务
管理服务器:用来管理项目,这里我们和git服务器用同一台机器
客户端: 使用git客户端
二,安装gitolite的准备工作
1,安装git:git服务器
[root@blog ~]# yum install git
查看git的版本:
[root@blog ~]# git --version
git version 2.43.5
2,安装perl: git服务器
[root@blog ~]# yum install perl
查看perl的版本
[root@blog ~]# perl --version
3,添加git用户:git服务器
[root@blog ~]# groupadd git
[root@blog ~]# useradd -m git -g git
设置密码:
[root@blog ~]# passwd git
Changing password for user git.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
4,生成密钥,过程中无需输入密码,一路回车即可:管理服务器
[root@blog ~]# ssh-keygen
Generating public/private rsa key pair.
...
保存公钥
[root@iZ2zejc9t0hf6pnw6sewrxZ ~]# cp .ssh/id_rsa.pub /tmp/admin.pub
三,安装gitolite
1, 切换到git账号: git服务器
[root@blog ~]# su git
[git@blog root]$ cd
[git@blog ~]$
创建bin目录
[git@blog ~]$ mkdir bin
[git@blog ~]$ ls
bin
2,下载源码:git服务器
[git@blog ~]$ git clone https://github.com/sitaramc/gitolite.git
Cloning into 'gitolite'...
remote: Enumerating objects: 9791, done.
remote: Counting objects: 100% (85/85), done.
remote: Compressing objects: 100% (58/58), done.
remote: Total 9791 (delta 24), reused 58 (delta 17), pack-reused 9706
Receiving objects: 100% (9791/9791), 3.09 MiB | 3.76 MiB/s, done.
Resolving deltas: 100% (6050/6050), done.
[git@blog ~]$ ls
bin gitolite
3,安装:git服务器
准备安装,把gitolite的安装文件指向bin
[git@blog ~]$ ./gitolite/install -to /home/git/bin/
[git@blog ~]$ cd bin/
[git@blog bin]$ ls
commands gitolite gitolite-shell lib syntactic-sugar triggers VERSION VREF
安装:
[git@blog ~]$ /home/git/bin/gitolite setup -pk /tmp/admin.pub
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /home/git/repositories/gitolite-admin.git/
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /home/git/repositories/testing.git/
WARNING: /home/git/.ssh missing; creating a new one
(this is normal on a brand new install)
WARNING: /home/git/.ssh/authorized_keys missing; creating a new one
(this is normal on a brand new install)
[git@blog ~]$ ls
bin gitolite projects.list repositories
查看创建的库:
[git@blog ~]$ ls repositories/
gitolite-admin.git testing.git
默认创建了testing仓库和gitolite-admin仓库,
testing是用于测试
gitolite-admin是用于权限配置
四,管理端克隆管理项目(本例中和服务端同一台机器)
1,克隆管理项目:管理服务器
[root@blog gitadmin]# git clone ssh://git@localhost:22/gitolite-admin
Cloning into 'gitolite-admin'...
The authenticity of host '[localhost]:22 ([127.0.0.1]:22)' can't be established.
ED25519 key fingerprint is SHA256:cTfZOVKLpUrtlhnXaD9GdXBrohdB7Y9VKN7RmRI9kTc.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[localhost]:22' (ED25519) to the list of known hosts.
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), pack-reused 0
Receiving objects: 100% (6/6), done.
可以看到它的目录结构:
[root@blog gitolite-admin]# ls
conf keydir
conf下是配置文件,
keydir是存放用户公钥的目录
2,添加一个用户:
客户端:创建密钥
liuhongdi@lhdpc:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/liuhongdi/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/liuhongdi/.ssh/id_rsa
Your public key has been saved in /home/liuhongdi/.ssh/id_rsa.pub
...
把公钥上传到管理项目所在目录
然后提交新用户公钥到gitolite-admin项目中
[root@blog gitolite-admin]# git add -A
[root@blog gitolite-admin]# git commit -m "add user liuhongdi";
[master 957bfaf] add user liuhongdi
1 file changed, 1 insertion(+)
create mode 100644 keydir/liuhongdi.pub
[root@blog gitolite-admin]# git push origin master
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 801 bytes | 801.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
To ssh://localhost:22/gitolite-admin
794ac5e..957bfaf master -> master
3, 新建一个项目并提交:管理服务器
[root@blog gitolite-admin]# cd conf/
[root@blog conf]# ls
gitolite.conf
[root@blog conf]# vi gitolite.conf
修改后内容:
repo gitolite-admin
RW+ = admin
repo testing
RW+ = @all
@gsGroup=admin liuhongdi
repo gsapi
RW+ = @gsGroup
提交
[root@blog conf]# git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: gitolite.conf
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitolite.conf.swp
no changes added to commit (use "git add" and/or "git commit -a")
[root@blog conf]# rm .gitolite.conf.swp
rm: remove regular file '.gitolite.conf.swp'? y
[root@blog conf]# git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: gitolite.conf
no changes added to commit (use "git add" and/or "git commit -a")
[root@blog conf]# git add -A
[root@blog conf]# git commit -m "add repo gsapi";
[master affb07b] add repo gsapi
1 file changed, 5 insertions(+)
[root@blog conf]# git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
[root@blog conf]# git push origin master
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 397 bytes | 397.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
remote: hint: Using 'master' as the name for the initial branch. This default branch name
remote: hint: is subject to change. To configure the initial branch name to use in all
remote: hint: of your new repositories, which will suppress this warning, call:
remote: hint:
remote: hint: git config --global init.defaultBranch <name>
remote: hint:
remote: hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
remote: hint: 'development'. The just-created branch can be renamed via this command:
remote: hint:
remote: hint: git branch -m <name>
remote: Initialized empty Git repository in /home/git/repositories/gsapi.git/
To ssh://localhost:22/gitolite-admin
957bfaf..affb07b master -> master
五,客户端配置项目
下载新项目:
新项目为空,所以提示是空仓库
liuhongdi@lhdpc:~/work/gsapi$ git clone ssh://[email protected]:22/gsapi
正克隆到 'gsapi'...
warning: 您似乎克隆了一个空仓库
提交修改等功能也可以使用了
liuhongdi@lhdpc:~/work/gsapi/gsapi$ git config --global user.email "[email protected]"
liuhongdi@lhdpc:~/work/gsapi/gsapi$ git config --global user.name "laoliu"
liuhongdi@lhdpc:~/work/gsapi/gsapi$ git add -A
liuhongdi@lhdpc:~/work/gsapi/gsapi$ git commit -m "info";
[master (根提交) 33122a6] info
1 file changed, 3 insertions(+)
create mode 100644 info.php
liuhongdi@lhdpc:~/work/gsapi/gsapi$
liuhongdi@lhdpc:~/work/gsapi/gsapi$ git status
位于分支 master
您的分支基于 'origin/master',但此上游分支已经不存在。
(使用 "git branch --unset-upstream" 来修复)
无文件要提交,干净的工作区
liuhongdi@lhdpc:~/work/gsapi/gsapi$ git push origin master
枚举对象: 3, 完成.
对象计数中: 100% (3/3), 完成.
写入对象中: 100% (3/3), 217 字节 | 217.00 KiB/s, 完成.
总共 3(差异 0),复用 0(差异 0),包复用 0
To ssh://8.1.2.3:22/gsapi
* [new branch] master -> master
六,安装过程的报错处理
1,报错
[git@blog ~]$ ./gitolite/install -to /home/git/bin/
Can't locate FindBin.pm in @INC (you may need to install the FindBin module)
(@INC contains: /usr/local/lib64/perl5/5.32 /usr/local/share/perl5/5.32
/usr/lib64/perl5/vendor_perl/usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5)
at ./gitolite/install line 9.
BEGIN failed--compilation aborted at ./gitolite/install line 9.
解决:
安装cpan:
[root@blog ~]# yum install perl-CPAN
配置cpan
[root@blog ~]# perl -MCPAN -e shell
Terminal does not support AddHistory.
To fix that, maybe try> install Term::ReadLine::Perl
cpan shell -- CPAN exploration and modules installation (v2.29)
Enter 'h' for help.
cpan[1]> install Term::ReadLine::Perl
...
安装FindBin
[root@blog ~]# cpan FindBin
...
标签:git,centos,hint,blog,gitolite,master,root,stream9 From: https://www.cnblogs.com/architectforest/p/18303368