温馨提示×

ubuntu gitlab怎样配置

小樊
47
2026-10-13 16:50:09
栏目: 智能运维

下面我按最常见的两种场景给你讲:
1)在 Ubuntu 上自建 GitLab(社区版)
2)Ubuntu 上配置 Git 客户端连接 GitLab


一、Ubuntu 上安装并配置 GitLab(自建)

1. 系统准备

sudo apt update
sudo apt upgrade -y

建议内存 ≥ 4GB


2. 安装依赖

sudo apt install -y curl openssh-server ca-certificates postfix
  • postfix 选 Internet Site

3. 添加 GitLab 源并安装

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

安装(替换为你自己的域名):

sudo EXTERNAL_URL="http://gitlab.example.com" apt install gitlab-ce

4. 初始化配置

sudo gitlab-ctl reconfigure

访问:

http://服务器IP

首次登录账号:root
密码在:

sudo cat /etc/gitlab/initial_root_password

5. 常用配置(可选)

编辑:

sudo vim /etc/gitlab/gitlab.rb

示例:

external_url 'http://gitlab.example.com'
gitlab_rails['gitlab_email_from'] = 'gitlab@example.com'

改完执行:

sudo gitlab-ctl reconfigure

6. 常用命令

sudo gitlab-ctl start
sudo gitlab-ctl stop
sudo gitlab-ctl restart
sudo gitlab-ctl status

二、Ubuntu 配置 Git 客户端连接 GitLab

1. 安装 Git

sudo apt install git -y

2. 配置用户信息

git config --global user.name "yourname"
git config --global user.email "you@example.com"

3. 生成 SSH 密钥

ssh-keygen -t ed25519 -C "you@example.com"

查看公钥:

cat ~/.ssh/id_ed25519.pub

4. 添加到 GitLab

  • GitLab → User → Preferences → SSH Keys
  • 粘贴公钥

5. 克隆仓库测试

git clone git@gitlab.example.com:group/project.git

三、常见问题

❌ 访问不了

  • 防火墙:
sudo ufw allow 80
sudo ufw allow 443

❌ SSH 连不上

ssh -T git@gitlab.example.com

如果你是指:

  • Docker 安装 GitLab
  • GitLab + Nginx + HTTPS
  • GitLab Runner(CI/CD)配置

告诉我,我可以直接给你对应方案。

0 踩