下面按常见场景给你讲怎么在 Linux 上“配 GitLab”。先确认你是哪一种需求:
我分别说,你可以按需看。
# 安装依赖
sudo apt update
sudo apt install -y curl openssh-server ca-certificates tzdata perl
# 添加 GitLab 源
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash
# 安装 GitLab(改域名)
sudo EXTERNAL_URL="http://gitlab.example.com" apt install gitlab-ee
如果是 CE:
curl 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
sudo gitlab-ctl reconfigure
访问:
http://服务器IP
首次登录:
rootsudo cat /etc/gitlab/initial_root_password
sudo gitlab-ctl start
sudo gitlab-ctl stop
sudo gitlab-ctl restart
sudo gitlab-ctl status
sudo apt install git # Ubuntu
sudo yum install git # CentOS
git config --global user.name "yourname"
git config --global user.email "you@example.com"
ssh-keygen -t ed25519 -C "you@example.com"
cat ~/.ssh/id_ed25519.pub
复制到:
GitLab → Settings → SSH Keys
测试:
ssh -T git@gitlab.com
GitLab → Access Tokens → 创建 token
git clone https://gitlab.com/username/repo.git
# 用户名:yourname
# 密码:token
# 安装
sudo apt install gitlab-runner
# 注册
sudo gitlab-runner register
按提示填:
shell 或 docker✅ 端口冲突(80/443)
sudo vim /etc/gitlab/gitlab.rb
external_url 'http://ip:8080'
sudo gitlab-ctl reconfigure
✅ 内存不足
我可以直接给你一套可执行命令。