centos

centos gitlab如何搭建私有仓库

小樊
47
2025-09-07 18:21:36
栏目: 智能运维

在CentOS上搭建GitLab私有仓库的步骤如下:

1. 安装依赖包

首先,确保你的系统是最新的,并安装必要的依赖包。

sudo yum update -y
sudo yum install -y curl policycoreutils-python openssh-server

2. 添加GitLab仓库

添加GitLab的官方仓库。

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

3. 安装GitLab CE(社区版)

安装GitLab社区版。

sudo yum install -y gitlab-ce

4. 配置GitLab

编辑GitLab的配置文件 /etc/gitlab/gitlab.rb,根据需要进行配置。例如,你可以更改GitLab的监听端口、外部URL等。

sudo nano /etc/gitlab/gitlab.rb

找到以下行并进行修改:

external_url 'http://your-gitlab-url'

确保 external_url 设置正确,以便外部访问。

5. 重新配置并重启GitLab

保存并退出编辑器后,运行以下命令重新配置并重启GitLab。

sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

6. 访问GitLab

打开浏览器,访问你在 external_url 中设置的URL,例如 http://your-gitlab-url。你应该会看到GitLab的登录页面。

7. 创建私有仓库

使用管理员账户登录后,创建一个新的私有仓库。

  1. 登录GitLab。
  2. 点击右上角的 “+” 号,然后选择 “New project”。
  3. 在 “Project name” 中输入项目名称。
  4. 选择 “Private” 选项。
  5. 点击 “Create project”。

8. 克隆私有仓库

你可以使用SSH密钥来克隆私有仓库。

  1. 生成SSH密钥(如果还没有):

    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
    
  2. 将公钥添加到GitLab账户中:

    • 复制公钥内容:

      cat ~/.ssh/id_rsa.pub
      
    • 登录GitLab,进入 “Settings” -> “SSH Keys”。

    • 粘贴公钥并保存。

  3. 克隆私有仓库:

    git clone git@your-gitlab-url:username/private-repo.git
    

现在,你已经成功在CentOS上搭建了一个GitLab私有仓库,并可以克隆和使用它。

0
看了该问题的人还看了