温馨提示×

linux gitlab如何远程配置

小樊
41
2026-10-25 01:43:23
栏目: 智能运维

下面按常见场景给你讲一下「Linux 上 GitLab 的远程配置」,分为 GitLab 服务端(远程服务器) 和 本地客户端连接远程 GitLab 两部分。


一、远程 GitLab 服务器(Linux 服务端)配置

1. 安装 GitLab(以 Ubuntu 为例)

sudo apt update
sudo apt install -y curl openssh-server ca-certificates postfix

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

如果是公网服务器,EXTERNAL_URL 写成你的域名或 IP

2. 初始化配置

sudo gitlab-ctl reconfigure

3. 防火墙 & 远程访问

sudo ufw allow 80
sudo ufw allow 443
sudo ufw allow 22

浏览器访问:

http://服务器IP

4. 修改 GitLab 配置文件(可选)

sudo vim /etc/gitlab/gitlab.rb

常见配置:

external_url 'http://gitlab.example.com'
gitlab_rails['gitlab_ssh_host'] = '192.168.1.100'
gitlab_rails['gitlab_shell_ssh_port'] = 22

修改后:

sudo gitlab-ctl reconfigure

二、本地 Linux 客户端远程连接 GitLab

1. 安装 Git

sudo apt install git

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

把公钥复制到:

GitLab → User → Settings → SSH Keys

4. 克隆远程仓库

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

或 HTTPS:

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

三、远程仓库基本操作

git add .
git commit -m "init"
git push origin main

四、常见问题

1. SSH 连不上

  • 确认 22 端口开放
  • 测试:
ssh -T git@gitlab.example.com

2. 端口不是 22

vim ~/.ssh/config
Host gitlab.example.com
    Port 2222

3. 忘记 root 密码

sudo gitlab-rake "gitlab:password:reset[root]"

五、你具体是哪种需求?

我可以更针对性地讲:

  • ✅ 自己搭建 GitLab 服务器
  • ✅ 配置 GitLab CI/CD
  • ✅ 局域网 / 公网远程访问
  • ✅ Docker 部署 GitLab
  • ✅ GitLab + Nginx 反代

你可以直接说你的 Linux 发行版 + 使用场景。

0 踩