git: centos stream9上安裝gitolite

刘宏缔的架构森林發表於2024-07-16

一,關於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://git@8.1.2.3:22/gsapi
正克隆到 'gsapi'...
warning: 您似乎克隆了一個空倉庫

提交修改等功能也可以使用了

liuhongdi@lhdpc:~/work/gsapi/gsapi$ git config --global user.email "lhd@qq.com"
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
...

相關文章