温馨提示×

gitlab在linux怎设置

小樊
46
2026-09-07 13:04:41
栏目: 智能运维

下面按最常见的两种场景给你说明:
1️⃣ 使用 GitLab 官方 Omnibus 包(推荐)
2️⃣ 修改已有 GitLab 的配置


一、在 Linux 上安装并配置 GitLab(以 Ubuntu / CentOS 为例)

1. 安装 GitLab(Omnibus)

# Ubuntu
sudo apt update
sudo apt install -y curl openssh-server ca-certificates
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash
sudo EXTERNAL_URL="http://gitlab.example.com" apt install gitlab-ee
# CentOS
sudo yum install -y curl policycoreutils-python openssh-server
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
sudo EXTERNAL_URL="http://gitlab.example.com" yum install gitlab-ee

2. 修改 GitLab 配置

配置文件路径:

/etc/gitlab/gitlab.rb

常见配置示例:

external_url 'http://gitlab.example.com'

# 修改端口
# external_url 'http://192.168.1.100:8080'

# 关闭自带 Nginx(如果你用外部 Nginx)
# nginx['enable'] = false

# 设置邮件
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.example.com"
gitlab_rails['smtp_port'] = 465

3. 重新加载配置

sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

4. 查看状态

sudo gitlab-ctl status

二、常用管理命令

gitlab-ctl start
gitlab-ctl stop
gitlab-ctl restart
gitlab-ctl tail

三、防火墙 & 端口

# 开放 80 / 443
sudo ufw allow 80
sudo ufw allow 443

四、首次登录

  • 访问:http://服务器IP
  • 默认用户:root
  • 密码:
sudo cat /etc/gitlab/initial_root_password

五、如果你是指「Git 客户端在 Linux 上连接 GitLab」

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

ssh-keygen -t rsa -b 4096
cat ~/.ssh/id_rsa.pub

把公钥加到 GitLab → Settings → SSH Keys


如果你能具体说一下:

  • ✅ 是 安装 GitLab
  • ✅ 还是 配置 GitLab 参数
  • ✅ 还是 Linux 上用 Git 连 GitLab

我可以直接给你精准步骤。

0 踩